Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency upgrades #93

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
}
],
"require": {
"php": ">=7.3.0",
"guzzlehttp/guzzle": "~6.5.5",
"guzzlehttp/oauth-subscriber": "0.3.*"
"php": ">=8.1.0",
"guzzlehttp/guzzle": ">7.5",
"guzzlehttp/oauth-subscriber": "0.6.*"
},
"require-dev": {
"phpunit/phpunit": "~5.0",
"friendsofphp/php-cs-fixer": "~2.12",
"php-coveralls/php-coveralls": "^2.1"
"phpunit/phpunit": ">9.0",
"php-coveralls/php-coveralls": "^2.7",
"friendsofphp/php-cs-fixer": "^3.65"
},
"autoload": {
"psr-4": { "phpSmug\\": "lib/phpSmug/" }
Expand Down
2 changes: 1 addition & 1 deletion examples/example-external-links.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
// Step 2: Get the User to login to SmugMug and authorise this demo
echo '<p>Click <a href="'.$client->getAuthorizeURL().'"><strong>HERE</strong></a> to Authorize This Demo.</p>';

// Alternatively, automatically direct your visitor by commenting out the above line in favour of this:
// Alternatively, automatically direct your visitor by commenting out the above line in favour of this:
//header("Location:".$client->getAuthorizeURL());
} else {
$reqToken = unserialize($_SESSION['SmugGalReqToken']);
Expand Down
3 changes: 2 additions & 1 deletion examples/example-oauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@

// Step 2: Get the User to login to SmugMug and authorise this demo
echo '<p>Click <a href="'.$client->getAuthorizeURL().'"><strong>HERE</strong></a> to Authorize This Demo.</p>';
// Alternatively, automatically direct your visitor by commenting out the above line in favour of this:

// Alternatively, automatically direct your visitor by commenting out the above line in favour of this:
//header("Location:".$client->getAuthorizeURL());
} else {
$reqToken = unserialize($_SESSION['SmugGalReqToken']);
Expand Down
60 changes: 30 additions & 30 deletions lib/phpSmug/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Client
/**
* A few default variables.
*/
const VERSION = '4.0.0';
public const VERSION = '4.0.0';
public $AppName = 'Unknown Application';
public $APIKey;
public $OAuthSecret;
Expand Down Expand Up @@ -149,7 +149,7 @@ public function __call($method, $args)
$this->request_options['query'][$key] = $value;
}
}
break;
break;
case 'put':
case 'post':
case 'patch':
Expand All @@ -158,10 +158,10 @@ public function __call($method, $args)
if ($options) {
$this->request_options['json'] = $options;
}
break;
break;
default:
throw new BadMethodCallException('Invalid method: '.$method);
break;
break;
}

$this->performRequest(strtoupper($method), $url);
Expand Down Expand Up @@ -337,32 +337,32 @@ private function performRequest($method, $url)
private function processResponse($method = null)
{
switch ($method) {
case 'getRequestToken':
case 'getAccessToken':
parse_str($this->response->getBody(), $token);
$this->setToken($token['oauth_token'], $token['oauth_token_secret']);
// Remove the middleware so it is re-added with the updated credentials on subsequent requests.
$this->stack->remove('oauth_middleware');

return $token;
break;
case 'options':
$body = json_decode((string) $this->response->getBody());

return $body->Options;
break;
default:
$body = json_decode((string) $this->response->getBody());
if (isset($body->Response)) {
if (isset($body->Expansions)) {
$body->Response->Expansions = $body->Expansions;
}

return $body->Response;
} else {
return $body;
}
break;
case 'getRequestToken':
case 'getAccessToken':
parse_str($this->response->getBody(), $token);
$this->setToken($token['oauth_token'], $token['oauth_token_secret']);
// Remove the middleware so it is re-added with the updated credentials on subsequent requests.
$this->stack->remove('oauth_middleware');

return $token;
break;
case 'options':
$body = json_decode((string) $this->response->getBody());

return $body->Options;
break;
default:
$body = json_decode((string) $this->response->getBody());
if (isset($body->Response)) {
if (isset($body->Expansions)) {
$body->Response->Expansions = $body->Expansions;
}

return $body->Response;
} else {
return $body;
}
break;
}
}

