Skip to content
This repository has been archived by the owner on Jan 9, 2025. It is now read-only.

[TDO-788] Update sws-php-sdk to be compatible with PHP8.2 #84

Merged
merged 3 commits into from
Jul 17, 2024
Merged
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
36 changes: 36 additions & 0 deletions .docker/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Install git an zip/unzip (required by composer)
apt update && apt install -y git zip unzip libgmp-dev

# Configure and install PHP GMP extension (this is not included in the base container images)
docker-php-ext-configure gmp
docker-php-ext-install gmp

# Download and install Composer
# I _could_ mount a volume and install it there. But it only takes
# a few seconds so do it everytime the container is run.
curl -o /home/composer-setup.php https://getcomposer.org/installer
EXPECTED_SIGNATURE="$(curl https://composer.github.io/installer.sig)"
ACTUAL_SIGNATURE="$(php -r "echo hash_file('sha384', '/home/composer-setup.php');")"
if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]
then
>&2 echo 'ERROR: Invalid installer signature'
rm composer-setup.php
exit 1
fi
cd /home
php /home/composer-setup.php --filename=composer
php -r "rename('/home/composer', '/usr/local/bin/composer');"
php -r "unlink('/home/composer-setup.php');"

# Install project dependencies using Composer
cd /srv/php-lib
composer install
ls -alh

# Output a PHP version details + other info
echo "\n"
php -v
echo "\n"

# Start a bash shell
bash
6 changes: 4 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# This workflow is triggered every time a PR is opened and master/release branches have a commit.
# The workflow installs dependencies, runs static code analyzers, and runs the test suite.
# todo: Enable Phpstan when all apps are updated to 8.2 and we no more support PHP 7.1.
# Currently it is impossible to fix Phpstan errors reported on PHP8.2 platform because of deprecations etc.
# ./vendor/bin/phpstan analyse -c phpstan.neon
name: Code checking and unit tests
on:
pull_request:
Expand All @@ -17,7 +20,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.1','7.2']
php-versions: ['7.1','8.2']
steps:
- uses: actions/checkout@v3
- name: Setup PHP
Expand All @@ -41,7 +44,6 @@ jobs:

- name: Run static code analyzers & security checker
run: |
./vendor/bin/phpstan analyse -c phpstan.neon
./vendor/bin/phpcs
- name: Run test suite
run: |
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
/.idea/*
composer.lock
/docs
/tests/reports
/tests/reports
.phpunit.result.cache
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
"description": "PHP SDK for Serato Web Services",
"type": "library",
"require": {
"php": "^7.1",
"php": "^7.1 || ^8.0",
"guzzlehttp/guzzle": "^6.0.0",
"serato/sws-discovery": "^2.0.0"
"serato/sws-discovery": "dev-TDO-789"
},
"require-dev": {
"phpunit/phpunit": "~7.0",
"squizlabs/php_codesniffer": "~3.6",
"aws/aws-sdk-php": "~3.0",
"phpstan/phpstan": "^0.12.0",
"phpstan/phpstan-phpunit": "^0.12.0",
"enlightn/security-checker": "^1.4"
"phpunit/phpunit": "^7 || ^8",
"squizlabs/php_codesniffer": "^3.0",
"aws/aws-sdk-php": "^3.0",
"phpstan/phpstan": "^1.4",
"phpstan/phpstan-phpunit": "^1.0",
"enlightn/security-checker": "^1.4 || ^2"
},
"autoload": {
"psr-4": {
Expand Down
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "3.8"

services:
php-build:
image: "php:${PHP_VERSION:-7.1}-cli"
command: ["sh", "/srv/php-lib/.docker/setup.sh"]
stdin_open: true
volumes:
- ./:/srv/php-lib
- ${HOME}/.aws/credentials:/root/.aws/credentials
55 changes: 18 additions & 37 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
namespace Serato\SwsSdk\Test;

use Serato\SwsSdk\Command;
use Serato\SwsSdk\Test\AbstractTestCase;
use Serato\SwsSdk\Exception\AccessDeniedException;
use Serato\SwsSdk\Exception\BadRequestException;
use Serato\SwsSdk\Exception\ResourceNotFoundException;
use Serato\SwsSdk\Exception\ServerApplicationErrorException;
use Serato\SwsSdk\Exception\ServiceUnavailableException;
use Serato\SwsSdk\Client;
use Serato\SwsSdk\Sdk;
use Serato\SwsSdk\Result;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Exception\ConnectException;
use InvalidArgumentException;

class ClientTest extends AbstractTestCase
{
Expand All @@ -37,11 +39,9 @@ public function testGetValidBearerTokenAuthCommand(): void
$this->assertTrue(is_a($command, self::BEARER_TOKEN_AUTH_COMMAND_CLASS));
}

/**
* @expectedException \InvalidArgumentException
*/
public function testGetInvalidCommand(): void
{
$this->expectException(\InvalidArgumentException::class);
$clientMock = $this->getMockClient([$this->getMock200Response()]);
$clientMock->getCommand('NoSuchCommand', $this->getCommandArgs());
}
Expand Down Expand Up @@ -74,11 +74,9 @@ public function testExecuteValidBearerTokenAuthCommand(): void
);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testExecuteInvalidCommand(): void
{
$this->expectException(\InvalidArgumentException::class);
$clientMock = $this->getMockClient([$this->getMock200Response()]);
$clientMock->execute('NoSuchCommand', $this->getCommandArgs());
}
Expand All @@ -98,11 +96,9 @@ public function testExecuteAsyncValidCommand(): void
);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testExecuteAsyncInvalidCommand(): void
{
$this->expectException(\InvalidArgumentException::class);
$clientMock = $this->getMockClient([$this->getMock200Response()]);
$clientMock->executeAsync('NoSuchCommand', $this->getCommandArgs());
}
Expand Down Expand Up @@ -135,11 +131,9 @@ public function testExecuteMagicMethodValidBearerTokenAuthCommand(): void
);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testExecuteMagicMethodInvalidCommand(): void
{
$this->expectException(\InvalidArgumentException::class);
$clientMock = $this->getMockClient([$this->getMock200Response()]);
$clientMock->noSuchMethod($this->getCommandArgs());
}
Expand All @@ -159,20 +153,16 @@ public function testExecuteAsyncMagicMethodValidCommand(): void
);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testExecuteAsyncMagicMethodInvalidCommand(): void
{
$this->expectException(\InvalidArgumentException::class);
$clientMock = $this->getMockClient([$this->getMock200Response()]);
$clientMock->noSuchMethodAsync($this->getCommandArgs());
}

