Skip to content

Commit

Permalink
Upgraded code base to support PHP 8.0 & PHPUnit 9 (#47)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
carlos-mg89 authored May 16, 2022
1 parent 1a832b8 commit 6a7570c
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 19 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}

Expand All @@ -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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
/tests/config.php
/config.php
/cache/

.phpunit.result.cache
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
4 changes: 2 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
colors="true"
bootstrap="vendor/autoload.php">

<testsuites>
<testsuite>
<testsuite name="Library's tests">
<directory>tests</directory>
</testsuite>
</testsuites>
Expand Down
2 changes: 1 addition & 1 deletion src/PhotosetsApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/TestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/ApiMethodGroup/PhotosetsApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class PhotosetsApiTest extends TestCase
{
protected $testPhotoId;

public function setUp()
public function setUp(): void
{
parent::setUp();
$flickr = $this->getFlickr(true);
Expand All @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion tests/ApiMethodGroup/TestApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)) {
Expand Down

0 comments on commit 6a7570c

Please sign in to comment.