Expand Down
46 changes: 19 additions & 27 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="test/bootstrap.php"
report-useless-tests="true"

>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
executionOrder="depends,defects"
shortenArraysForExportThreshold="10"
requireCoverageMetadata="false"
beStrictAboutCoverageMetadata="false"
beStrictAboutOutputDuringTests="true"
displayDetailsOnPhpunitDeprecations="true"
failOnPhpunitDeprecation="true"
failOnRisky="true"
failOnWarning="true">
<testsuites>
<testsuite name="phpSmug Test Suite">
<directory>./test/phpSmug/</directory>
<directory>test/phpSmug/</directory>
</testsuite>
</testsuites>

Expand All @@ -25,16 +24,9 @@
</exclude>
</groups>

<filter>
<whitelist>
<directory suffix=".php">./lib/phpSmug/</directory>
</whitelist>
</filter>

<logging>
<log type="coverage-html" target="./build/logs/report/"
charset="UTF-8" yui="true" highlight="true"
lowUpperBound="35" highLowerBound="70" showUncoveredFiles="true" />
<log type="coverage-clover" target="./build/logs/clover.xml"/>
</logging>
<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true">
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
83 changes: 45 additions & 38 deletions test/phpSmug/Tests/ClientSmugMugTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,26 @@

use phpSmug\Client;
use GuzzleHttp\Client as GuzzleClient;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\Depends;

class ClientSmugMugTest extends \PHPUnit_Framework_TestCase
class ClientSmugMugTest extends TestCase
{
public function setup()
protected const DEFAULT_NICKNAME = 'colinseymour';
protected const DEFAULT_FOLDER = 'Other';
protected const APP_NAME = 'phpSmug Unit Testing';

protected string $nickname;
protected string $folder;

public function setUp(): void
{
$this->nickname = getenv('NICKNAME') ?? self::DEFAULT_NICKNAME;
$this->folder = getenv('FOLDER') ?? self::DEFAULT_FOLDER;

$options = [
'AppName' => 'phpSmug Unit Testing',
'AppName' => self::APP_NAME,
'OAuthSecret' => getenv('OAUTH_SECRET'),
'_verbosity' => 1,
'_shorturis' => true,
Expand All @@ -36,39 +49,36 @@ public function checkEnvVars()
}

/**
* @test
*
* Test unauthenticated GET
*/
#[Test]
public function shouldGetPublicUserInfo()
{
$this->checkEnvVars();
$client = new \phpSmug\Client(getenv('APIKEY'), ['AppName' => 'phpSmug Unit Testing']);
$response = $client->get('user/colinseymour');
$client = new \phpSmug\Client(getenv('APIKEY'), ['AppName' => self::APP_NAME]);
$response = $client->get('user/' . $this->nickname);
$this->assertTrue(is_object($response));
$this->assertEquals('Public', $response->User->ResponseLevel);
$this->assertEquals('colinseymour', $response->User->NickName);
$this->assertEquals($this->nickname, $response->User->NickName);
}

/**
* @test
*
* Test authenticated GET
*/
#[Test]
public function shouldGetFullUserInfo()
{
$this->checkEnvVars();
$response = $this->client->get('!authuser');
$this->assertTrue(is_object($response));
$this->assertEquals('Full', $response->User->ResponseLevel);
$this->assertEquals('colinseymour', $response->User->NickName);
$this->assertEquals($this->nickname, $response->User->NickName);
}

/**
* @test
*
* Tests POST by creating a new album
*/
#[Test]
public function shouldCreateNewAlbum()
{
$this->checkEnvVars();
Expand All @@ -79,7 +89,7 @@ public function shouldCreateNewAlbum()
'Title' => 'New Album from unit testing phpSmug',
'Privacy' => 'Private',
];
$response = $this->client->post('folder/user/colinseymour/Other!albums', $options);
$response = $this->client->post('folder/user/' . $this->nickname . '/' . $this->folder . '/!albums', $options);
$this->assertTrue(is_object($response));
$this->assertEquals($options['NiceName'], $response->Album->NiceName);
$this->assertEquals($options['Title'], $response->Album->Title);
Expand All @@ -89,11 +99,10 @@ public function shouldCreateNewAlbum()
}

/**
* @test
* @depends shouldCreateNewAlbum
*
* Tests PATCH by modifying the previously created album.
*/
#[Test]
#[Depends('shouldCreateNewAlbum')]
public function shouldModifyNewlyCreatedAlbum($album_uri)
{
$this->checkEnvVars();
Expand All @@ -111,11 +120,10 @@ public function shouldModifyNewlyCreatedAlbum($album_uri)
}

/**
* @test
* @depends shouldModifyNewlyCreatedAlbum
*
* Tests upload()
*/
#[Test]
#[Depends('shouldModifyNewlyCreatedAlbum')]
public function shouldUploadPictureToNewlyCreatedAlbum($album_uri)
{
$this->checkEnvVars();
Expand All @@ -129,50 +137,50 @@ public function shouldUploadPictureToNewlyCreatedAlbum($album_uri)
];
$response = $this->client->upload($album_uri, 'examples/phpSmug-logo.png', $options);
$this->assertTrue(is_object($response));
$this->assertObjectHasAttribute('Image', $response);
$this->assertObjectHasProperty('Image', $response);

return $album_uri;
}

