starting to add tests
This commit is contained in:
parent
649d36359f
commit
8686f9ddd7
9 changed files with 388 additions and 1 deletions
30
.atoum.php
Normal file
30
.atoum.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
use mageekguy\atoum\reports;
|
||||
|
||||
$runner
|
||||
->addTestsFromDirectory(__DIR__ . '/tests/units');
|
||||
|
||||
$runner->getScore()->getCoverage()->excludeDirectory(__DIR__ . '/tests/units/mock');
|
||||
|
||||
$travis = getenv('TRAVIS');
|
||||
if ($travis) {
|
||||
$script->addDefaultReport();
|
||||
$coverallsToken = getenv('COVERALLS_REPO_TOKEN');
|
||||
if ($coverallsToken) {
|
||||
$coverallsReport = new reports\asynchronous\coveralls('classes', $coverallsToken);
|
||||
$defaultFinder = $coverallsReport->getBranchFinder();
|
||||
$coverallsReport
|
||||
->setBranchFinder(function () use ($defaultFinder) {
|
||||
if (($branch = getenv('TRAVIS_BRANCH')) === false) {
|
||||
$branch = $defaultFinder();
|
||||
}
|
||||
return $branch;
|
||||
}
|
||||
)
|
||||
->setServiceName('travis-ci')
|
||||
->setServiceJobId(getenv('TRAVIS_JOB_ID'))
|
||||
->addDefaultWriter()
|
||||
;
|
||||
$runner->addReport($coverallsReport);
|
||||
}
|
||||
}
|
9
.travis.yml
Normal file
9
.travis.yml
Normal file
|
@ -0,0 +1,9 @@
|
|||
language: php
|
||||
php:
|
||||
- 7.1
|
||||
- 7.2
|
||||
- 7.3
|
||||
- 7.4
|
||||
install:
|
||||
- composer install
|
||||
script: composer test
|
|
@ -30,5 +30,8 @@
|
|||
"psr-4": {
|
||||
"ByJoby\\ImageTransform\\tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"test": "./vendor/bin/atoum -d tests"
|
||||
}
|
||||
}
|
||||
|
|
BIN
tests/units/100x200.jpg
Normal file
BIN
tests/units/100x200.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.8 KiB |
BIN
tests/units/200x100.jpg
Normal file
BIN
tests/units/200x100.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 4 KiB |
BIN
tests/units/200x200.jpg
Normal file
BIN
tests/units/200x200.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.6 KiB |
|
@ -3,8 +3,171 @@
|
|||
namespace ByJoby\ImageTransform\tests\units\Sizers;
|
||||
|
||||
use atoum;
|
||||
use ByJoby\ImageTransform\Sizers\Cover as SizerUnderTest;
|
||||
use ByJoby\ImageTransform\tests\units\mock\MockDriver;
|
||||
|
||||
class Cover extends atoum
|
||||
{
|
||||
|
||||
public function testPortraitWhenImageIsTaller()
|
||||
{
|
||||
$this
|
||||
->given($image = $this->image(__DIR__.'/../100x200.jpg',100,150))
|
||||
->integer($image->width())->isEqualTo(100)
|
||||
->integer($image->height())->isEqualTo(200)
|
||||
->variable($image->sizer()->resizeToWidth())->isEqualTo(100)
|
||||
->variable($image->sizer()->resizeToHeight())->isEqualTo(200)
|
||||
->variable($image->sizer()->cropToWidth())->isEqualTo(100)
|
||||
->variable($image->sizer()->cropToHeight())->isEqualTo(150)
|
||||
->given($image->rotate())
|
||||
->integer($image->width())->isEqualTo(300)
|
||||
->integer($image->height())->isEqualTo(150)
|
||||
->variable($image->sizer()->resizeToWidth())->isEqualTo(300)
|
||||
->variable($image->sizer()->resizeToHeight())->isEqualTo(150)
|
||||
->variable($image->sizer()->cropToWidth())->isEqualTo(100)
|
||||
->variable($image->sizer()->cropToHeight())->isEqualTo(150)
|
||||
;
|
||||
}
|
||||
|
||||
// public function testPortraitWhenImageIsShorter()
|
||||
// {
|
||||
// $this
|
||||
// ->given($image = $this->image(__DIR__.'/../100x200.jpg',50,300))
|
||||
// ->integer($image->width())->isEqualTo(50)
|
||||
// ->integer($image->height())->isEqualTo(100)
|
||||
// ->variable($image->sizer()->resizeToWidth())->isEqualTo(50)
|
||||
// ->variable($image->sizer()->resizeToHeight())->isEqualTo(100)
|
||||
// ->variable($image->sizer()->cropToWidth())->isNull()
|
||||
// ->variable($image->sizer()->cropToHeight())->isNull()
|
||||
// ->given($image->rotate())
|
||||
// ->integer($image->width())->isEqualTo(50)
|
||||
// ->integer($image->height())->isEqualTo(25)
|
||||
// ->variable($image->sizer()->resizeToWidth())->isEqualTo(50)
|
||||
// ->variable($image->sizer()->resizeToHeight())->isEqualTo(25)
|
||||
// ->variable($image->sizer()->cropToWidth())->isNull()
|
||||
// ->variable($image->sizer()->cropToHeight())->isNull()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function testPortraitWithSquareImage()
|
||||
// {
|
||||
// $this
|
||||
// ->given($image = $this->image(__DIR__.'/../200x200.jpg',75,300))
|
||||
// ->integer($image->width())->isEqualTo(75)
|
||||
// ->integer($image->height())->isEqualTo(75)
|
||||
// ->variable($image->sizer()->resizeToWidth())->isEqualTo(75)
|
||||
// ->variable($image->sizer()->resizeToHeight())->isEqualTo(75)
|
||||
// ->variable($image->sizer()->cropToWidth())->isNull()
|
||||
// ->variable($image->sizer()->cropToHeight())->isNull()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function testPortraitWithLandscapeImage()
|
||||
// {
|
||||
// $this
|
||||
// ->given($image = $this->image(__DIR__.'/../200x100.jpg',100,200))
|
||||
// ->integer($image->width())->isEqualTo(100)
|
||||
// ->integer($image->height())->isEqualTo(50)
|
||||
// ->variable($image->sizer()->resizeToWidth())->isEqualTo(100)
|
||||
// ->variable($image->sizer()->resizeToHeight())->isEqualTo(50)
|
||||
// ->variable($image->sizer()->cropToWidth())->isNull()
|
||||
// ->variable($image->sizer()->cropToHeight())->isNull()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function testLandscapeWhenImageIsTaller()
|
||||
// {
|
||||
// $this
|
||||
// ->given($image = $this->image(__DIR__.'/../200x100.jpg',150,100))
|
||||
// ->integer($image->width())->isEqualTo(150)
|
||||
// ->integer($image->height())->isEqualTo(75)
|
||||
// ->variable($image->sizer()->resizeToWidth())->isEqualTo(150)
|
||||
// ->variable($image->sizer()->resizeToHeight())->isEqualTo(75)
|
||||
// ->variable($image->sizer()->cropToWidth())->isNull()
|
||||
// ->variable($image->sizer()->cropToHeight())->isNull()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function testLandscapeWhenImageIsShorter()
|
||||
// {
|
||||
// $this
|
||||
// ->given($image = $this->image(__DIR__.'/../200x100.jpg',300,75))
|
||||
// ->integer($image->width())->isEqualTo(150)
|
||||
// ->integer($image->height())->isEqualTo(75)
|
||||
// ->variable($image->sizer()->resizeToWidth())->isEqualTo(150)
|
||||
// ->variable($image->sizer()->resizeToHeight())->isEqualTo(75)
|
||||
// ->variable($image->sizer()->cropToWidth())->isNull()
|
||||
// ->variable($image->sizer()->cropToHeight())->isNull()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function testLandscapeWithSquareImage()
|
||||
// {
|
||||
// $this
|
||||
// ->given($image = $this->image(__DIR__.'/../200x200.jpg',300,75))
|
||||
// ->integer($image->width())->isEqualTo(75)
|
||||
// ->integer($image->height())->isEqualTo(75)
|
||||
// ->variable($image->sizer()->resizeToWidth())->isEqualTo(75)
|
||||
// ->variable($image->sizer()->resizeToHeight())->isEqualTo(75)
|
||||
// ->variable($image->sizer()->cropToWidth())->isNull()
|
||||
// ->variable($image->sizer()->cropToHeight())->isNull()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function testLandscapeWithPortraitImage()
|
||||
// {
|
||||
// $this
|
||||
// ->given($image = $this->image(__DIR__.'/../100x200.jpg',200,100))
|
||||
// ->integer($image->width())->isEqualTo(50)
|
||||
// ->integer($image->height())->isEqualTo(100)
|
||||
// ->variable($image->sizer()->resizeToWidth())->isEqualTo(50)
|
||||
// ->variable($image->sizer()->resizeToHeight())->isEqualTo(100)
|
||||
// ->variable($image->sizer()->cropToWidth())->isNull()
|
||||
// ->variable($image->sizer()->cropToHeight())->isNull()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function testWithSmallSquareImage()
|
||||
// {
|
||||
// $this
|
||||
// ->given($image = $this->image(__DIR__.'/../200x200.jpg',300,300))
|
||||
// ->integer($image->width())->isEqualTo(300)
|
||||
// ->integer($image->height())->isEqualTo(300)
|
||||
// ->variable($image->sizer()->resizeToWidth())->isEqualTo(300)
|
||||
// ->variable($image->sizer()->resizeToHeight())->isEqualTo(300)
|
||||
// ->variable($image->sizer()->cropToWidth())->isNull()
|
||||
// ->variable($image->sizer()->cropToHeight())->isNull()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function testWithSmallLandscapeImage()
|
||||
// {
|
||||
// $this
|
||||
// ->given($image = $this->image(__DIR__.'/../200x100.jpg',300,300))
|
||||
// ->integer($image->width())->isEqualTo(300)
|
||||
// ->integer($image->height())->isEqualTo(150)
|
||||
// ->variable($image->sizer()->resizeToWidth())->isEqualTo(300)
|
||||
// ->variable($image->sizer()->resizeToHeight())->isEqualTo(150)
|
||||
// ->variable($image->sizer()->cropToWidth())->isNull()
|
||||
// ->variable($image->sizer()->cropToHeight())->isNull()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function testWithSmallPortraitImage()
|
||||
// {
|
||||
// $this
|
||||
// ->given($image = $this->image(__DIR__.'/../100x200.jpg',300,300))
|
||||
// ->integer($image->width())->isEqualTo(150)
|
||||
// ->integer($image->height())->isEqualTo(300)
|
||||
// ->variable($image->sizer()->resizeToWidth())->isEqualTo(150)
|
||||
// ->variable($image->sizer()->resizeToHeight())->isEqualTo(300)
|
||||
// ->variable($image->sizer()->cropToWidth())->isNull()
|
||||
// ->variable($image->sizer()->cropToHeight())->isNull()
|
||||
// ;
|
||||
// }
|
||||
|
||||
protected function image(string $path, int $width, int $height)
|
||||
{
|
||||
$driver = new MockDriver();
|
||||
return $driver->image($path, new SizerUnderTest($width, $height));
|
||||
}
|
||||
}
|
||||
|
|
173
tests/units/Sizers/Fit.php
Normal file
173
tests/units/Sizers/Fit.php
Normal file
|
@ -0,0 +1,173 @@
|
|||
<?php
|
||||
/* image-transform | https://github.com/jobyone/image-transform | MIT License */
|
||||
namespace ByJoby\ImageTransform\tests\units\Sizers;
|
||||
|
||||
use atoum;
|
||||
use ByJoby\ImageTransform\Sizers\Fit as SizerUnderTest;
|
||||
use ByJoby\ImageTransform\tests\units\mock\MockDriver;
|
||||
|
||||
class Fit extends atoum
|
||||
{
|
||||
public function testPortraitWhenImageIsTaller()
|
||||
{
|
||||
$this
|
||||
->given($image = $this->image(__DIR__.'/../100x200.jpg',100,150))
|
||||
->integer($image->width())->isEqualTo(75)
|
||||
->integer($image->height())->isEqualTo(150)
|
||||
->variable($image->sizer()->resizeToWidth())->isEqualTo(75)
|
||||
->variable($image->sizer()->resizeToHeight())->isEqualTo(150)
|
||||
->variable($image->sizer()->cropToWidth())->isNull()
|
||||
->variable($image->sizer()->cropToHeight())->isNull()
|
||||
->given($image->rotate())
|
||||
->integer($image->width())->isEqualTo(100)
|
||||
->integer($image->height())->isEqualTo(50)
|
||||
->variable($image->sizer()->resizeToWidth())->isEqualTo(100)
|
||||
->variable($image->sizer()->resizeToHeight())->isEqualTo(50)
|
||||
->variable($image->sizer()->cropToWidth())->isNull()
|
||||
->variable($image->sizer()->cropToHeight())->isNull()
|
||||
;
|
||||
}
|
||||
|
||||
public function testPortraitWhenImageIsShorter()
|
||||
{
|
||||
$this
|
||||
->given($image = $this->image(__DIR__.'/../100x200.jpg',50,300))
|
||||
->integer($image->width())->isEqualTo(50)
|
||||
->integer($image->height())->isEqualTo(100)
|
||||
->variable($image->sizer()->resizeToWidth())->isEqualTo(50)
|
||||
->variable($image->sizer()->resizeToHeight())->isEqualTo(100)
|
||||
->variable($image->sizer()->cropToWidth())->isNull()
|
||||
->variable($image->sizer()->cropToHeight())->isNull()
|
||||
->given($image->rotate())
|
||||
->integer($image->width())->isEqualTo(50)
|
||||
->integer($image->height())->isEqualTo(25)
|
||||
->variable($image->sizer()->resizeToWidth())->isEqualTo(50)
|
||||
->variable($image->sizer()->resizeToHeight())->isEqualTo(25)
|
||||
->variable($image->sizer()->cropToWidth())->isNull()
|
||||
->variable($image->sizer()->cropToHeight())->isNull()
|
||||
;
|
||||
}
|
||||
|
||||
public function testPortraitWithSquareImage()
|
||||
{
|
||||
$this
|
||||
->given($image = $this->image(__DIR__.'/../200x200.jpg',75,300))
|
||||
->integer($image->width())->isEqualTo(75)
|
||||
->integer($image->height())->isEqualTo(75)
|
||||
->variable($image->sizer()->resizeToWidth())->isEqualTo(75)
|
||||
->variable($image->sizer()->resizeToHeight())->isEqualTo(75)
|
||||
->variable($image->sizer()->cropToWidth())->isNull()
|
||||
->variable($image->sizer()->cropToHeight())->isNull()
|
||||
;
|
||||
}
|
||||
|
||||
public function testPortraitWithLandscapeImage()
|
||||
{
|
||||
$this
|
||||
->given($image = $this->image(__DIR__.'/../200x100.jpg',100,200))
|
||||
->integer($image->width())->isEqualTo(100)
|
||||
->integer($image->height())->isEqualTo(50)
|
||||
->variable($image->sizer()->resizeToWidth())->isEqualTo(100)
|
||||
->variable($image->sizer()->resizeToHeight())->isEqualTo(50)
|
||||
->variable($image->sizer()->cropToWidth())->isNull()
|
||||
->variable($image->sizer()->cropToHeight())->isNull()
|
||||
;
|
||||
}
|
||||
|
||||
public function testLandscapeWhenImageIsTaller()
|
||||
{
|
||||
$this
|
||||
->given($image = $this->image(__DIR__.'/../200x100.jpg',150,100))
|
||||
->integer($image->width())->isEqualTo(150)
|
||||
->integer($image->height())->isEqualTo(75)
|
||||
->variable($image->sizer()->resizeToWidth())->isEqualTo(150)
|
||||
->variable($image->sizer()->resizeToHeight())->isEqualTo(75)
|
||||
->variable($image->sizer()->cropToWidth())->isNull()
|
||||
->variable($image->sizer()->cropToHeight())->isNull()
|
||||
;
|
||||
}
|
||||
|
||||
public function testLandscapeWhenImageIsShorter()
|
||||
{
|
||||
$this
|
||||
->given($image = $this->image(__DIR__.'/../200x100.jpg',300,75))
|
||||
->integer($image->width())->isEqualTo(150)
|
||||
->integer($image->height())->isEqualTo(75)
|
||||
->variable($image->sizer()->resizeToWidth())->isEqualTo(150)
|
||||
->variable($image->sizer()->resizeToHeight())->isEqualTo(75)
|
||||
->variable($image->sizer()->cropToWidth())->isNull()
|
||||
->variable($image->sizer()->cropToHeight())->isNull()
|
||||
;
|
||||
}
|
||||
|
||||
public function testLandscapeWithSquareImage()
|
||||
{
|
||||
$this
|
||||
->given($image = $this->image(__DIR__.'/../200x200.jpg',300,75))
|
||||
->integer($image->width())->isEqualTo(75)
|
||||
->integer($image->height())->isEqualTo(75)
|
||||
->variable($image->sizer()->resizeToWidth())->isEqualTo(75)
|
||||
->variable($image->sizer()->resizeToHeight())->isEqualTo(75)
|
||||
->variable($image->sizer()->cropToWidth())->isNull()
|
||||
->variable($image->sizer()->cropToHeight())->isNull()
|
||||
;
|
||||
}
|
||||
|
||||
public function testLandscapeWithPortraitImage()
|
||||
{
|
||||
$this
|
||||
->given($image = $this->image(__DIR__.'/../100x200.jpg',200,100))
|
||||
->integer($image->width())->isEqualTo(50)
|
||||
->integer($image->height())->isEqualTo(100)
|
||||
->variable($image->sizer()->resizeToWidth())->isEqualTo(50)
|
||||
->variable($image->sizer()->resizeToHeight())->isEqualTo(100)
|
||||
->variable($image->sizer()->cropToWidth())->isNull()
|
||||
->variable($image->sizer()->cropToHeight())->isNull()
|
||||
;
|
||||
}
|
||||
|
||||
public function testWithSmallSquareImage()
|
||||
{
|
||||
$this
|
||||
->given($image = $this->image(__DIR__.'/../200x200.jpg',300,300))
|
||||
->integer($image->width())->isEqualTo(300)
|
||||
->integer($image->height())->isEqualTo(300)
|
||||
->variable($image->sizer()->resizeToWidth())->isEqualTo(300)
|
||||
->variable($image->sizer()->resizeToHeight())->isEqualTo(300)
|
||||
->variable($image->sizer()->cropToWidth())->isNull()
|
||||
->variable($image->sizer()->cropToHeight())->isNull()
|
||||
;
|
||||
}
|
||||
|
||||
public function testWithSmallLandscapeImage()
|
||||
{
|
||||
$this
|
||||
->given($image = $this->image(__DIR__.'/../200x100.jpg',300,300))
|
||||
->integer($image->width())->isEqualTo(300)
|
||||
->integer($image->height())->isEqualTo(150)
|
||||
->variable($image->sizer()->resizeToWidth())->isEqualTo(300)
|
||||
->variable($image->sizer()->resizeToHeight())->isEqualTo(150)
|
||||
->variable($image->sizer()->cropToWidth())->isNull()
|
||||
->variable($image->sizer()->cropToHeight())->isNull()
|
||||
;
|
||||
}
|
||||
|
||||
public function testWithSmallPortraitImage()
|
||||
{
|
||||
$this
|
||||
->given($image = $this->image(__DIR__.'/../100x200.jpg',300,300))
|
||||
->integer($image->width())->isEqualTo(150)
|
||||
->integer($image->height())->isEqualTo(300)
|
||||
->variable($image->sizer()->resizeToWidth())->isEqualTo(150)
|
||||
->variable($image->sizer()->resizeToHeight())->isEqualTo(300)
|
||||
->variable($image->sizer()->cropToWidth())->isNull()
|
||||
->variable($image->sizer()->cropToHeight())->isNull()
|
||||
;
|
||||
}
|
||||
|
||||
protected function image(string $path, int $width, int $height)
|
||||
{
|
||||
$driver = new MockDriver();
|
||||
return $driver->image($path, new SizerUnderTest($width, $height));
|
||||
}
|
||||
}
|
9
tests/units/mock/MockDriver.php
Normal file
9
tests/units/mock/MockDriver.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
/* image-transform | https://github.com/jobyone/image-transform | MIT License */
|
||||
namespace ByJoby\ImageTransform\tests\units\mock;
|
||||
|
||||
use ByJoby\ImageTransform\Drivers\AbstractDriver;
|
||||
|
||||
class MockDriver extends AbstractDriver
|
||||
{
|
||||
}
|
Loading…
Reference in a new issue