mirror of
https://github.com/Intervention/image.git
synced 2025-08-18 19:51:22 +02:00
Tests.
This commit is contained in:
@@ -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
|
||||
));
|
||||
|
@@ -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;
|
||||
|
57
tests/PsrResponseCommandTest.php
Normal file
57
tests/PsrResponseCommandTest.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
use Intervention\Image\Commands\PsrResponseCommand;
|
||||
|
||||
class PsrResponseCommandTest extends PHPUnit_Framework_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(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')
|
||||
);
|
||||
}
|
||||
}
|
35
tests/StreamCommandTest.php
Normal file
35
tests/StreamCommandTest.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
use Intervention\Image\Commands\StreamCommand;
|
||||
|
||||
class StreamCommandTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
public function testStreamCreationAndContent()
|
||||
{
|
||||
$encodedContent = 'sample-content';
|
||||
$image = Mockery::mock('Intervention\Image\Image');
|
||||
|
||||
$image->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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user