-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
PsrResponseCommandTest.php
58 lines (45 loc) · 1.67 KB
/
PsrResponseCommandTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
use Intervention\Image\Commands\PsrResponseCommand;
use PHPUnit\Framework\TestCase;
class PsrResponseCommandTest extends TestCase
{
public function tearDown()
{
Mockery::close();
}
public function testResponseCreationAndHeaders()
{
//We know for sure that mimetype will be "application/xml"
$encodedContent = '<?xml version="1.0" encoding="UTF-8"?>';
$image = Mockery::mock('Intervention\Image\Image');
$stream = \GuzzleHttp\Psr7\stream_for($encodedContent);
$image->shouldReceive('stream')
->with('jpg', 87)
->once()
->andReturn($stream);
$image->shouldReceive('getEncoded')
->twice()
->andReturn($encodedContent);
$command = new PsrResponseCommand(['jpg', 87]);
$result = $command->execute($image);
$this->assertTrue($result);
$this->assertTrue($command->hasOutput());
$output = $command->getOutput();
$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $output);
/**
* @var \Psr\Http\Message\ResponseInterface $output
*/
$this->assertEquals($stream, $output->getBody());
$this->assertEquals($encodedContent, (string)$output->getBody());
$this->assertTrue($output->hasHeader('Content-Type'));
$this->assertTrue($output->hasHeader('Content-Length'));
$this->assertTrue(in_array($output->getHeaderLine('Content-Type'), [
'application/xml',
'text/xml',
]));
$this->assertEquals(
strlen($encodedContent),
$output->getHeaderLine('Content-Length')
);
}
}