1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-30 01:00:06 +02:00

added checksumCommand

This commit is contained in:
Oliver Vogel
2014-05-11 16:38:47 +02:00
parent c2d9a9a320
commit 51e9ef0349
2 changed files with 49 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
<?php
namespace Intervention\Image\Commands;
class ChecksumCommand extends AbstractCommand
{
public function execute($image)
{
$colors = array();
$size = $image->getSize();
for ($x=0; $x <= ($size->width-1); $x++) {
for ($y=0; $y <= ($size->height-1); $y++) {
$colors[] = $image->pickColor($x, $y, 'array');
}
}
$this->setOutput(md5(serialize($colors)));
return true;
}
}

View File

@@ -0,0 +1,26 @@
<?php
use Intervention\Image\Commands\ChecksumCommand;
class ExifCommandTest extends PHPUnit_Framework_TestCase
{
public function tearDown()
{
Mockery::close();
}
public function testExecute()
{
$size = Mockery::mock('Intervention\Image\Size', array(3, 3));
$color = array(0,0,0,1);
$resource = imagecreatefrompng(__DIR__.'/images/tile.png');
$image = Mockery::mock('Intervention\Image\Image');
$image->shouldReceive('getSize')->once()->andReturn($size);
$image->shouldReceive('pickColor')->times(9)->andReturn($color);
$command = new ChecksumCommand(array());
$result = $command->execute($image);
$this->assertTrue($result);
$this->assertTrue($command->hasOutput());
$this->assertEquals('ec9cbdb71be04e26b4a89333f20c273b', $command->getOutput());
}
}