Skip to content

Commit

Permalink
Merge pull request #55 from vfalies/php7.4Compatibility
Browse files Browse the repository at this point in the history
Php Versions
  • Loading branch information
vfalies authored Apr 29, 2021
2 parents 036225b + 321db87 commit 95cb4c6
Show file tree
Hide file tree
Showing 34 changed files with 616 additions and 268 deletions.
33 changes: 19 additions & 14 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,36 @@ build:
tests:
override:
-
command: 'vendor/bin/phpunit --coverage-clover=coverage.clover'
coverage:
file: 'coverage.clover'
format: 'clover'

command: 'vendor/bin/phpunit'
php72:
environment:
php:
version: 7.2
tests:
override:
-
command: 'vendor/bin/phpunit --coverage-clover=coverage.clover'
coverage:
file: 'coverage.clover'
format: 'clover'

command: 'vendor/bin/phpunit'
php73:
environment:
php:
version: 7.3
tests:
override:
-
command: 'vendor/bin/phpunit --coverage-clover=coverage.clover'
coverage:
file: 'coverage.clover'
format: 'clover'
command: 'vendor/bin/phpunit'
php74:
environment:
php:
version: 7.4
tests:
override:
-
command: 'vendor/bin/phpunit'
php8:
environment:
php:
version: 8.0
tests:
override:
-
command: 'vendor/bin/phpunit'
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ php:
- '7.1'
- '7.2'
- '7.3'
- '7.4'
- '8.0'

env:
global:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Tmdb - PHP Wrapper for The Movie Database API V3

