Skip to content

Commit

Permalink
Merge pull request #42 from flyimg/more-unittests
Browse files Browse the repository at this point in the history
More unittests
  • Loading branch information
sadok-f committed Feb 3, 2017
2 parents 791a458 + d2fb7c4 commit 8f1cc01
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/Core/Tests/BaseTest.php
Expand Up @@ -6,7 +6,8 @@

class BaseTest extends \PHPUnit_Framework_TestCase
{
const IMG_TEST_PATH = __DIR__ . '/../../../web/Rovinj-Croatia.jpg';
const JPG_TEST_IMAGE = __DIR__ . '/TestImages/square.jpg';
const PNG_TEST_IMAGE = __DIR__ . '/TestImages/square.png';
const OPTION_URL = 'w_200,h_100,c_1,bg_#999999,rz_1,sc_50,r_-45,unsh_0.25x0.25+8+0.065,ett_100x80,fb_1,rf_1';

/**
Expand All @@ -24,7 +25,7 @@ class BaseTest extends \PHPUnit_Framework_TestCase
public function setUp()
{
$this->app = $this->createApplication();
$this->image = new Image(self::OPTION_URL, self::IMG_TEST_PATH, $this->app['params']);
$this->image = new Image(self::OPTION_URL, self::JPG_TEST_IMAGE, $this->app['params']);
}

/**
Expand Down
48 changes: 46 additions & 2 deletions src/Core/Tests/ImageProcessorTest.php
Expand Up @@ -7,14 +7,58 @@

class ImageProcessorTest extends BaseTest
{

/**
*/
public function testProcessPNG()
{
$this->image = new Image(parent::OPTION_URL . ',o_png', parent::PNG_TEST_IMAGE, $this->app['params']);
/** @var ImageProcessor $processor */
$processor = $this->app['image.processor'];
$processor->process($this->image);
$this->assertFileExists($this->image->getNewFilePath());
$this->assertEquals('image/png', $this->getFileMemeType($this->image->getNewFilePath()));
}
/**
*/
public function testProcess()
public function testProcessWebP()
{
$this->image = new Image(parent::OPTION_URL, parent::IMG_TEST_PATH, $this->app['params']);
$this->image = new Image(parent::OPTION_URL . ',o_webp', parent::PNG_TEST_IMAGE, $this->app['params']);
/** @var ImageProcessor $processor */
$processor = $this->app['image.processor'];
$processor->process($this->image);
$this->assertFileExists($this->image->getNewFilePath());
$this->assertEquals('image/webp', $this->getFileMemeType($this->image->getNewFilePath()));
}
/**
*/
public function testProcessJpgFromPng()
{
$this->image = new Image(parent::OPTION_URL . ',o_jpg', parent::PNG_TEST_IMAGE, $this->app['params']);
/** @var ImageProcessor $processor */
$processor = $this->app['image.processor'];
$processor->process($this->image);
$this->assertFileExists($this->image->getNewFilePath());
$this->assertEquals('image/jpeg', $this->getFileMemeType($this->image->getNewFilePath()));
}

/**
*/
public function testProcessJpg()
{
$this->image = new Image(parent::OPTION_URL, parent::JPG_TEST_IMAGE, $this->app['params']);
/** @var ImageProcessor $processor */
$processor = $this->app['image.processor'];
$processor->process($this->image);
$this->assertFileExists($this->image->getNewFilePath());
}

/**
* @param $filePath
* @return mixed
*/
protected function getFileMemeType($filePath)
{
return finfo_file(finfo_open(FILEINFO_MIME_TYPE), $filePath);
}
}
4 changes: 2 additions & 2 deletions src/Core/Tests/ImageTest.php
Expand Up @@ -57,15 +57,15 @@ public function testSaveToTemporaryFile()
public function testSaveToTemporaryFileException()
{
$this->expectException(ReadFileException::class);
$this->image = new Image('', parent::IMG_TEST_PATH . '--fail', $this->app['params']);
$this->image = new Image('', parent::JPG_TEST_IMAGE . '--fail', $this->app['params']);
}

/**
* Test GenerateFilesName
*/
public function testGenerateFilesName()
{
$image_2 = new Image(parent::OPTION_URL, parent::IMG_TEST_PATH, $this->app['params']);
$image_2 = new Image(parent::OPTION_URL, parent::JPG_TEST_IMAGE, $this->app['params']);
$this->assertEquals($this->image->getNewFileName(), $image_2->getNewFileName());
$this->assertNotEquals($this->image->getNewFilePath(), $image_2->getNewFilePath());
}
Expand Down
Binary file added src/Core/Tests/TestImages/square.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Core/Tests/TestImages/square.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8f1cc01

Please sign in to comment.