/**
* @test
* @depends shouldUploadPictureToNewlyCreatedAlbum
* @expectedException \GuzzleHttp\Exception\ClientException
* @expectedExceptionMessage 404 Not Found
*
* Tests that we really can't access the private image
*/
#[Test]
#[Depends('shouldUploadPictureToNewlyCreatedAlbum')]
public function shouldFailToGetPrivateImage($album_uri)
{
$this->checkEnvVars();
$thumbnail_url = $this->client->get($album_uri.'!images')->AlbumImage[0]->ThumbnailUrl;
$thumbnail_url = $this->client->get($album_uri . '!images')->AlbumImage[0]->ThumbnailUrl;

$client = new GuzzleClient();

$this->expectException(\GuzzleHttp\Exception\ClientException::class);
$this->expectExceptionMessage('404 Not Found');
$client->get($thumbnail_url);
}

/**
* @test
* @depends shouldUploadPictureToNewlyCreatedAlbum
*
* Tests signResource()
*/
#[Test]
#[Depends('shouldUploadPictureToNewlyCreatedAlbum')]
public function shouldGetPrivateImageWithSignedUrl($album_uri)
{
$this->checkEnvVars();
$thumbnail_url = $this->client->get($album_uri.'!images')->AlbumImage[0]->ThumbnailUrl;
$signed_thumbnail_url = $this->client->signResource($thumbnail_url);

$client = new GuzzleClient();
$client->get($signed_thumbnail_url);

return $album_uri;
}

/**
* @test
* @depends shouldGetPrivateImageWithSignedUrl
*
* Tests DELETE
*/
#[Test]
#[Depends('shouldGetPrivateImageWithSignedUrl')]
public function shouldDeleteNewlyCreatedAlbumWithUploadedPicture($album_uri)
{
$this->checkEnvVars();
Expand All @@ -183,16 +191,15 @@ public function shouldDeleteNewlyCreatedAlbumWithUploadedPicture($album_uri)
}

/**
* @test
*
* Tests OPTIONS
*/
#[Test]
public function shouldGetInfoAboutMethod()
{
$this->checkEnvVars();
$options = $this->client->options('user/colinseymour');
$this->assertObjectHasAttribute('Output', $options);
$options = $this->client->options('user/' . $this->nickname);
$this->assertObjectHasProperty('Output', $options);
$this->assertTrue(is_array($options->Output));
$this->assertObjectNotHasAttribute('Response', $options);
$this->assertObjectNotHasProperty('Response', $options);
}
}
Loading