Skip to content

Commit

Permalink
Expanding test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Feb 8, 2014
1 parent b07efd4 commit c89dc45
Show file tree
Hide file tree
Showing 8 changed files with 1,317 additions and 25 deletions.
23 changes: 0 additions & 23 deletions lib/Tmdb/Model/Collection/Images.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,27 +163,4 @@ function($key, $value) use ($height) {
}
);
}

/**
* Return a single image that is rated highest
*
* @return ImageFilter|null
*/
public function filterBestVotedImage()
{
$currentImage = null;
$voteAverage = 0;

/**
* @var $image Image
*/
foreach($this as $image) {
if ($image instanceof ImageFilter && $image->getVoteAverage() > $voteAverage) {
$voteAverage = $image->getVoteAverage();
$currentImage = $image;
}
}

return $currentImage;
}
}
167 changes: 167 additions & 0 deletions test/Tmdb/Tests/Factory/ImageFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,31 @@
*/
namespace Tmdb\Tests\Factory;

use Tmdb\Model\Collection\Images;
use Tmdb\Model\Image;

class ImageFactoryTest extends TestCase
{
/**
* @var Images
*/
private $images;

public function setUp()
{
$factory = $this->getFactory();

$movieData = $this->loadByFile('images/movie.json');
$tvData = $this->loadByFile('images/tv.json');
$tvSeasonData = $this->loadByFile('images/tv_season.json');
$tvEpisodeData = $this->loadByFile('images/tv_episode.json');
$personData = $this->loadByFile('images/person.json');

$data = array_merge(array(), array($movieData, $tvData, $tvSeasonData, $tvEpisodeData, $personData));

$this->images = $factory->createCollection($data);
}

/**
* @test
*/
Expand All @@ -31,6 +54,150 @@ public function shouldBeAbleToCreateCollection()
$this->assertEquals(2, count($collection));
}

/**
* @test
*/
public function shouldFilterPosters()
{
$this->setUp();

$posters = $this->images->filterPosters();

foreach($posters as $poster) {
$this->assertInstanceOf('Tmdb\Model\Image\PosterImage', $poster);
}
}

/**
* @test
*/
public function shouldFilterBackdrops()
{
$this->setUp();

$backdrops = $this->images->filterBackdrops();

foreach($backdrops as $backdrop) {
$this->assertInstanceOf('Tmdb\Model\Image\BackdropImage', $backdrop);
}
}

/**
* @test
*/
public function shouldFilterProfiles()
{
$this->setUp();

$profiles = $this->images->filterProfile();

foreach($profiles as $profile) {
$this->assertInstanceOf('Tmdb\Model\Image\ProfileImage', $profile);
}
}

/**
* @test
*/
public function shouldFilterStills()
{
$this->setUp();

$stills = $this->images->filterStills();

foreach($stills as $still) {
$this->assertInstanceOf('Tmdb\Model\Image\StillImage', $still);
}
}

/**
* @test
*/
public function shouldFilterMinHeight()
{
$this->setUp();

$images = $this->images->filterMinHeight(1000);

$this->assertEquals(false, empty($images));

/**
* @var Image $image
*/
foreach($images as $image) {
$this->assertEquals(true, $image->getHeight() >= 1000);
}
}

/**
* @test
*/
public function shouldFilterMinWidth()
{
$this->setUp();

$images = $this->images->filterMinWidth(1000);

$this->assertEquals(false, empty($images));

/**
* @var Image $image
*/
foreach($images as $image) {
$this->assertEquals(true, $image->getWidth() >= 1000);
}
}

/**
* @test
*/
public function shouldFilterMaxHeight()
{
$this->setUp();

$images = $this->images->filterMaxHeight(1000);

$this->assertEquals(false, empty($images));

/**
* @var Image $image
*/
foreach($images as $image) {
$this->assertEquals(true, $image->getHeight() <= 1000);
}
}

/**
* @test
*/
public function shouldFilterMaxWidth()
{
$this->setUp();

$images = $this->images->filterMaxWidth(1000);

$this->assertEquals(false, empty($images));

/**
* @var Image $image
*/
foreach($images as $image) {
$this->assertEquals(true, $image->getWidth() <= 1000);
}
}

/**
* @test
*/
public function shouldFilterBestImage()
{
$this->setUp();

$image = $this->images->filterBestVotedImage();

$this->assertInstanceOf('Tmdb\Model\Image', $image);
}

