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

PHP 8.0, 8.1, PHPUnit 9 support + automated check for php compatibility #2403

Merged
merged 34 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
64aac67
PHP 8.0, 8.1, PHPUnit 9 support
27pchrisl Oct 11, 2021
5963c8c
Replace key-fixture in CloudFront-tests with generated keys
Zombaya May 17, 2022
73595b3
Additional changes to unittest for phpunit9-compatibility
Zombaya Mar 16, 2022
69e7187
Fix problems with non-fully-reset environment-variables after test
Zombaya Mar 18, 2022
22c3c77
Add changelog document
Zombaya Mar 18, 2022
3fa4d92
Small rewrites of unittests because of deprecation-warnings in phpuni…
Zombaya May 11, 2022
82715b9
Remove warnings from usage of arguments of wrong type in php 8.1
Zombaya May 11, 2022
bebfcc7
Solve failing unittest CloudFront\SignerTest::testBadPrivateKeyPath()
Zombaya Jun 7, 2022
eccd896
switch to double pipe
stobrien89 Jun 9, 2022
863a65a
Formatting fixes
Zombaya Jun 13, 2022
bce4721
Additional methods added to PHPUnitCompatibilitityTraits
Zombaya Jun 27, 2022
8f4b64e
PHP 8.0, 8.1, PHPUnit 9 support
27pchrisl Oct 11, 2021
1c4109d
Replace key-fixture in CloudFront-tests with generated keys
Zombaya May 17, 2022
7dd0db1
Additional changes to unittest for phpunit9-compatibility
Zombaya Mar 16, 2022
a129990
Fix problems with non-fully-reset environment-variables after test
Zombaya Mar 18, 2022
22374fc
Add changelog document
Zombaya Mar 18, 2022
991312f
Small rewrites of unittests because of deprecation-warnings in phpuni…
Zombaya May 11, 2022
a57b51f
Remove warnings from usage of arguments of wrong type in php 8.1
Zombaya May 11, 2022
f07ec26
Solve failing unittest CloudFront\SignerTest::testBadPrivateKeyPath()
Zombaya Jun 7, 2022
d6474a8
switch to double pipe
stobrien89 Jun 9, 2022
c2def67
Formatting fixes
Zombaya Jun 13, 2022
c6f3be2
Additional methods added to PHPUnitCompatibilitityTraits
Zombaya Jun 27, 2022
71f3ec5
fix conflicts/warnings
Jul 19, 2022
b7b6f7e
update tests
Jul 21, 2022
f49a0ef
refactor jsonbody getcontenttype
Jul 21, 2022
ceb60cc
add compattrait to endpointparametermiddlewaretest
Aug 4, 2022
7ce24b4
add compattrait to endpointparametermiddlewaretest
Aug 4, 2022
6d1e8aa
add update to instanceprofileprovider
Aug 4, 2022
e98701e
Merge branch 'master' into phpcompatibilityChecker
stobrien89 Aug 4, 2022
9634dfa
Replace PHPUnitCompatTrait with packages yoast/phpunit-polyfills and …
Zombaya Aug 11, 2022
661ac2f
Replace $this->expectNotToPerformAssertions() with $this->addToAssert…
Zombaya Aug 11, 2022
4c34478
Merge remote-tracking branch 'upstream/master' into phpcompatibilityC…
Zombaya Sep 2, 2022
e67a48e
fix spacing
stobrien89 Sep 12, 2022
06e01bf
Fix spacing
stobrien89 Sep 12, 2022
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
7 changes: 7 additions & 0 deletions .changes/nextrelease/php8
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"type": "enhancement",
"category": "",
"description": "Add support for php 8.0 and 8.1"
}
]
26 changes: 15 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
#for each of the following versions of PHP, with and without --prefer-lowest
matrix:
php-versions: ['5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4']
php-versions: ['5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
composer-options: ['', '--prefer-lowest']
#set the name for each job
name: PHP ${{ matrix.php-versions }} ${{ matrix.composer-options }}
Expand All @@ -42,28 +42,32 @@ jobs:
- name: Validate composer.json and composer.lock
run: composer validate

#downgrade to supported php unit and remove incompatible xdebug file if it exists
#remove incompatible xdebug file if it exists
- if: ${{ matrix.php-versions == '5.5' }}
name: PHP 5.5 specific setup
name: PHP 5.5
run: |
sudo rm -f /etc/php5/cli/conf.d/20-xdebug.ini
composer require --dev --ignore-platform-reqs phpunit/phpunit "4.8.36"

#downgrade to supported php unit
- if: ${{ matrix.php-versions <= '7.1' && matrix.php-versions > 5.5}}
name: PHP 5.6-7.1 specific setup
run: composer require --dev --ignore-platform-reqs phpunit/phpunit "^5.7.11"

#get dependencies
- name: Install dependencies
run: composer update ${{ matrix.composer-options }} --no-interaction --prefer-source

#php 8.x requirements
- if: ${{ matrix.php-versions >= '8.0' && matrix.composer-options != '' }}
name: PHP 8.x
run: composer require --dev phpunit/phpunit "^9.5" --no-interaction --prefer-source --with-all-dependencies

#php 8.1 requirements
- if: ${{ matrix.php-versions >= '8.1' && matrix.composer-options != '' }}
name: PHP 8.1
run: composer require --dev guzzlehttp/guzzle "^7.3" --no-interaction --prefer-source --with-all-dependencies

#run tests
- name: Run test suite
run: make test

#static analysis
- if: ${{ matrix.php-versions >= '7.1' && matrix.php-versions <= 7.4 && matrix.composer-options == '' }}
- if: ${{ matrix.php-versions >= '7.1' && matrix.php-versions < '8.0' && matrix.composer-options == '' }}
name: Static analysis
run: |
composer require --dev nette/neon "^3.0"
Expand All @@ -79,6 +83,6 @@ jobs:
make package

#generate code coverage
- if: ${{ matrix.php-versions == '7.1' && matrix.composer-options == '' }}
- if: ${{ (matrix.php-versions == '7.1' || matrix.php-versions == '8.0') && matrix.composer-options == '' }}
stobrien89 marked this conversation as resolved.
Show resolved Hide resolved
name: Code coverage
run: bash <(curl -s https://codecov.io/bash)
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ test_services.json
/Makefile
.idea
.php_cs.cache
.phpunit.result.cache
atlassian-ide-plugin.xml
aws-sdk-php.iml
.DS_Store
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"ext-dom": "*",
"ext-pcntl": "*",
"ext-sockets": "*",
"phpunit/phpunit": "^4.8.35 || ^5.6.3",
"phpunit/phpunit": "^4.8.35 || ^5.6.3 || ^9.5",
"behat/behat": "~3.0",
"doctrine/cache": "~1.4",
"aws/aws-php-sns-message-validator": "~1.0",
Expand All @@ -41,7 +41,9 @@
"psr/cache": "^1.0",
"psr/simple-cache": "^1.0",
"paragonie/random_compat": ">= 2",
"sebastian/comparator": "^1.2.3"
"sebastian/comparator": "^1.2.3 || ^4.0",
"yoast/phpunit-polyfills": "^1.0",
"dms/phpunit-arraysubset-asserts": "^0.4.0"
},
"suggest": {
"ext-openssl": "Allows working with CloudFront private distributions and verifying received SNS messages",
Expand Down
53 changes: 22 additions & 31 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./tests/bootstrap.php"
colors="true">

<php>
<!-- Specify the path to your CloudFront private key -->
<server name="CF_PRIVATE_KEY" value="changeme" />
<!-- Specify the CloudFront key pair ID to use when testing -->
<server name="CF_KEY_PAIR_ID" value="change_me" />
</php>

<testsuites>
<testsuite name="unit">
<directory suffix="Test.php">tests/</directory>
<exclude>tests/Integ</exclude>
</testsuite>
<testsuite name="integ">
<directory suffix="Test.php">tests/Integ</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory suffix=".php">src</directory>
<exclude>
<directory>src/data</directory>
</exclude>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="clover.xml"/>
</logging>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<directory>src/data</directory>
</exclude>
<report>
<clover outputFile="clover.xml"/>
</report>
</coverage>
<testsuites>
<testsuite name="unit">
<directory suffix="Test.php">tests/</directory>
<exclude>tests/Integ</exclude>
</testsuite>
<testsuite name="integ">
<directory suffix="Test.php">tests/Integ</directory>
</testsuite>
</testsuites>
<logging/>
</phpunit>
2 changes: 1 addition & 1 deletion src/Api/Parser/AbstractRestParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private function extractHeaders(
// Check if the headers are prefixed by a location name
$result[$name] = [];
$prefix = $shape['locationName'];
$prefixLen = strlen($prefix);
$prefixLen = $prefix !== null ? strlen($prefix) : 0;

foreach ($response->getHeaders() as $k => $values) {
if (!$prefixLen) {
Expand Down
13 changes: 11 additions & 2 deletions src/Api/Serializer/JsonBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,17 @@ public function __construct(Service $api)
*/
public static function getContentType(Service $service)
{
return 'application/x-amz-json-'
. number_format($service->getMetadata('jsonVersion'), 1);
if ($service->getMetadata('protocol') === 'rest-json') {
return 'application/json';
}

$jsonVersion = $service->getMetadata('jsonVersion');
if (empty($jsonVersion)) {
throw new \InvalidArgumentException('invalid json');
} else {
return 'application/x-amz-json-'
. @number_format($service->getMetadata('jsonVersion'), 1);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Serializer/RestJsonSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(
JsonBody $jsonFormatter = null
) {
parent::__construct($api, $endpoint);
$this->contentType = 'application/json';
$this->contentType = JsonBody::getContentType($api);
$this->jsonFormatter = $jsonFormatter ?: new JsonBody($api);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Arn/ArnParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ArnParser
*/
public static function isArn($string)
{
return strpos($string, 'arn:') === 0;
return $string !== null && strpos($string, 'arn:') === 0;
}

/**
Expand Down
12 changes: 8 additions & 4 deletions src/CloudFront/Signer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ public function __construct($keyPairId, $privateKey, $passphrase = "")
if (!$this->pkHandle = openssl_pkey_get_private($privateKey, $passphrase)) {
if (!file_exists($privateKey)) {
throw new \InvalidArgumentException("PK file not found: $privateKey");
} else {
$this->pkHandle = openssl_pkey_get_private("file://$privateKey", $passphrase);
if (!$this->pkHandle) {
throw new \InvalidArgumentException(openssl_error_string());
}

$this->pkHandle = openssl_pkey_get_private("file://$privateKey", $passphrase);
if (!$this->pkHandle) {
$errorMessages = [];
while(($newMessage = openssl_error_string()) !== false){
$errorMessages[] = $newMessage;
}
throw new \InvalidArgumentException(implode("\n",$errorMessages));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/MockHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(
$this->onRejected = $onRejected;

if ($resultOrQueue) {
call_user_func_array([$this, 'append'], $resultOrQueue);
call_user_func_array([$this, 'append'], array_values($resultOrQueue));
stobrien89 marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/S3/S3Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,9 @@ public function __construct(array $args)
*/
public static function isBucketDnsCompatible($bucket)
SamRemis marked this conversation as resolved.
Show resolved Hide resolved
{
if (!is_string($bucket)) {
return false;
}
$bucketLen = strlen($bucket);

return ($bucketLen >= 3 && $bucketLen <= 63) &&
Expand Down
6 changes: 2 additions & 4 deletions tests/AbstractConfigurationProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Aws\Result;
use Aws\ResultInterface;
use GuzzleHttp\Promise;
use PHPUnit\Framework\TestCase;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;

/**
* @covers \Aws\AbstractConfigurationProvider
Expand Down Expand Up @@ -65,11 +65,9 @@ public function testChainsConfiguration()
$this->assertSame($expected, $result);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testChainThrowsExceptionOnEmptyArgs()
{
$this->expectException(\InvalidArgumentException::class);
call_user_func([$this->provider, 'chain']);
}

Expand Down
18 changes: 8 additions & 10 deletions tests/Api/ApiProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use Aws\Api\ApiProvider;
use Aws\Exception\UnresolvedApiException;
use PHPUnit\Framework\TestCase;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;

/**
* @covers Aws\Api\ApiProvider
Expand All @@ -30,7 +30,7 @@ public function testCanResolveProvider()
$this->assertEquals($result, ApiProvider::resolve($p, 't', 's', 'v'));

$p = function ($a, $b, $c) {return null;};
$this->setExpectedException(UnresolvedApiException::class);
$this->expectException(UnresolvedApiException::class);
ApiProvider::resolve($p, 't', 's', 'v');
}

Expand All @@ -53,7 +53,7 @@ public function testCanGetServiceVersions()
public function testCanGetDefaultProvider()
{
$p = ApiProvider::defaultProvider();
$this->assertArrayHasKey('s3', $this->readAttribute($p, 'manifest'));
$this->assertArrayHasKey('s3', $this->getPropertyValue($p, 'manifest'));
}

public function testManifestProviderReturnsNullForMissingService()
Expand All @@ -66,15 +66,13 @@ public function testManifestProviderCanLoadData()
{
$p = $this->getTestApiProvider();
$data = $p('api', 'dynamodb', 'latest');
$this->assertInternalType('array', $data);
$this->assertIsArray($data);
$this->assertArrayHasKey('foo', $data);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testFilesystemProviderEnsuresDirectoryIsValid()
{
$this->expectException(\InvalidArgumentException::class);
ApiProvider::filesystem('/path/to/invalid/dir');
}

Expand Down Expand Up @@ -116,21 +114,21 @@ public function testReturnsWaiterConfigsForLatestCompatibleVersion()

public function testThrowsOnBadType()
{
$this->setExpectedException(UnresolvedApiException::class);
$this->expectException(UnresolvedApiException::class);
$p = $this->getTestApiProvider();
ApiProvider::resolve($p, 'foo', 's3', 'latest');
}

public function testThrowsOnBadService()
{
$this->setExpectedException(UnresolvedApiException::class);
$this->expectException(UnresolvedApiException::class);
$p = $this->getTestApiProvider();
ApiProvider::resolve($p, 'api', '', 'latest');
}

public function testThrowsOnBadVersion()
{
$this->setExpectedException(UnresolvedApiException::class);
$this->expectException(UnresolvedApiException::class);
$p = $this->getTestApiProvider();
ApiProvider::resolve($p, 'api', 'dynamodb', 'derp');
}
Expand Down
4 changes: 3 additions & 1 deletion tests/Api/ErrorParser/XmlErrorParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@

use Aws\Api\ErrorParser\XmlErrorParser;
use Aws\Test\TestServiceTrait;
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use GuzzleHttp\Psr7;
use PHPUnit\Framework\TestCase;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;

/**
* @covers Aws\Api\ErrorParser\XmlErrorParser
*/
class XmlErrorParserTest extends TestCase
{
use ArraySubsetAsserts;
use TestServiceTrait;

/**
Expand Down
6 changes: 2 additions & 4 deletions tests/Api/ListShapeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use Aws\Api\ShapeMap;
use Aws\Api\ListShape;
use PHPUnit\Framework\TestCase;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;

/**
* @covers \Aws\Api\ListShape
Expand All @@ -23,11 +23,9 @@ public function testReturnsMember()
$this->assertSame('string', $m->getType());
}

/**
* @expectedException \RuntimeException
*/
public function testFailsWhenMemberIsMissing()
{
$this->expectException(\RuntimeException::class);
(new ListShape([], new ShapeMap([])))->getMember();
}
}
6 changes: 2 additions & 4 deletions tests/Api/MapShapeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use Aws\Api\ShapeMap;
use Aws\Api\MapShape;
use PHPUnit\Framework\TestCase;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;

/**
* @covers \Aws\Api\MapShape
Expand All @@ -19,11 +19,9 @@ public function testReturnsValue()
$this->assertSame($v, $s->getValue());
}

/**
* @expectedException \RuntimeException
*/
public function testFailsWhenValueIsMissing()
{
$this->expectException(\RuntimeException::class);
(new MapShape([], new ShapeMap([])))->getValue();
}

Expand Down
Loading