diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d032142..0075d4f 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.3', '7.4', '8.0' ] + php: [ '7.3', '7.4', '8.0', '8.1' ] runs-on: ${{matrix.os}} diff --git a/composer.json b/composer.json index 0738ea6..1041d91 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "ext-json": "*", "ext-libxml": "*", "ext-simplexml": "*", - "lusitanian/oauth": "dev-master#ee5a83310c6014b6cc07ac0610ec9d67ba452664 as 0.8.12", + "carlos-mg89/oauth": "^0.8", "psr/cache": "^1.0" }, "require-dev": { diff --git a/tests/ApiMethodGroup/PhotosApiTest.php b/tests/ApiMethodGroup/PhotosApiTest.php index c327b4b..6b86535 100644 --- a/tests/ApiMethodGroup/PhotosApiTest.php +++ b/tests/ApiMethodGroup/PhotosApiTest.php @@ -81,13 +81,29 @@ public function testSetTags() public function testSearch() { $flickr = $this->getFlickr(true); - $testFilename = dirname(__DIR__) . '/../examples/Agateware_Example.JPG'; - $photo = $flickr->uploader()->upload($testFilename); - $search = $flickr->photos()->search([ + $testTitle = uniqid('PhpFlickr search test '); + $searchParams = [ 'user_id' => 'me', - 'text' => 'Agateware_Example', - ]); - static::assertGreaterThan(1, count($search['photo'])); + 'text' => $testTitle, + ]; + + // Make sure there are no search results to start with. + $search = $flickr->photos()->search($searchParams); + static::assertCount(0, $search['photo']); + + // Upload a test photo. + $testFilename = dirname(__DIR__) . '/../examples/Agateware_Example.JPG'; + $photo = $flickr->uploader()->upload($testFilename, $testTitle, null, null, true, null, null, null, 1); + + // Look for search results, looping because it's a new file and can take time to be indexed. + for ($i = 0; $i < 15; $i++) { + sleep(1); + $search = $flickr->photos()->search($searchParams); + if (count($search['photo']) > 0) { + break; + } + } + static::assertGreaterThanOrEqual(1, count($search['photo'])); // Clean up. $flickr->photos()->delete($photo['photoid']); diff --git a/tests/ApiMethodGroup/TestApiTest.php b/tests/ApiMethodGroup/TestApiTest.php index 655bc59..0b949ec 100644 --- a/tests/ApiMethodGroup/TestApiTest.php +++ b/tests/ApiMethodGroup/TestApiTest.php @@ -27,7 +27,11 @@ public function testEcho() { $flickr = $this->getFlickr(); - $echo = $flickr->test()->testEcho(['foo' => 'bar']); + try { + $echo = $flickr->test()->testEcho(['foo' => 'bar']); + } catch (FlickrException $e) { + static::markTestSkipped($e->getMessage()); + } $this->assertArrayHasKey('foo', $echo); } diff --git a/tests/TestCase.php b/tests/TestCase.php index 14353a2..7615897 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -4,12 +4,13 @@ use OAuth\OAuth1\Token\StdOAuth1Token; use PHPUnit\Framework\TestCase as PhpUnitTestCase; +use Samwilson\PhpFlickr\FlickrException; use Samwilson\PhpFlickr\PhpFlickr; abstract class TestCase extends PhpUnitTestCase { - /** @var PhpFlickr */ - private $flickr; + /** @var PhpFlickr[] */ + private $flickrs = []; /** * Get an instance of PhpFlickr, configured by the config.php file in the tests directory. @@ -19,8 +20,9 @@ abstract class TestCase extends PhpUnitTestCase */ public function getFlickr(bool $authenticate = false): PhpFlickr { - if ($this->flickr instanceof PhpFlickr) { - return $this->flickr; + $authed = $authenticate ? 'authed' : 'notauthed'; + if (isset($this->flickrs[$authed])) { + return $this->flickrs[$authed]; } // Get config values from env vars or the tests/config.php file. @@ -35,16 +37,34 @@ public function getFlickr(bool $authenticate = false): PhpFlickr // Skip if no key found, so PRs from forks can still be run in CI. static::markTestSkipped('No Flickr API key set.'); } - $this->flickr = new PhpFlickr($apiKey, $apiSecret); + try { + $this->flickrs[$authed] = new PhpFlickr($apiKey, $apiSecret); + } catch (FlickrException $ex) { + static::markTestSkipped($ex->getMessage()); + } // Authenticate? if ($authenticate && !empty($accessToken) && !empty($accessTokenSecret)) { $token = new StdOAuth1Token(); $token->setAccessToken($accessToken); $token->setAccessTokenSecret($accessTokenSecret); - $this->flickr->getOauthTokenStorage()->storeAccessToken('Flickr', $token); + $this->flickrs[$authed]->getOauthTokenStorage()->storeAccessToken('Flickr', $token); + try { + $authenticated = $this->flickrs[$authed]->test()->login(); + } catch (FlickrException $e) { + $authenticated = false; + } + if (!$authenticated) { + static::markTestSkipped('Unable to authenticate with provided access token.'); + } + } + if ($authenticate && empty($accessToken)) { + static::markTestSkipped( + 'Access token required for this test. ' + . 'Please use examples/get_auth_token.php to get token to add to tests/config.php.' + ); } - return $this->flickr; + return $this->flickrs[$authed]; } }