Skip to content

Commit

Permalink
Merge pull request #2 from rooxie/0.2.1
Browse files Browse the repository at this point in the history
0.2.1
  • Loading branch information
rooxie authored Jun 20, 2019
2 parents 4ff855d + 87dcdb4 commit 0845818
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 52 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ echo $movie->getMetascore(); // 82
```php
Array
(
[ImdbId] => tt0246578
[Title] => Donnie Darko
[Year] => 2001
[Rated] => R
Expand Down Expand Up @@ -93,6 +94,7 @@ Array
)

[Awards] => 11 wins & 15 nominations.
[Poster] => https://m.media-amazon.com/images/M/MV5BZjZlZDlkYTktMmU1My00ZDBiLWFlNjEtYTBhNjVhOTM4ZjJjXkEyXkFqcGdeQXVyMTMxODk2OTU@._V1_.jpg
[Type] => movie
[DVD] => 19 Mar 2002
[BoxOffice] => N/A
Expand All @@ -103,7 +105,7 @@ Array
[IMDbRating] => 8.1
[IMDbVotes] => 695608
[TotalSeasons] => N/A
[seriesID] => N/A
[SeriesID] => N/A
[Season] => N/A
[Episode] => N/A
)
Expand Down
4 changes: 3 additions & 1 deletion src/Model/Movie.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ public function getEpisode(): string
public function toArray(): array
{
return [
'ImdbId' => $this->imdbId,
'Title' => $this->title,
'Year' => $this->year,
'Rated' => $this->rated,
Expand All @@ -540,6 +541,7 @@ public function toArray(): array
'Language' => $this->language,
'Country' => $this->country,
'Awards' => $this->awards,
'Poster' => $this->posterUrl,
'Type' => $this->type,
'DVD' => $this->dvd,
'BoxOffice' => $this->boxOffice,
Expand All @@ -550,7 +552,7 @@ public function toArray(): array
'IMDbRating' => $this->imdbRating,
'IMDbVotes' => $this->imdbVotes,
'TotalSeasons' => $this->totalSeasons,
'seriesID' => $this->seriesImdbId,
'SeriesID' => $this->seriesImdbId,
'Season' => $this->season,
'Episode' => $this->episode,
];
Expand Down
23 changes: 5 additions & 18 deletions tests/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,13 @@ protected function sample(string $path)
}

/**
* Provides access to OMDb::class protected method by method named.
* Invoke private method of OMDb::class and returns it's result.
*
* @param string $methodName
* @param string $name
* @param array $args
*
* @return ReflectionMethod
* @return mixed
*/
protected function getOmdbProtectedMethod(string $methodName): ReflectionMethod
{
try {
$omdbRef = new ReflectionClass(OMDb::class);
$methodRef = $omdbRef->getMethod($methodName);

$methodRef->setAccessible(true);

return $methodRef;
} catch (ReflectionException $e) {
$this->fail("Couldn'n create OMDb class reflection, got: ".$e->getMessage());
}
}

protected function invokeOmdbMethod(string $name, array $args)
{
try {
Expand All @@ -66,7 +53,7 @@ protected function invokeOmdbMethod(string $name, array $args)

return $method->invokeArgs(new OMDb('.......'), $args);
} catch (ReflectionException $e) {
$this->fail("Couldn'n create OMDb class reflection, got: ".$e->getMessage());
$this->fail("Couldn't create OMDb class reflection, got: ".$e->getMessage());
}
}
}
109 changes: 77 additions & 32 deletions tests/MovieModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private function positiveCreateTitleTest(array $title): void
$movie = $this->invokeOmdbMethod('createMovieObject', [$title]);

$this->assertEquals(Movie::class, get_class($movie));
$this->assertMovieModel($movie, $title);
$this->validateResults($movie, $title);
}

/**
Expand Down Expand Up @@ -81,12 +81,12 @@ private function negativeCreateTitleTest(array $title): void
}

/**
* Compares movie data with the data from the created model.
* Compare movie data with the data from the created model.
*
* @param Movie $movie
* @param array $data
*/
private function assertMovieModel(Movie $movie, array $data): void
private function validateResults(Movie $movie, array $data): void
{
$rottenTomatoesRating = 0;

Expand All @@ -97,34 +97,79 @@ private function assertMovieModel(Movie $movie, array $data): void
}
}

$this->assertEquals($movie->getImdbId(), $data['imdbID']);
$this->assertEquals($movie->getTitle(), $data['Title']);
$this->assertEquals($movie->getYear(), $data['Year']);
$this->assertEquals($movie->getRated(), $data['Rated']);
$this->assertEquals($movie->getReleased(), $data['Released']);
$this->assertEquals($movie->getRuntime(), intval($data['Runtime']));
$this->assertEquals($movie->getTitle(), $data['Title']);
$this->assertEquals($movie->getGenre(), explode(', ', $data['Genre']));
$this->assertEquals($movie->getDirector(), explode(', ', $data['Director']));
$this->assertEquals($movie->getWriter(), explode(', ', $data['Writer']));
$this->assertEquals($movie->getActors(), explode(', ', $data['Actors']));
$this->assertEquals($movie->getPlot(), $data['Plot']);
$this->assertEquals($movie->getLanguage(), explode(', ', $data['Language']));
$this->assertEquals($movie->getCountry(), explode(', ', $data['Country']));
$this->assertEquals($movie->getAwards(), $data['Awards']);
$this->assertEquals($movie->getPosterUrl(), $data['Poster']);
$this->assertEquals($movie->getType(), $data['Type']);
$this->assertEquals($movie->getDvd(), $data['DVD'] ?? 'N/A');
$this->assertEquals($movie->getBoxOffice(), $data['BoxOffice'] ?? 'N/A');
$this->assertEquals($movie->getProduction(), $data['Production'] ?? 'N/A');
$this->assertEquals($movie->getWebsite(), $data['Website'] ?? 'N/A');
$this->assertEquals($movie->getMetascore(), $data['Metascore'] === 'N/A' ? 0 : $data['Metascore']);
$this->assertEquals($movie->getRottenTomatoesRating(), $rottenTomatoesRating);
$this->assertEquals($movie->getImdbRating(), floatval($data['imdbRating']));
$this->assertEquals($movie->getImdbVotes(), intval(str_replace(',', '', $data['imdbVotes'])));
$this->assertEquals($movie->getTotalSeasons(), $data['totalSeasons'] ?? 'N/A');
$this->assertEquals($movie->getSeriesImdbId(), $data['seriesID'] ?? 'N/A');
$this->assertEquals($movie->getSeason(), $data['Season'] ?? 'N/A');
$this->assertEquals($movie->getEpisode(), $data['Episode'] ?? 'N/A');
$this->assertMovieModel($movie, [
'ImdbId' => $data['imdbID'],
'Title' => $data['Title'],
'Year' => $data['Year'],
'Rated' => $data['Rated'],
'Released' => $data['Released'],
'Runtime' => intval($data['Runtime']),
'Genre' => explode(', ', $data['Genre']),
'Director' => explode(', ', $data['Director']),
'Writer' => explode(', ', $data['Writer']),
'Actors' => explode(', ', $data['Actors']),
'Plot' => $data['Plot'],
'Language' => explode(', ', $data['Language']),
'Country' => explode(', ', $data['Country']),
'Awards' => $data['Awards'],
'Poster' => $data['Poster'],
'Type' => $data['Type'],
'DVD' => $data['DVD'] ?? 'N/A',
'BoxOffice' => $data['BoxOffice'] ?? 'N/A',
'Production' => $data['Production'] ?? 'N/A',
'Website' => $data['Website'] ?? 'N/A',
'Metascore' => $data['Metascore'] === 'N/A' ? 0 : $data['Metascore'],
'RottenTomatoesRating' => $rottenTomatoesRating,
'IMDbRating' => floatval($data['imdbRating']),
'IMDbVotes' => intval(str_replace(',', '', $data['imdbVotes'])),
'TotalSeasons' => $data['totalSeasons'] ?? 'N/A',
'SeriesID' => $data['seriesID'] ?? 'N/A',
'Season' => $data['Season'] ?? 'N/A',
'Episode' => $data['Season'] ?? 'N/A',
]);

$toArray = $movie->toArray();
$getters = array_filter(get_class_methods($movie), function (string $name) {
return substr($name, 0, 3) === "get";
});

$this->assertEquals(count($toArray), count($getters));
$this->assertMovieModel($movie, $toArray);
}

/**
* @param Movie $movie
* @param array $compare
*/
private function assertMovieModel(Movie $movie, array $compare): void
{
$this->assertEquals($movie->getImdbId(), $compare['ImdbId']);
$this->assertEquals($movie->getTitle(), $compare['Title']);
$this->assertEquals($movie->getYear(), $compare['Year']);
$this->assertEquals($movie->getRated(), $compare['Rated']);
$this->assertEquals($movie->getReleased(), $compare['Released']);
$this->assertEquals($movie->getRuntime(), $compare['Runtime']);
$this->assertEquals($movie->getGenre(), $compare['Genre']);
$this->assertEquals($movie->getDirector(), $compare['Director']);
$this->assertEquals($movie->getWriter(), $compare['Writer']);
$this->assertEquals($movie->getActors(), $compare['Actors']);
$this->assertEquals($movie->getPlot(), $compare['Plot']);
$this->assertEquals($movie->getLanguage(), $compare['Language']);
$this->assertEquals($movie->getCountry(), $compare['Country']);
$this->assertEquals($movie->getAwards(), $compare['Awards']);
$this->assertEquals($movie->getPosterUrl(), $compare['Poster']);
$this->assertEquals($movie->getType(), $compare['Type']);
$this->assertEquals($movie->getDvd(), $compare['DVD']);
$this->assertEquals($movie->getBoxOffice(), $compare['BoxOffice']);
$this->assertEquals($movie->getProduction(), $compare['Production']);
$this->assertEquals($movie->getWebsite(), $compare['Website']);
$this->assertEquals($movie->getMetascore(), $compare['Metascore']);
$this->assertEquals($movie->getRottenTomatoesRating(), $compare['RottenTomatoesRating']);
$this->assertEquals($movie->getImdbRating(), $compare['IMDbRating']);
$this->assertEquals($movie->getImdbVotes(), $compare['IMDbVotes']);
$this->assertEquals($movie->getTotalSeasons(), $compare['TotalSeasons']);
$this->assertEquals($movie->getSeriesImdbId(), $compare['SeriesID']);
$this->assertEquals($movie->getSeason(), $compare['Season']);
$this->assertEquals($movie->getEpisode(), $compare['Episode']);
}
}

0 comments on commit 0845818

Please sign in to comment.