From c7a630520526bb74dbffc43f82e3362d079b3729 Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Sun, 28 Jun 2015 17:08:10 +0300 Subject: [PATCH] Tests. --- .../Image/Commands/PsrResponseCommand.php | 6 +- .../Image/Commands/StreamCommand.php | 2 +- tests/PsrResponseCommandTest.php | 57 +++++++++++++++++++ tests/StreamCommandTest.php | 35 ++++++++++++ 4 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 tests/PsrResponseCommandTest.php create mode 100644 tests/StreamCommandTest.php diff --git a/src/Intervention/Image/Commands/PsrResponseCommand.php b/src/Intervention/Image/Commands/PsrResponseCommand.php index 5624a113..1019f2b3 100644 --- a/src/Intervention/Image/Commands/PsrResponseCommand.php +++ b/src/Intervention/Image/Commands/PsrResponseCommand.php @@ -28,14 +28,14 @@ class PsrResponseCommand extends AbstractCommand $mimetype = finfo_buffer( finfo_open(FILEINFO_MIME_TYPE), - $image->encoded + $image->getEncoded() ); - +print_r($mimetype); $this->setOutput(new Response( 200, array( 'Content-Type' => $mimetype, - 'Content-Length' => strlen($image->encoded) + 'Content-Length' => strlen($image->getEncoded()) ), $stream )); diff --git a/src/Intervention/Image/Commands/StreamCommand.php b/src/Intervention/Image/Commands/StreamCommand.php index 39fc698c..111c4756 100644 --- a/src/Intervention/Image/Commands/StreamCommand.php +++ b/src/Intervention/Image/Commands/StreamCommand.php @@ -17,7 +17,7 @@ class StreamCommand extends AbstractCommand $quality = $this->argument(1)->between(0, 100)->value(); $this->setOutput(\GuzzleHttp\Psr7\stream_for( - $image->encode($format, $quality)->encoded + $image->encode($format, $quality)->getEncoded() )); return true; diff --git a/tests/PsrResponseCommandTest.php b/tests/PsrResponseCommandTest.php new file mode 100644 index 00000000..b28a45f9 --- /dev/null +++ b/tests/PsrResponseCommandTest.php @@ -0,0 +1,57 @@ +'; + + $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(array('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->assertEquals( + "application/xml", + $output->getHeaderLine('Content-Type') + ); + + $this->assertEquals( + strlen($encodedContent), + $output->getHeaderLine('Content-Length') + ); + } +} \ No newline at end of file diff --git a/tests/StreamCommandTest.php b/tests/StreamCommandTest.php new file mode 100644 index 00000000..79d1048f --- /dev/null +++ b/tests/StreamCommandTest.php @@ -0,0 +1,35 @@ +shouldReceive('encode') + ->with('jpg', 87) + ->once() + ->andReturnSelf(); + + $image->shouldReceive('getEncoded') + ->once() + ->andReturn($encodedContent); + + $command = new StreamCommand(array('jpg', 87)); + $result = $command->execute($image); + + $this->assertTrue($result); + $this->assertTrue($command->hasOutput()); + + $output = $command->getOutput(); + $this->assertInstanceOf('Psr\Http\Message\StreamInterface', $output); + $this->assertEquals($encodedContent, (string)$output); + } +} \ No newline at end of file