[![Latest Stable Version](https://poser.pugx.org/vfalies/tmdb/version)](https://packagist.org/packages/vfalies/tmdb) [![Build Status](https://scrutinizer-ci.com/g/vfalies/tmdb/badges/build.png?b=master)](https://scrutinizer-ci.com/g/vfalies/tmdb/build-status/master) [![Code Coverage](https://scrutinizer-ci.com/g/vfalies/tmdb/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/vfalies/tmdb/?branch=master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/vfalies/tmdb/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/vfalies/tmdb/?branch=master) [![License](https://poser.pugx.org/vfalies/tmdb/license)](https://packagist.org/packages/vfalies/tmdb) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/6bf2cf4c-4b74-4a06-a5ca-afcc259df86e/mini.png)](https://insight.sensiolabs.com/projects/6bf2cf4c-4b74-4a06-a5ca-afcc259df86e)
[![Latest Stable Version](https://poser.pugx.org/vfalies/tmdb/version)](https://packagist.org/packages/vfalies/tmdb) ![Packagist PHP Version Support](https://img.shields.io/packagist/php-v/vfalies/tmdb) [![Build Status](https://scrutinizer-ci.com/g/vfalies/tmdb/badges/build.png?b=master)](https://scrutinizer-ci.com/g/vfalies/tmdb/build-status/master) [![Code Coverage](https://scrutinizer-ci.com/g/vfalies/tmdb/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/vfalies/tmdb/?branch=master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/vfalies/tmdb/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/vfalies/tmdb/?branch=master) [![License](https://poser.pugx.org/vfalies/tmdb/license)](https://packagist.org/packages/vfalies/tmdb)

Tmdb is a PHP wrapper for [The Movie Database](https://www.themoviedb.org/) API [V3](https://developers.themoviedb.org).

Expand Down
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@
"email": "vincent@vfac.fr"
}
],
"minimum-stability": "dev",
"require": {
"php": ">= 7.1",
"psr/log": "~1.0",
"psr/log": "~1.1.3",
"guzzlehttp/guzzle": ">= 6.3"
},
"require-dev": {
"phpunit/phpunit": "7.5",
"friendsofphp/php-cs-fixer": "~2.15.3",
"monolog/monolog": "~1.25.1"
"phpunit/phpunit": ">=7.0 <9.5.4",
"friendsofphp/php-cs-fixer": ">=2.15.3",
"monolog/monolog": ">1.25.1"
},
"suggest": {
"monolog/monolog": "Allows more advanced logging of the application flow"
Expand Down
19 changes: 6 additions & 13 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="tests/bootstrap.php" colors="true">
<testsuites>
<testsuite name="Vfac TMDB Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<testsuites>
<testsuite name="Vfac TMDB Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>

<!--
<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="coverage-html" target="logs/build/coverage" lowUpperBound="35" highLowerBound="70"/>
</logging>
-->

</phpunit>
2 changes: 1 addition & 1 deletion src/VfacTmdb/Tmdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Tmdb implements TmdbInterface
* @param LoggerInterface $logger Logger used in the class
* @param HttpRequestInterface $http_request
*/
public function __construct(string $api_key, int $version = 3, LoggerInterface $logger, HttpRequestInterface $http_request)
public function __construct(string $api_key, int $version, LoggerInterface $logger, HttpRequestInterface $http_request)
{
$this->api_key = $api_key;
$this->logger = $logger;
Expand Down
137 changes: 105 additions & 32 deletions tests/VfacTmdb/Account/FavoriteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,32 @@ public function tearDown() : void
public function createSession()
{
$json_object = json_decode(file_get_contents('tests/json/sessionOk.json'));
$this->tmdb->expects($this->at(0))->method('sendRequest')->willReturn($json_object);
$this->tmdb->method('sendRequest')->willReturn($json_object);

$this->auth = new Auth($this->tmdb);
return $this->auth->createSession('991c25974a2fcf3d923ae722f46e9c44788ff3ea');
}

public function testGetMovies()
{
$session_id = $this->createSession();
$sessionOk = json_decode(file_get_contents('tests/json/sessionOk.json'));
$configurationOk = json_decode(file_get_contents('tests/json/configurationOk.json'));
$accountOk = json_decode(file_get_contents('tests/json/accountOk.json'));
$accountFavoriteMoviesOk = json_decode(file_get_contents('tests/json/accountFavoriteMoviesOk.json'));

$this->tmdb->method('sendRequest')
->will($this->onConsecutiveCalls(
$sessionOk,
$configurationOk,
$accountOk,
$accountFavoriteMoviesOk
));

$this->auth = new Auth($this->tmdb);
$session_id = $this->auth->createSession('991c25974a2fcf3d923ae722f46e9c44788ff3ea');

$this->tmdb->expects($this->at(0))->method('sendRequest')->willReturn(json_decode(file_get_contents('tests/json/configurationOk.json')));
$this->tmdb->expects($this->at(1))->method('sendRequest')->willReturn(json_decode(file_get_contents('tests/json/accountOk.json')));
$account = new Account($this->tmdb, $session_id);

$this->tmdb->expects($this->at(0))->method('sendRequest')->willReturn(json_decode(file_get_contents('tests/json/accountFavoriteMoviesOk.json')));
$favorite = $account->getFavorite();
$movies = $favorite->getMovies();

Expand All @@ -71,13 +82,23 @@ public function testGetMovies()

public function testGetTVShows()
{
$session_id = $this->createSession();
$sessionOk = json_decode(file_get_contents('tests/json/sessionOk.json'));
$configurationOk = json_decode(file_get_contents('tests/json/configurationOk.json'));
$accountOk = json_decode(file_get_contents('tests/json/accountOk.json'));
$accountFavoriteMoviesOk = json_decode(file_get_contents('tests/json/accountFavoriteTVShowsOk.json'));

$this->tmdb->method('sendRequest')
->will($this->onConsecutiveCalls(
$sessionOk,
$configurationOk,
$accountOk,
$accountFavoriteMoviesOk
));

$this->tmdb->expects($this->at(0))->method('sendRequest')->willReturn(json_decode(file_get_contents('tests/json/configurationOk.json')));
$this->tmdb->expects($this->at(1))->method('sendRequest')->willReturn(json_decode(file_get_contents('tests/json/accountOk.json')));
$this->auth = new Auth($this->tmdb);
$session_id = $this->auth->createSession('991c25974a2fcf3d923ae722f46e9c44788ff3ea');
$account = new Account($this->tmdb, $session_id);

$this->tmdb->expects($this->at(0))->method('sendRequest')->willReturn(json_decode(file_get_contents('tests/json/accountFavoriteTVShowsOk.json')));
$tvs = $account->getFavorite()->getTVShows();

$this->assertEquals('/3/account/'.$account->getId().'/favorite/tv', parse_url($this->tmdb->url, PHP_URL_PATH));
Expand All @@ -87,30 +108,49 @@ public function testGetTVShows()
}
}

/**
* @expectedException \VfacTmdb\Exceptions\ServerErrorException
*/
public function testMarkMovieAsFavoriteFailed()
{
$session_id = $this->createSession();
$sessionOk = json_decode(file_get_contents('tests/json/sessionOk.json'));
$configurationOk = json_decode(file_get_contents('tests/json/configurationOk.json'));
$accountOk = json_decode(file_get_contents('tests/json/accountOk.json'));

$this->tmdb->method('sendRequest')
->will($this->onConsecutiveCalls(
$sessionOk,
$configurationOk,
$accountOk,
$this->throwException(new ServerErrorException)
));

$this->tmdb->expects($this->at(0))->method('sendRequest')->willReturn(json_decode(file_get_contents('tests/json/configurationOk.json')));
$this->tmdb->expects($this->at(1))->method('sendRequest')->willReturn(json_decode(file_get_contents('tests/json/accountOk.json')));
$this->auth = new Auth($this->tmdb);
$session_id = $this->auth->createSession('991c25974a2fcf3d923ae722f46e9c44788ff3ea');
$account = new Account($this->tmdb, $session_id);

$this->tmdb->expects($this->at(0))->method('sendRequest')->will($this->throwException(new ServerErrorException));
$this->expectException(\VfacTmdb\Exceptions\ServerErrorException::class);

$fav = $account->getFavorite()->markMovieAsFavorite(11);
}

public function testMarkMovieAsFavorite()
{
$session_id = $this->createSession();
$sessionOk = json_decode(file_get_contents('tests/json/sessionOk.json'));
$configurationOk = json_decode(file_get_contents('tests/json/configurationOk.json'));
$accountOk = json_decode(file_get_contents('tests/json/accountOk.json'));
$accountFavoriteMoviesOk = json_decode(file_get_contents('tests/json/accountMarkFavoriteOk.json'));

$this->tmdb->method('sendRequest')
->will($this->onConsecutiveCalls(
$sessionOk,
$configurationOk,
$accountOk,
$accountFavoriteMoviesOk
));

$this->auth = new Auth($this->tmdb);
$session_id = $this->auth->createSession('991c25974a2fcf3d923ae722f46e9c44788ff3ea');

$this->tmdb->expects($this->at(0))->method('sendRequest')->willReturn(json_decode(file_get_contents('tests/json/configurationOk.json')));
$this->tmdb->expects($this->at(1))->method('sendRequest')->willReturn(json_decode(file_get_contents('tests/json/accountOk.json')));
$account = new Account($this->tmdb, $session_id);

$this->tmdb->expects($this->at(0))->method('sendRequest')->willReturn(json_decode(file_get_contents('tests/json/accountMarkFavoriteOk.json')));
$fav = $account->getFavorite()->markMovieAsFavorite(11);

$this->assertEquals('/3/account/'.$account->getId().'/favorite', parse_url($this->tmdb->url, PHP_URL_PATH));
Expand All @@ -119,13 +159,24 @@ public function testMarkMovieAsFavorite()

public function testUnMarkMovieAsFavorite()
{
$session_id = $this->createSession();
$sessionOk = json_decode(file_get_contents('tests/json/sessionOk.json'));
$configurationOk = json_decode(file_get_contents('tests/json/configurationOk.json'));
$accountOk = json_decode(file_get_contents('tests/json/accountOk.json'));
$accountFavoriteMoviesOk = json_decode(file_get_contents('tests/json/accountMarkFavoriteOk.json'));

$this->tmdb->method('sendRequest')
->will($this->onConsecutiveCalls(
$sessionOk,
$configurationOk,
$accountOk,
$accountFavoriteMoviesOk
));

$this->auth = new Auth($this->tmdb);
$session_id = $this->auth->createSession('991c25974a2fcf3d923ae722f46e9c44788ff3ea');

$this->tmdb->expects($this->at(0))->method('sendRequest')->willReturn(json_decode(file_get_contents('tests/json/configurationOk.json')));
$this->tmdb->expects($this->at(1))->method('sendRequest')->willReturn(json_decode(file_get_contents('tests/json/accountOk.json')));
$account = new Account($this->tmdb, $session_id);

$this->tmdb->expects($this->at(0))->method('sendRequest')->willReturn(json_decode(file_get_contents('tests/json/accountMarkFavoriteOk.json')));
$fav = $account->getFavorite()->unmarkMovieAsFavorite(11);

$this->assertEquals('/3/account/'.$account->getId().'/favorite', parse_url($this->tmdb->url, PHP_URL_PATH));
Expand All @@ -134,13 +185,24 @@ public function testUnMarkMovieAsFavorite()

public function testMarkTVShowAsFavorite()
{
$session_id = $this->createSession();
$sessionOk = json_decode(file_get_contents('tests/json/sessionOk.json'));
$configurationOk = json_decode(file_get_contents('tests/json/configurationOk.json'));
$accountOk = json_decode(file_get_contents('tests/json/accountOk.json'));
$accountFavoriteMoviesOk = json_decode(file_get_contents('tests/json/accountMarkFavoriteOk.json'));

$this->tmdb->method('sendRequest')
->will($this->onConsecutiveCalls(
$sessionOk,
$configurationOk,
$accountOk,
$accountFavoriteMoviesOk
));

$this->auth = new Auth($this->tmdb);
$session_id = $this->auth->createSession('991c25974a2fcf3d923ae722f46e9c44788ff3ea');

$this->tmdb->expects($this->at(0))->method('sendRequest')->willReturn(json_decode(file_get_contents('tests/json/configurationOk.json')));
$this->tmdb->expects($this->at(1))->method('sendRequest')->willReturn(json_decode(file_get_contents('tests/json/accountOk.json')));
$account = new Account($this->tmdb, $session_id);

$this->tmdb->expects($this->at(0))->method('sendRequest')->willReturn(json_decode(file_get_contents('tests/json/accountMarkFavoriteOk.json')));
$fav = $account->getFavorite()->markTVShowAsFavorite(11);

$this->assertEquals('/3/account/'.$account->getId().'/favorite', parse_url($this->tmdb->url, PHP_URL_PATH));
Expand All @@ -149,13 +211,24 @@ public function testMarkTVShowAsFavorite()

public function testUnMarkTVShowAsFavorite()
{
$session_id = $this->createSession();
$sessionOk = json_decode(file_get_contents('tests/json/sessionOk.json'));
$configurationOk = json_decode(file_get_contents('tests/json/configurationOk.json'));
$accountOk = json_decode(file_get_contents('tests/json/accountOk.json'));
$accountFavoriteMoviesOk = json_decode(file_get_contents('tests/json/accountMarkFavoriteOk.json'));

$this->tmdb->method('sendRequest')
->will($this->onConsecutiveCalls(
$sessionOk,
$configurationOk,
$accountOk,
$accountFavoriteMoviesOk
));

$this->auth = new Auth($this->tmdb);
$session_id = $this->auth->createSession('991c25974a2fcf3d923ae722f46e9c44788ff3ea');

$this->tmdb->expects($this->at(0))->method('sendRequest')->willReturn(json_decode(file_get_contents('tests/json/configurationOk.json')));
$this->tmdb->expects($this->at(1))->method('sendRequest')->willReturn(json_decode(file_get_contents('tests/json/accountOk.json')));
$account = new Account($this->tmdb, $session_id);

$this->tmdb->expects($this->at(0))->method('sendRequest')->willReturn(json_decode(file_get_contents('tests/json/accountMarkFavoriteOk.json')));
$fav = $account->getFavorite()->unmarkTVShowAsFavorite(11);

$this->assertEquals('/3/account/'.$account->getId().'/favorite', parse_url($this->tmdb->url, PHP_URL_PATH));
Expand Down
Loading

0 comments on commit 95cb4c6

Please sign in to comment.