/**
* @expectedException \Serato\SwsSdk\Exception\BadRequestException
*/
public function test400ClientError(): void
{
$this->expectException(BadRequestException::class);
$response = new Response(
400,
['Content-Type' => 'application/json'],
Expand All @@ -182,11 +172,9 @@ public function test400ClientError(): void
$clientMock->getProduct($this->getCommandArgs());
}

/**
* @expectedException \Serato\SwsSdk\Exception\AccessDeniedException
*/
public function test403Response(): void
{
$this->expectException(AccessDeniedException::class);
$response = new Response(
403,
['Content-Type' => 'application/json'],
Expand All @@ -197,11 +185,9 @@ public function test403Response(): void
$clientMock->getProduct($this->getCommandArgs());
}

/**
* @expectedException \Serato\SwsSdk\Exception\ResourceNotFoundException
*/
public function test404Response(): void
{
$this->expectException(ResourceNotFoundException::class);
$response = new Response(
404,
['Content-Type' => 'application/json'],
Expand All @@ -212,11 +198,9 @@ public function test404Response(): void
$clientMock->getProduct($this->getCommandArgs());
}

/**
* @expectedException \Serato\SwsSdk\Exception\ServerApplicationErrorException
*/
public function test500Response(): void
{
$this->expectException(ServerApplicationErrorException::class);
$response = new Response(
500,
['Content-Type' => 'application/json'],
Expand All @@ -227,11 +211,9 @@ public function test500Response(): void
$clientMock->getProduct($this->getCommandArgs());
}

/**
* @expectedException \Serato\SwsSdk\Exception\ServiceUnavailableException
*/
public function test503Response(): void
{
$this->expectException(ServiceUnavailableException::class);
$response = new Response(
503,
['Content-Type' => 'application/json'],
Expand All @@ -242,11 +224,9 @@ public function test503Response(): void
$clientMock->getProduct($this->getCommandArgs());
}

/**
* @expectedException GuzzleHttp\Exception\ConnectException
*/
public function testRequestTimeout(): void
{
$this->expectException(ConnectException::class);
$exception = new ConnectException(
"Error Communicating with Server",
new Request('GET', 'test')
Expand Down Expand Up @@ -294,7 +274,7 @@ protected function getCommandArgs(): array
/**
* Undocumented function
*
* @param array<mixed> $mockResponses
* @param array<mixed, mixed> $mockResponses
* @return mixed
*/
protected function getMockClient(array $mockResponses)
Expand All @@ -304,6 +284,7 @@ protected function getMockClient(array $mockResponses)
Sdk::BASE_URI_ID => 'https://id.server.com',
Sdk::BASE_URI_LICENSE => 'https://license.server.com',
],
'timeout' => 10,
'handler' => HandlerStack::create(
new MockHandler($mockResponses)
)
Expand Down
3 changes: 2 additions & 1 deletion tests/Ecom/Command/InvoiceCreateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ public function missingRequiredArgProvider(): array
* @param array<string, DateTime|int|string> $args
*
* @dataProvider missingRequiredArgProvider
* @expectedException \InvalidArgumentException
*
*/
public function testMissingRequiredArg(array $args): void
{
$this->expectException(\InvalidArgumentException::class);
$command = new InvoiceCreate(
'app_id',
'app_password',
Expand Down
3 changes: 2 additions & 1 deletion tests/Ecom/Command/SubscriptionCancelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ public function missingRequiredArgProvider(): array
* @param array<string, DateTime|int|string> $args
*
* @dataProvider missingRequiredArgProvider
* @expectedException \InvalidArgumentException
*
*/
public function testMissingRequiredArg(array $args): void
{
$this->expectException(\InvalidArgumentException::class);
$command = new SubscriptionCancel(
'app_id',
'app_password',
Expand Down
3 changes: 2 additions & 1 deletion tests/Ecom/Command/UpdateCartBillingAddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ public function missingRequiredArgProvider(): array
* @return void
*
* @dataProvider missingRequiredArgProvider
* @expectedException \InvalidArgumentException
*
*/
public function testMissingRequiredArg(array $args): void
{
$this->expectException(\InvalidArgumentException::class);
$command = new UpdateCartBillingAddress(
'app_id',
'app_password',
Expand Down
6 changes: 2 additions & 4 deletions tests/Ecom/Command/VoucherAssignTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@ public function missingRequiredArgProvider(): array
];
}

/**
/**
* Tests that an exception is thrown if required parameters are missing.
*
* @param array<string, DateTime|int|string> $args
*
* @dataProvider missingRequiredArgProvider
* @expectedException \InvalidArgumentException
*/
public function testMissingRequiredArg(array $args): void
{
$this->expectException(\InvalidArgumentException::class);
$command = new VoucherAssign(
'app_id',
'app_password',
Expand Down
5 changes: 3 additions & 2 deletions tests/Ecom/Command/VoucherCreateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ public function missingRequiredArgProvider(): array
* @param array<string, DateTime|int|string> $args
*
* @dataProvider missingRequiredArgProvider
* @expectedException \InvalidArgumentException
*/
*
*/
public function testMissingRequiredArg(array $args): void
{
$this->expectException(\InvalidArgumentException::class);
$command = new VoucherCreate(
'app_id',
'app_password',
Expand Down
3 changes: 2 additions & 1 deletion tests/Identity/Command/TokenExchangeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ class TokenExchangeTest extends AbstractTestCase
*
* @dataProvider missingRequiredArgProvider
*
* @expectedException \InvalidArgumentException
*
*/
public function testMissingRequiredArg(array $args): void
{
$this->expectException(\InvalidArgumentException::class);
$command = new TokenExchange(
'app_id',
'app_password',
Expand Down
3 changes: 2 additions & 1 deletion tests/Identity/Command/UserAddGaClientIdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ class UserAddGaClientIdTest extends AbstractTestCase
*
* @dataProvider missingRequiredArgProvider
*
* @expectedException \InvalidArgumentException
*
*/
public function testMissingRequiredArg(array $args): void
{
$this->expectException(\InvalidArgumentException::class);
$command = new UserAddGaClientId(
'app_id',
'app_password',
Expand Down
3 changes: 2 additions & 1 deletion tests/Identity/Command/UserGroupAddTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ class UserGroupAddTest extends AbstractTestCase
*
* @dataProvider missingRequiredArgProvider
*
* @expectedException \InvalidArgumentException
*
*/
public function testMissingRequiredArg(array $args): void
{
$this->expectException(\InvalidArgumentException::class);
$command = new UserGroupAdd(
'app_id',
'app_password',
Expand Down
Loading
Loading