Skip to content

Commit d6d2415

Browse files
authored
Switch to carlos-mg89/oauth fork of lusitanian/oauth, add PHP 8.1 to CI, and fix failures
* Switch to carlos-mg89/oauth fork of lusitanian/oauth and add PHP 8.1 to CI * Skip tests if unable to authenticate * Skip echo test on exception * Fix up search test
1 parent 6a7570c commit d6d2415

File tree

5 files changed

+56
-16
lines changed

5 files changed

+56
-16
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
matrix:
1010
os: [ ubuntu-latest, macos-latest, windows-latest ]
1111
# All supported PHP versions https://www.php.net/supported-versions.php
12-
php: [ '7.3', '7.4', '8.0' ]
12+
php: [ '7.3', '7.4', '8.0', '8.1' ]
1313

1414
runs-on: ${{matrix.os}}
1515

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"ext-json": "*",
2020
"ext-libxml": "*",
2121
"ext-simplexml": "*",
22-
"lusitanian/oauth": "dev-master#ee5a83310c6014b6cc07ac0610ec9d67ba452664 as 0.8.12",
22+
"carlos-mg89/oauth": "^0.8",
2323
"psr/cache": "^1.0"
2424
},
2525
"require-dev": {

tests/ApiMethodGroup/PhotosApiTest.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,29 @@ public function testSetTags()
8181
public function testSearch()
8282
{
8383
$flickr = $this->getFlickr(true);
84-
$testFilename = dirname(__DIR__) . '/../examples/Agateware_Example.JPG';
85-
$photo = $flickr->uploader()->upload($testFilename);
86-
$search = $flickr->photos()->search([
84+
$testTitle = uniqid('PhpFlickr search test ');
85+
$searchParams = [
8786
'user_id' => 'me',
88-
'text' => 'Agateware_Example',
89-
]);
90-
static::assertGreaterThan(1, count($search['photo']));
87+
'text' => $testTitle,
88+
];
89+
90+
// Make sure there are no search results to start with.
91+
$search = $flickr->photos()->search($searchParams);
92+
static::assertCount(0, $search['photo']);
93+
94+
// Upload a test photo.
95+
$testFilename = dirname(__DIR__) . '/../examples/Agateware_Example.JPG';
96+
$photo = $flickr->uploader()->upload($testFilename, $testTitle, null, null, true, null, null, null, 1);
97+
98+
// Look for search results, looping because it's a new file and can take time to be indexed.
99+
for ($i = 0; $i < 15; $i++) {
100+
sleep(1);
101+
$search = $flickr->photos()->search($searchParams);
102+
if (count($search['photo']) > 0) {
103+
break;
104+
}
105+
}
106+
static::assertGreaterThanOrEqual(1, count($search['photo']));
91107

92108
// Clean up.
93109
$flickr->photos()->delete($photo['photoid']);

tests/ApiMethodGroup/TestApiTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ public function testEcho()
2727
{
2828
$flickr = $this->getFlickr();
2929

30-
$echo = $flickr->test()->testEcho(['foo' => 'bar']);
30+
try {
31+
$echo = $flickr->test()->testEcho(['foo' => 'bar']);
32+
} catch (FlickrException $e) {
33+
static::markTestSkipped($e->getMessage());
34+
}
3135

3236
$this->assertArrayHasKey('foo', $echo);
3337
}

tests/TestCase.php

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
use OAuth\OAuth1\Token\StdOAuth1Token;
66
use PHPUnit\Framework\TestCase as PhpUnitTestCase;
7+
use Samwilson\PhpFlickr\FlickrException;
78
use Samwilson\PhpFlickr\PhpFlickr;
89

910
abstract class TestCase extends PhpUnitTestCase
1011
{
11-
/** @var PhpFlickr */
12-
private $flickr;
12+
/** @var PhpFlickr[] */
13+
private $flickrs = [];
1314

1415
/**
1516
* Get an instance of PhpFlickr, configured by the config.php file in the tests directory.
@@ -19,8 +20,9 @@ abstract class TestCase extends PhpUnitTestCase
1920
*/
2021
public function getFlickr(bool $authenticate = false): PhpFlickr
2122
{
22-
if ($this->flickr instanceof PhpFlickr) {
23-
return $this->flickr;
23+
$authed = $authenticate ? 'authed' : 'notauthed';
24+
if (isset($this->flickrs[$authed])) {
25+
return $this->flickrs[$authed];
2426
}
2527

2628
// Get config values from env vars or the tests/config.php file.
@@ -35,16 +37,34 @@ public function getFlickr(bool $authenticate = false): PhpFlickr
3537
// Skip if no key found, so PRs from forks can still be run in CI.
3638
static::markTestSkipped('No Flickr API key set.');
3739
}
38-
$this->flickr = new PhpFlickr($apiKey, $apiSecret);
40+
try {
41+
$this->flickrs[$authed] = new PhpFlickr($apiKey, $apiSecret);
42+
} catch (FlickrException $ex) {
43+
static::markTestSkipped($ex->getMessage());
44+
}
3945

4046
// Authenticate?
4147
if ($authenticate && !empty($accessToken) && !empty($accessTokenSecret)) {
4248
$token = new StdOAuth1Token();
4349
$token->setAccessToken($accessToken);
4450
$token->setAccessTokenSecret($accessTokenSecret);
45-
$this->flickr->getOauthTokenStorage()->storeAccessToken('Flickr', $token);
51+
$this->flickrs[$authed]->getOauthTokenStorage()->storeAccessToken('Flickr', $token);
52+
try {
53+
$authenticated = $this->flickrs[$authed]->test()->login();
54+
} catch (FlickrException $e) {
55+
$authenticated = false;
56+
}
57+
if (!$authenticated) {
58+
static::markTestSkipped('Unable to authenticate with provided access token.');
59+
}
60+
}
61+
if ($authenticate && empty($accessToken)) {
62+
static::markTestSkipped(
63+
'Access token required for this test. '
64+
. 'Please use examples/get_auth_token.php to get token to add to tests/config.php.'
65+
);
4666
}
4767

48-
return $this->flickr;
68+
return $this->flickrs[$authed];
4969
}
5070
}

0 commit comments

Comments
 (0)