forked from php-tmdb/api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing up colletions, factories and cleaning up deprecated methods fr…
…om models.
- Loading branch information
1 parent
2d13dc5
commit 589262a
Showing
13 changed files
with
143 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
/** | ||
* This file is part of the Tmdb PHP API created by Michael Roterman. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Tmdb | ||
* @author Michael Roterman <[email protected]> | ||
* @copyright (c) 2013, Michael Roterman | ||
* @version 0.0.1 | ||
*/ | ||
namespace Tmdb\Factory; | ||
|
||
use Tmdb\Model\Change; | ||
use Tmdb\Model\Collection\Changes; | ||
|
||
class ChangesFactory extends AbstractFactory | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
* @return \Tmdb\Model\Change | ||
*/ | ||
public function create(array $data = array()) | ||
{ | ||
return $this->hydrate(new Change(), $data); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createCollection(array $data = array()) | ||
{ | ||
$collection = new Changes(); | ||
|
||
if (array_key_exists('page', $data)) { | ||
$collection->setPage($data['page']); | ||
} | ||
|
||
if (array_key_exists('total_pages', $data)) { | ||
$collection->setTotalPages($data['total_pages']); | ||
} | ||
|
||
if (array_key_exists('total_results', $data)) { | ||
$collection->setTotalResults($data['total_results']); | ||
} | ||
|
||
if (array_key_exists('results', $data)) { | ||
$data = $data['results']; | ||
} | ||
|
||
foreach($data as $item) { | ||
$collection->add(null, $this->create($item)); | ||
} | ||
|
||
return $collection; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
/** | ||
* This file is part of the Tmdb PHP API created by Michael Roterman. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Tmdb | ||
* @author Michael Roterman <[email protected]> | ||
* @copyright (c) 2013, Michael Roterman | ||
* @version 0.0.1 | ||
*/ | ||
namespace Tmdb\Tests\Factory; | ||
|
||
use Tmdb\Factory\CompanyFactory; | ||
use Tmdb\Model\Collection\Changes; | ||
use Tmdb\Model\Company; | ||
|
||
class ChangesFactoryTest extends TestCase | ||
{ | ||
const COMPANY_ID = 1; | ||
|
||
private $data; | ||
|
||
/** | ||
* @var Changes | ||
*/ | ||
private $changes; | ||
|
||
public function setUp() | ||
{ | ||
$this->data = $this->loadByFile('changes/movies.json'); | ||
|
||
/** | ||
* @var CompanyFactory $factory | ||
*/ | ||
$factory = $this->getFactory(); | ||
|
||
/** | ||
* @var Company $company | ||
*/ | ||
$this->changes = $factory->createCollection($this->data); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldCreateCollection() | ||
{ | ||
$this->assertEquals(true, !empty($this->changes)); | ||
|
||
$this->assertEquals(1, $this->changes->getPage()); | ||
$this->assertEquals(12, $this->changes->getTotalPages()); | ||
$this->assertEquals(1151, $this->changes->getTotalResults()); | ||
|
||
$this->assertEquals(100, count($this->changes)); | ||
} | ||
|
||
protected function getFactoryClass() | ||
{ | ||
return 'Tmdb\Factory\ChangesFactory'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"results":[{"id":253759,"adult":false},{"id":243914,"adult":false},{"id":14324,"adult":false},{"id":253760,"adult":false},{"id":164159,"adult":false},{"id":253761,"adult":false},{"id":10315,"adult":false},{"id":44942,"adult":false},{"id":50457,"adult":false},{"id":15037,"adult":false},{"id":11926,"adult":false},{"id":22798,"adult":false},{"id":44215,"adult":false},{"id":93053,"adult":false},{"id":53505,"adult":false},{"id":122662,"adult":false},{"id":253762,"adult":false},{"id":19850,"adult":false},{"id":47088,"adult":false},{"id":17680,"adult":false},{"id":15285,"adult":false},{"id":40722,"adult":false},{"id":43943,"adult":false},{"id":33542,"adult":false},{"id":251865,"adult":false},{"id":46837,"adult":false},{"id":253763,"adult":false},{"id":47407,"adult":false},{"id":7839,"adult":false},{"id":11831,"adult":false},{"id":20618,"adult":false},{"id":5548,"adult":false},{"id":50687,"adult":false},{"id":205724,"adult":false},{"id":253764,"adult":false},{"id":603,"adult":false},{"id":605,"adult":false},{"id":253765,"adult":false},{"id":62177,"adult":false},{"id":253766,"adult":false},{"id":253767,"adult":false},{"id":253768,"adult":false},{"id":253276,"adult":false},{"id":253769,"adult":false},{"id":253770,"adult":false},{"id":253771,"adult":false},{"id":6973,"adult":false},{"id":389,"adult":false},{"id":253772,"adult":false},{"id":77459,"adult":false},{"id":253773,"adult":false},{"id":53913,"adult":false},{"id":253714,"adult":false},{"id":253774,"adult":false},{"id":253775,"adult":false},{"id":253776,"adult":false},{"id":253511,"adult":false},{"id":253777,"adult":false},{"id":10378,"adult":false},{"id":100402,"adult":false},{"id":253778,"adult":false},{"id":253779,"adult":false},{"id":253780,"adult":false},{"id":253781,"adult":false},{"id":57619,"adult":false},{"id":10013,"adult":false},{"id":25566,"adult":false},{"id":253782,"adult":false},{"id":126838,"adult":false},{"id":109513,"adult":false},{"id":253783,"adult":false},{"id":16632,"adult":false},{"id":51730,"adult":false},{"id":133805,"adult":false},{"id":253784,"adult":false},{"id":152747,"adult":false},{"id":204709,"adult":false},{"id":126755,"adult":false},{"id":9924,"adult":false},{"id":58559,"adult":false},{"id":120932,"adult":false},{"id":41428,"adult":false},{"id":200713,"adult":false},{"id":157370,"adult":false},{"id":97199,"adult":false},{"id":157841,"adult":false},{"id":240745,"adult":false},{"id":84659,"adult":false},{"id":253785,"adult":false},{"id":36810,"adult":false},{"id":250482,"adult":false},{"id":17979,"adult":false},{"id":253786,"adult":false},{"id":6575,"adult":false},{"id":122906,"adult":false},{"id":80797,"adult":false},{"id":166076,"adult":false},{"id":15301,"adult":false},{"id":50620,"adult":false},{"id":50619,"adult":false}],"page":1,"total_pages":12,"total_results":1151} |