From 6a7570c5fc135cc75a1a281259b1f87683b55628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADnez=20Gadea?= Date: Mon, 16 May 2022 11:36:48 +0200 Subject: [PATCH] Upgraded code base to support PHP 8.0 & PHPUnit 9 (#47) * Upgraded code base to support PHP ^8.0 and PHPUnit * Refactor to make test PHPUnit 9 compliant * Forced lusitanian/oauth dependency with a commit hash that's PHP 8 compliant * Allow PHP 7.4 tests and removed PHP 8.1 (due to Composer dependencies issues) * Prevent crash iv config.php file cannot be found while runnning tests * Added PHPUnit testsuite's name and updated current schema --- .github/workflows/ci.yml | 6 +++--- .gitignore | 2 +- composer.json | 10 +++++----- phpunit.xml.dist | 4 ++-- src/PhotosetsApi.php | 2 +- src/TestApi.php | 2 +- tests/ApiMethodGroup/PhotosetsApiTest.php | 6 +++--- tests/ApiMethodGroup/TestApiTest.php | 4 +++- tests/TestCase.php | 4 ++-- 9 files changed, 21 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 475f6f9..d032142 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: matrix: os: [ ubuntu-latest, macos-latest, windows-latest ] # All supported PHP versions https://www.php.net/supported-versions.php - php: [ '7.2', '7.3', '7.4' ] + php: [ '7.3', '7.4', '8.0' ] runs-on: ${{matrix.os}} @@ -28,10 +28,10 @@ jobs: composer install - name: Test + run: | + composer test env: FLICKR_API_KEY: ${{ secrets.FLICKR_API_KEY }} FLICKR_API_SECRET: ${{ secrets.FLICKR_API_SECRET }} FLICKR_ACCESS_TOKEN: ${{ secrets.FLICKR_ACCESS_TOKEN }} FLICKR_ACCESS_SECRET: ${{ secrets.FLICKR_ACCESS_SECRET }} - run: | - composer test diff --git a/.gitignore b/.gitignore index 04a6d9e..414bf55 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,4 @@ /tests/config.php /config.php /cache/ - +.phpunit.result.cache diff --git a/composer.json b/composer.json index eaaa8cb..0738ea6 100644 --- a/composer.json +++ b/composer.json @@ -14,20 +14,20 @@ } }, "require": { - "php": ">=5.6", + "php": "^7.3 || ^8.0", "ext-curl": "*", "ext-json": "*", "ext-libxml": "*", "ext-simplexml": "*", - "lusitanian/oauth": "^0.8", + "lusitanian/oauth": "dev-master#ee5a83310c6014b6cc07ac0610ec9d67ba452664 as 0.8.12", "psr/cache": "^1.0" }, "require-dev": { - "jakub-onderka/php-parallel-lint": "1.0.0", "squizlabs/php_codesniffer": "^3.0", "mediawiki/minus-x": "^0.3", - "phpunit/phpunit": "^5.0", - "tedivm/stash": "^0.14" + "phpunit/phpunit": "^9.5", + "tedivm/stash": "^0.17.1", + "php-parallel-lint/php-parallel-lint": "^1.3" }, "scripts": { "test": [ diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 7c4d822..fa5bd5d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,10 +1,10 @@ - + tests diff --git a/src/PhotosetsApi.php b/src/PhotosetsApi.php index 4cb54ad..bb8faa1 100644 --- a/src/PhotosetsApi.php +++ b/src/PhotosetsApi.php @@ -35,7 +35,7 @@ public function addPhoto($photosetId, $photoId) * @param string $description A description of the photoset. May contain limited HTML. * @param int $primaryPhotoId The ID of the photo to represent this set. The photo must belong * to the calling user. - * @return bool + * @return bool|mixed[] */ public function create($title, $description, $primaryPhotoId) { diff --git a/src/TestApi.php b/src/TestApi.php index b6e8c47..4dac71f 100644 --- a/src/TestApi.php +++ b/src/TestApi.php @@ -15,7 +15,7 @@ class TestApi extends ApiMethodGroup * @param array $args * @return string[]|bool */ - public function testEcho($args = []) + public function testEcho(array $args = []) { return $this->flickr->request('flickr.test.echo', $args, true); } diff --git a/tests/ApiMethodGroup/PhotosetsApiTest.php b/tests/ApiMethodGroup/PhotosetsApiTest.php index 0bae177..f266526 100644 --- a/tests/ApiMethodGroup/PhotosetsApiTest.php +++ b/tests/ApiMethodGroup/PhotosetsApiTest.php @@ -8,7 +8,7 @@ class PhotosetsApiTest extends TestCase { protected $testPhotoId; - public function setUp() + public function setUp(): void { parent::setUp(); $flickr = $this->getFlickr(true); @@ -17,9 +17,9 @@ public function setUp() $this->testPhotoId = $uploaded['photoid']; } - public function tearDown() + public function tearDown(): void { - $this->getFlickr(true)->photos_delete($this->testPhotoId); + $this->getFlickr(true)->photos()->delete($this->testPhotoId); } public function testCreate() diff --git a/tests/ApiMethodGroup/TestApiTest.php b/tests/ApiMethodGroup/TestApiTest.php index bc0f27a..655bc59 100644 --- a/tests/ApiMethodGroup/TestApiTest.php +++ b/tests/ApiMethodGroup/TestApiTest.php @@ -26,7 +26,9 @@ public function testEchoWithInvalidKey() public function testEcho() { $flickr = $this->getFlickr(); + $echo = $flickr->test()->testEcho(['foo' => 'bar']); - static::assertArraySubset(['foo' => 'bar', 'method' => 'flickr.test.echo'], $echo); + + $this->assertArrayHasKey('foo', $echo); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index bdf290f..14353a2 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -17,7 +17,7 @@ abstract class TestCase extends PhpUnitTestCase * available in tests/config.php. * @return PhpFlickr */ - public function getFlickr($authenticate = false) + public function getFlickr(bool $authenticate = false): PhpFlickr { if ($this->flickr instanceof PhpFlickr) { return $this->flickr; @@ -28,7 +28,7 @@ public function getFlickr($authenticate = false) $apiSecret = getenv('FLICKR_API_SECRET'); $accessToken = getenv('FLICKR_ACCESS_TOKEN'); $accessTokenSecret = getenv('FLICKR_ACCESS_SECRET'); - if (empty($apiKey)) { + if (empty($apiKey) && file_exists(__DIR__ . '/config.php')) { require __DIR__ . '/config.php'; } if (empty($apiKey)) {