From 8686f9ddd7f48e9440e7f6905c591618ed53b427 Mon Sep 17 00:00:00 2001 From: Joby Elliott Date: Thu, 1 Oct 2020 12:45:56 -0600 Subject: [PATCH] starting to add tests --- .atoum.php | 30 ++++++ .travis.yml | 9 ++ composer.json | 3 + tests/units/100x200.jpg | Bin 0 -> 4962 bytes tests/units/200x100.jpg | Bin 0 -> 4067 bytes tests/units/200x200.jpg | Bin 0 -> 5747 bytes tests/units/Sizers/Cover.php | 165 +++++++++++++++++++++++++++++- tests/units/Sizers/Fit.php | 173 ++++++++++++++++++++++++++++++++ tests/units/mock/MockDriver.php | 9 ++ 9 files changed, 388 insertions(+), 1 deletion(-) create mode 100644 .atoum.php create mode 100644 .travis.yml create mode 100644 tests/units/100x200.jpg create mode 100644 tests/units/200x100.jpg create mode 100644 tests/units/200x200.jpg create mode 100644 tests/units/Sizers/Fit.php create mode 100644 tests/units/mock/MockDriver.php diff --git a/.atoum.php b/.atoum.php new file mode 100644 index 0000000..3d84643 --- /dev/null +++ b/.atoum.php @@ -0,0 +1,30 @@ +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); + } +} diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..47f4af2 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: php +php: + - 7.1 + - 7.2 + - 7.3 + - 7.4 +install: + - composer install +script: composer test diff --git a/composer.json b/composer.json index 58ccc06..891466d 100644 --- a/composer.json +++ b/composer.json @@ -30,5 +30,8 @@ "psr-4": { "ByJoby\\ImageTransform\\tests\\": "tests/" } + }, + "scripts": { + "test": "./vendor/bin/atoum -d tests" } } diff --git a/tests/units/100x200.jpg b/tests/units/100x200.jpg new file mode 100644 index 0000000000000000000000000000000000000000..aa3bcc59b36580b5330bc227f5ccd87c6e6c94cb GIT binary patch literal 4962 zcmeHJc{r3^8-HdowyBJ*vSds}DYMx!OhYraLKu6Nn3))wrJ1p(RiQnF7^NhX(rZce z;-x|em9>aolp>$8yjhCo8@+9RynWaA$M?^7UESC9T-Q1GxqrX=KIi<-Igj|6xDQxn z70KKI0CskIfDG{6#3KNL5=IM+0zd#%;x-2WaUW!Tut2~iU@&YxI)KgzWT0sr7A7)) zi@~9>7{Htq$qk@|G6cv#Mi7%tM2X5OQAj48i1ILUz&dcrj9{j1G><`zc66mhhtf>x zDAGoxc_bl{#bq%B0mw+!PBxzqNkn}nCrH{0ZVU?fIYbajL|HCmMS40oA;}yb18I!L z>eH}TJkrDzjWaehG{&w+;<0!v25W@D;q`IG1gs$eXM+4mM?H&e6RN(iTSQkTn5I4!RLhWXbegC z$^|f&K;|(51RS0#hqLqRDmn#o1RQ=ahl|AH(0Jq;4VEtWsUVkE_27IyZBo&M^Q z$Y-JXO}CQHH{~I+m^D((W{5J_nW2m&Ah!xte&X+i6U^!P6{>`X4TsH}p@@wf*5k8Z_o=ge1D zTU{L{tK1mT?tB4JJMd)rRoa!dBS+6~JF+>Ea0cm&O5+!L-)tuC2|n2v50OrJe$tUy zAdGm84_tSS@A;c<@6JrO)}>cVWOU>eRSU~rlzOJ$Sl;Hf@{ViMa3kb32jQ!UI%Wau zS6qFnX@}P%!sd)=X+?*(fLLCr7= zEPJ5(&~^5-eu_@Mb(pH{sER>!F)+KW+QY{7vI6K%Tq51TD}~pbluNub!IPc#3nz2>5Jbh4l3c=Sl?{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CZ#S)J-qj z?VccdNY0V9xo=#Cb(2f8x`X-Rt3p*PENW-fN$j-gI>H_QB4V2ae0Ftj74|?h9OyShnbQ`?zaom)%ST zth=U9uSnn9V?x$q*G{aF$U;I+R*i4NCAa1sZ?|dW?9nu-3|3QNcV7J#ofu@_o#eyu zk+t?rSILJTnqM4V1H#c&2Lf#9K1}V48#lhuiHw?A1M#G1*RCl*NsQmym2eW{GxDLN zekqJ{a4IrSuKiSRPW{&RrMOyLQ~%M_mm#3ZQ{tJwiI7yKTYyTs2)m8Z1j$|G#<`G zH)o2c@bpUp#}%$#Tz33CL^7}qkxOwgQx572xWh)X3XiHI%RlHHGJ2^>K5k1Ty74z! zX>eYqCZBYtM!of!N)wkTXHfjjO!KOSKkHsDN6xT!T-cv+Y*p45M>gu*6GG-Z%9}SG4PAbx&rTe^n?2qEt65IJcYd}cL^-TL9PiOPyfCA} zcnW)GBOl$A$4eQEjm$PQ0|3BFnrs&p-Isd26M2WDg%z%Q3v=TN=+F-rLv@wlx}w-V zyz`T|8lmgyog=IpQQ4_2X|`Z9bZaFTE^ABZ)uj;{?DpJ~#-&-@1mF;e7^U)9+taoHw= z##rJ$*^};e+H)4M`MH`eiz(GAdx0QywfLQEvgL_ZT(W2MI@iRD_&ZesuoPHn2H%(O6`!!Mk^W2hqf=J^yc*){#U2 literal 0 HcmV?d00001 diff --git a/tests/units/200x200.jpg b/tests/units/200x200.jpg new file mode 100644 index 0000000000000000000000000000000000000000..6a4cf3e0a48510db9693e0344ecebc315d26f62e GIT binary patch literal 5747 zcmeHLc{J4D`@dr_k_I8l8tJPnV{A2KkclLbJu1tXth1QK9!k<8Q?i7zBw3Y`8?;m&$;)x&+~eg``qWe?`3u{2Y|>CKlgJ0 z7#ZycT;MNaP6B=m4eRL-Ab_34J_G=B0IJ|drIIue2m(dP$%W{QQ^FGQ2tOwh0;!~o z0Ecw^NKRN!997C0=ju+-mY#W4E-mHmqAhKsZlY{L(#N^E9}OVmECNngVgo#}C>LoR zwA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IW3*E!KS%{$c*OK?gGS=x1=qnV=cYCL&;QOOEZd=rgF`hi`6BJ^+p*+E`Bs z)TQ^yFso&T64$$6EiVDmD`^HBn;GElHJ%;yoTNx(*Ys+S`IP5(Ex+w;O`Y7K+yR>h zoFc35_4JdxcX#$(z0%F8k}U>cktQ`}srqalWLaPw<`e3i(1!=k0Bi|gNd*9&ysTO= zUal?sM&wBi{vtux<&2c>F#xg84i;-XABAl@xSClC|FkITaM1o`jQGWBQLqsTDkc5p zhp0yE=Q9SnA9yK!bctpt;SRyT>w!ow`4sYwe;`x6Sw*D z;JJ*@_o;l7x0BZ&aBa~A@-#$c!jpoAfJ{m1Qd-wWrRSHezUE>1wv~>OAAtyVMwSDP zuZnOD*el~DQulxaB#;Nh4`1Nfl3g1EQQFo8x#sHs3~~j4y~5+60B8mdH$ijO=HuC& z%f*YgJU?@bdI2H_I0zZvDe8+Ty5-Px^1PNq2R>+kFmC3vRm2Or0-!wShf~uUpWmFE n!BpYHc3MUOX!YKqEVJDg)KS|*W#7EgWxcy-gdzceF+2YalxG~F literal 0 HcmV?d00001 diff --git a/tests/units/Sizers/Cover.php b/tests/units/Sizers/Cover.php index ba9f46e..cb54cf2 100644 --- a/tests/units/Sizers/Cover.php +++ b/tests/units/Sizers/Cover.php @@ -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)); + } } diff --git a/tests/units/Sizers/Fit.php b/tests/units/Sizers/Fit.php new file mode 100644 index 0000000..d8f9865 --- /dev/null +++ b/tests/units/Sizers/Fit.php @@ -0,0 +1,173 @@ +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)); + } +} diff --git a/tests/units/mock/MockDriver.php b/tests/units/mock/MockDriver.php new file mode 100644 index 0000000..7883a42 --- /dev/null +++ b/tests/units/mock/MockDriver.php @@ -0,0 +1,9 @@ +