protected function getFactoryClass()
{
return 'Tmdb\Factory\ImageFactory';
Expand Down
4 changes: 2 additions & 2 deletions test/Tmdb/Tests/Model/Collection/PeopleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public function setUp()
{
$this->collection = new People();

foreach($this->people as $keyword) {
$object = $this->hydrate(new Person(), $keyword);
foreach($this->people as $person) {
$object = $this->hydrate(new Person(), $person);

$this->collection->addPerson($object);
}
Expand Down
142 changes: 142 additions & 0 deletions test/Tmdb/Tests/Resources/images/movie.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
{
"id": 550,
"backdrops": [
{
"file_path": "/8uO0gUM8aNqYLs1OsTBQiXu0fEv.jpg",
"width": 1280,
"height": 720,
"iso_639_1": null,
"aspect_ratio": 1.78,
"vote_average": 6.6470588235294121,
"vote_count": 17
},
{
"file_path": "/8T0hpqWsgzKhWGsXGD8ilkwRPkC.jpg",
"width": 1280,
"height": 720,
"iso_639_1": null,
"aspect_ratio": 1.78,
"vote_average": 6.375,
"vote_count": 12
},
{
"file_path": "/hNFMawyNDWZKKHU4GYCBz1krsRM.jpg",
"width": 1280,
"height": 720,
"iso_639_1": null,
"aspect_ratio": 1.78,
"vote_average": 5.7142857142857144,
"vote_count": 14
},
{
"file_path": "/mMZRKb3NVo5ZeSPEIaNW9buLWQ0.jpg",
"width": 1920,
"height": 1080,
"iso_639_1": null,
"aspect_ratio": 1.78,
"vote_average": 5.5625,
"vote_count": 8
},
{
"file_path": "/9Kr6UzouF674Smw3D9Hp2DlH1Vo.jpg",
"width": 1280,
"height": 720,
"iso_639_1": null,
"aspect_ratio": 1.78,
"vote_average": 5.5499999999999998,
"vote_count": 10
},
{
"file_path": "/eTVdpy2JXaGFit2V2ToZ79v9D7R.jpg",
"width": 1920,
"height": 1080,
"iso_639_1": null,
"aspect_ratio": 1.78,
"vote_average": 5.25,
"vote_count": 12
},
{
"file_path": "/fuSeIUKsizmfiPIwDH7lKiFNQoD.jpg",
"width": 1280,
"height": 720,
"iso_639_1": null,
"aspect_ratio": 1.78,
"vote_average": 4.2999999999999998,
"vote_count": 5
}
],
"posters": [
{
"file_path": "/2lECpi35Hnbpa4y46JX0aY3AWTy.jpg",
"width": 1000,
"height": 1500,
"iso_639_1": "en",
"aspect_ratio": 0.67000000000000004,
"vote_average": 6.1395348837209305,
"vote_count": 43
},
{
"file_path": "/shFj1K58Tn55Qz2p2v0RqxXiXyo.jpg",
"width": 1000,
"height": 1408,
"iso_639_1": "en",
"aspect_ratio": 0.70999999999999996,
"vote_average": 6.0,
"vote_count": 2
},
{
"file_path": "/jQ2iUsXI2jmUcOFGjOaONCLwaVp.jpg",
"width": 675,
"height": 1000,
"iso_639_1": "en",
"aspect_ratio": 0.68000000000000005,
"vote_average": 5.546875,
"vote_count": 32
},
{
"file_path": "/6cMPLU1jv8pG9BMmieXCHDTVRPm.jpg",
"width": 1479,
"height": 2166,
"iso_639_1": "es",
"aspect_ratio": 0.68000000000000005,
"vote_average": 5.375,
"vote_count": 4
},
{
"file_path": "/pKGrxTB35AkLsZCT8d8h6F9BSMN.jpg",
"width": 1000,
"height": 1500,
"iso_639_1": "en",
"aspect_ratio": 0.67000000000000004,
"vote_average": 5.3611111111111107,
"vote_count": 18
},
{
"file_path": "/5qEBvDRdY2S2CJ9tsoFktIt8Xue.jpg",
"width": 2689,
"height": 3539,
"iso_639_1": "es",
"aspect_ratio": 0.76000000000000001,
"vote_average": 5.25,
"vote_count": 2
},
{
"file_path": "/1dTxsr21UmFewu2CJ886JNqqkqn.jpg",
"width": 2030,
"height": 3000,
"iso_639_1": "en",
"aspect_ratio": 0.68000000000000005,
"vote_average": 5.25,
"vote_count": 6
},
{
"file_path": "/olTEZdZJ7UKLE1o4hkFDq4jXBs8.jpg",
"width": 713,
"height": 1002,
"iso_639_1": "hu",
"aspect_ratio": 0.70999999999999996,
"vote_average": 5.25,
"vote_count": 2
}
]
}
26 changes: 26 additions & 0 deletions test/Tmdb/Tests/Resources/images/person.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"id": 287,
"profiles": [
{
"file_path": "/w8zJQuN7tzlm6FY9mfGKihxp3Cb.jpg",
"width": 1295,
"height": 1969,
"iso_639_1": null,
"aspect_ratio": 0.66000000000000003
},
{
"file_path": "/cLUacutO7dOMksQK8Zg0q2Gybsx.jpg",
"width": 820,
"height": 1230,
"iso_639_1": null,
"aspect_ratio": 0.67000000000000004
},
{
"file_path": "/zEbgoayf0MfuSznehhXdaP2YkeH.jpg",
"width": 700,
"height": 983,
"iso_639_1": null,
"aspect_ratio": 0.70999999999999996
}
]
}
Loading

0 comments on commit c89dc45

Please sign in to comment.