Skip to content

Commit

Permalink
Additional changes to unittest for phpunit9-compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Zombaya committed May 11, 2022
1 parent 467d9d2 commit ea3df80
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 98 deletions.
7 changes: 3 additions & 4 deletions tests/Api/ServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ public function serializerDataProvider()

/**
* @dataProvider serializerDataProvider
* @doesNotPerformAssertions
*/
public function testCreatesSerializer($type, $cl)
{
Expand All @@ -203,7 +202,6 @@ public function parserDataProvider()

/**
* @dataProvider parserDataProvider
* @doesNotPerformAssertions
*/
public function testCreatesParsers($type, $cl)
{
Expand All @@ -215,8 +213,9 @@ function () { return []; }
$this->assertInstanceOf($cl, $parser);

if ($parser instanceof QueryParser) {
$this->assertAttributeInstanceOf(
'Aws\Api\Parser\XmlParser', 'parser', $parser
$this->assertInstanceOf(
'Aws\Api\Parser\XmlParser',
$this->readAttribute($parser, 'parser')
);
}
}
Expand Down
6 changes: 2 additions & 4 deletions tests/ClientResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -612,12 +612,10 @@ public function testDualstackEndpointInIsoPartition()
);
}

/**
* @expectedException \Aws\Endpoint\UseDualstackEndpoint\Exception\ConfigurationException
* @expectedExceptionMessage Dual-stack is not supported in ISO regions
*/
public function testDualstackEndpointFailureOnDualstackNotSupported()
{
$this->expectException(\Aws\Endpoint\UseDualstackEndpoint\Exception\ConfigurationException::class);
$this->expectExceptionMessage("Dual-stack is not supported in ISO regions");
$data = json_decode(
file_get_contents(__DIR__ . '/Endpoint/fixtures/dualstack_endpoints.json'),
true
Expand Down
8 changes: 4 additions & 4 deletions tests/Credentials/InstanceProfileProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ public function testExtendsExpirationAndSendsRequestIfImdsYieldsExpiredCreds($cl
$creds = $provider()->wait();

$message = stream_get_contents($capture);
$this->assertRegExp('/Attempting credential expiration extension/', $message);
$this->assertMatchesRegularExpression('/Attempting credential expiration extension/', $message);
$this->assertSame('foo', $creds->getAccessKeyId());
$this->assertSame('baz', $creds->getSecretKey());
$this->assertFalse($creds->isExpired());
Expand All @@ -1008,7 +1008,7 @@ public function testExtendsExpirationAndSendsRequestIfImdsYieldsExpiredCreds($cl
$result = $s3Client->listBuckets();

$this->assertEquals('Request sent', $result['message']);
$this->assertAttributeLessThanOrEqual(3, 'attempts', $provider);
$this->assertLessThanOrEqual(3,$this->readAttribute($provider,'attempts'));
}

public function returnsExpiredCredsProvider()
Expand Down Expand Up @@ -1072,7 +1072,7 @@ public function testExtendsExpirationAndSendsRequestIfImdsUnavailable($client)
$creds = $provider($expiredCreds)->wait();

$message = stream_get_contents($capture);
$this->assertRegExp('/Attempting credential expiration extension/', $message);
$this->assertMatchesRegularExpression('/Attempting credential expiration extension/', $message);
$this->assertSame('foo', $creds->getAccessKeyId());
$this->assertSame('baz', $creds->getSecretKey());
$this->assertFalse($expiredCreds->isExpired());
Expand All @@ -1094,7 +1094,7 @@ public function testExtendsExpirationAndSendsRequestIfImdsUnavailable($client)
$result = $s3Client->listBuckets();

$this->assertEquals('Request sent', $result['message']);
$this->assertAttributeLessThanOrEqual(3, 'attempts', $provider);
$this->assertLessThanOrEqual(3,$this->readAttribute($provider,'attempts'));
}

public function imdsUnavailableProvider()
Expand Down
37 changes: 14 additions & 23 deletions tests/DefaultsMode/ConfigurationProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Aws\DefaultsMode\ConfigurationInterface;
use Aws\DefaultsMode\ConfigurationProvider;
use Aws\DefaultsMode\Exception\ConfigurationException;
use Aws\Test\Polyfill\PHPUnit\PHPUnitCompatTrait;
use GuzzleHttp\Promise;
use PHPUnit\Framework\TestCase;

Expand All @@ -14,6 +15,8 @@
*/
class ConfigurationProviderTest extends TestCase
{
use PHPUnitCompatTrait;

private static $originalEnv;

private $iniFile = <<<EOT
Expand All @@ -30,7 +33,7 @@ class ConfigurationProviderTest extends TestCase
defaults_mode = cross-region
EOT;

public static function setUpBeforeClass()
public static function _setUpBeforeClass()
{
self::$originalEnv = [
'mode' => getenv(ConfigurationProvider::ENV_MODE) ?: '',
Expand All @@ -53,7 +56,7 @@ private function clearEnv()
return $dir;
}

public static function tearDownAfterClass()
public static function _tearDownAfterClass()
{
putenv(ConfigurationProvider::ENV_MODE . '=' .
self::$originalEnv['mode']);
Expand Down Expand Up @@ -167,21 +170,17 @@ public function testCreatesFromIniFileWithSpecifiedProfile()
unlink($dir . '/config');
}

/**
* @expectedException \Aws\DefaultsMode\Exception\ConfigurationException
*/
public function testEnsuresIniFileExists()
{
$this->expectException(\Aws\DefaultsMode\Exception\ConfigurationException::class);
$this->clearEnv();
putenv('HOME=/does/not/exist');
call_user_func(ConfigurationProvider::ini())->wait();
}

/**
* @expectedException \Aws\DefaultsMode\Exception\ConfigurationException
*/
public function testEnsuresProfileIsNotEmpty()
{
$this->expectException(\Aws\DefaultsMode\Exception\ConfigurationException::class);
$dir = $this->clearEnv();
$ini = "[custom]";
file_put_contents($dir . '/config', $ini);
Expand All @@ -195,12 +194,10 @@ public function testEnsuresProfileIsNotEmpty()
}
}

/**
* @expectedException \Aws\DefaultsMode\Exception\ConfigurationException
* @expectedExceptionMessage 'foo' not found in
*/
public function testEnsuresFileIsNotEmpty()
{
$this->expectException(\Aws\DefaultsMode\Exception\ConfigurationException::class);
$this->expectExceptionMessage("'foo' not found in");
$dir = $this->clearEnv();
file_put_contents($dir . '/config', '');
putenv('HOME=' . dirname($dir));
Expand All @@ -213,12 +210,10 @@ public function testEnsuresFileIsNotEmpty()
}
}

/**
* @expectedException \Aws\DefaultsMode\Exception\ConfigurationException
* @expectedExceptionMessage Invalid config file:
*/
public function testEnsuresIniFileIsValid()
{
$this->expectException(\Aws\DefaultsMode\Exception\ConfigurationException::class);
$this->expectExceptionMessage("Invalid config file:");
$dir = $this->clearEnv();
file_put_contents($dir . '/config', "wef \n=\nwef");
putenv('HOME=' . dirname($dir));
Expand Down Expand Up @@ -285,11 +280,9 @@ public function testChainsConfiguration()
unlink($dir . '/config');
}

/**
* @expectedException \InvalidArgumentException
*/
public function testChainThrowsExceptionOnEmptyArgs()
{
$this->expectException(\InvalidArgumentException::class);
ConfigurationProvider::chain();
}

Expand Down Expand Up @@ -406,12 +399,10 @@ public function testCreatesLegacy()
self::assertNull($config->getStsRegionalEndpoints());
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage is not a valid mode. The mode has to be 'legacy', 'standard', 'cross-region', 'in-region', 'mobile', or 'auto'.
*/
public function testThrowsForInvalidUnwrapArgument()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage("is not a valid mode. The mode has to be 'legacy', 'standard', 'cross-region', 'in-region', 'mobile', or 'auto'.");
ConfigurationProvider::unwrap('some_string');
}
}
9 changes: 5 additions & 4 deletions tests/DefaultsMode/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
namespace Aws\Test\DefaultsMode;

use Aws\DefaultsMode\Configuration;
use Aws\Test\Polyfill\PHPUnit\PHPUnitCompatTrait;
use PHPUnit\Framework\TestCase;

/**
* @covers \Aws\DefaultsMode\Configuration
*/
class ConfigurationTest extends TestCase
{
use PHPUnitCompatTrait;

public function testGetsCorrectValues()
{
$config = new Configuration('standard');
Expand Down Expand Up @@ -42,12 +45,10 @@ public function testToArrayWithLegacy()
$this->assertEquals($expected, $config->toArray());
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage 'foo' is not a valid mode
*/
public function testHandlesInvalidMode()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage("'foo' is not a valid mode");
new Configuration('foo');
}
}
4 changes: 2 additions & 2 deletions tests/DynamoDb/DynamoDbClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public function testRegisterSessionHandlerReturnsHandler()
{
$client = $this->getTestSdk()->createDynamoDb();
@$sh = $client->registerSessionHandler(['locking' => true]);
$this->assertAttributeInstanceOf(
$this->assertInstanceOf(
'Aws\DynamoDb\LockingSessionConnection',
'connection', $sh
$this->readAttribute($sh, 'connection')
);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Endpoint/PartitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ public function testGetVariantIgnoresVariantTagOrder(
]
]);

self::assertContains('testsuffix.com', $resolved['endpoint']);
$this->assertStringContainsString('testsuffix.com', $resolved['endpoint']);
}

public function variantTagProvider()
Expand Down Expand Up @@ -841,7 +841,7 @@ public function testGetVariantNoVariantSelectedIfTagsAreEmpty(
]
]);

self::assertNotContains('testsuffix.com', $resolved['endpoint']);
$this->assertStringNotContainsString('testsuffix.com', $resolved['endpoint']);
}

public function variantTagEmptyProvider()
Expand Down
31 changes: 12 additions & 19 deletions tests/Endpoint/UseDualstackEndpoint/ConfigurationProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Aws\Endpoint\UseDualstackEndpoint\Configuration;
use Aws\Endpoint\UseDualstackEndpoint\ConfigurationInterface;
use Aws\Endpoint\UseDualstackEndpoint\Exception\ConfigurationException;
use Aws\Test\Polyfill\PHPUnit\PHPUnitCompatTrait;
use GuzzleHttp\Promise;
use PHPUnit\Framework\TestCase;

Expand All @@ -15,6 +16,8 @@
*/
class ConfigurationProviderTest extends TestCase
{
use PHPUnitCompatTrait;

private static $originalEnv;

private $iniFile = <<<EOT
Expand All @@ -31,7 +34,7 @@ class ConfigurationProviderTest extends TestCase
use_dualstack_endpoint = true
EOT;

public static function setUpBeforeClass()
public static function _setUpBeforeClass()
{
self::$originalEnv = [
'use_dualstack_endpoint' => getenv(ConfigurationProvider::ENV_USE_DUAL_STACK_ENDPOINT) ?: '',
Expand All @@ -54,7 +57,7 @@ private function clearEnv()
return $dir;
}

public static function tearDownAfterClass()
public static function _tearDownAfterClass()
{
putenv(ConfigurationProvider::ENV_USE_DUAL_STACK_ENDPOINT . '=' .
self::$originalEnv['use_dualstack_endpoint']);
Expand Down Expand Up @@ -169,21 +172,17 @@ public function testCreatesFromIniFileWithSpecifiedProfile()
unlink($dir . '/config');
}

/**
* @expectedException \Aws\Endpoint\UseDualstackEndpoint\Exception\ConfigurationException
*/
public function testEnsuresIniFileExists()
{
$this->expectException(\Aws\Endpoint\UseDualstackEndpoint\Exception\ConfigurationException::class);
$this->clearEnv();
putenv('HOME=/does/not/exist');
call_user_func(ConfigurationProvider::ini('us-east-1'))->wait();
}

/**
* @expectedException \Aws\Endpoint\UseDualstackEndpoint\Exception\ConfigurationException
*/
public function testEnsuresProfileIsNotEmpty()
{
$this->expectException(\Aws\Endpoint\UseDualstackEndpoint\Exception\ConfigurationException::class);
$dir = $this->clearEnv();
$ini = "[custom]";
file_put_contents($dir . '/config', $ini);
Expand All @@ -197,12 +196,10 @@ public function testEnsuresProfileIsNotEmpty()
}
}

/**
* @expectedException \Aws\Endpoint\UseDualstackEndpoint\Exception\ConfigurationException
* @expectedExceptionMessage 'foo' not found in
*/
public function testEnsuresFileIsNotEmpty()
{
$this->expectException(\Aws\Endpoint\UseDualstackEndpoint\Exception\ConfigurationException::class);
$this->expectExceptionMessage("'foo' not found in");
$dir = $this->clearEnv();
file_put_contents($dir . '/config', '');
putenv('HOME=' . dirname($dir));
Expand All @@ -215,12 +212,10 @@ public function testEnsuresFileIsNotEmpty()
}
}

/**
* @expectedException \Aws\Endpoint\UseDualstackEndpoint\Exception\ConfigurationException
* @expectedExceptionMessage Invalid config file:
*/
public function testEnsuresIniFileIsValid()
{
$this->expectException(\Aws\Endpoint\UseDualstackEndpoint\Exception\ConfigurationException::class);
$this->expectExceptionMessage("Invalid config file:");
$dir = $this->clearEnv();
file_put_contents($dir . '/config', "wef \n=\nwef");
putenv('HOME=' . dirname($dir));
Expand Down Expand Up @@ -290,11 +285,9 @@ public function testChainsConfiguration()
unlink($dir . '/config');
}

/**
* @expectedException \InvalidArgumentException
*/
public function testChainThrowsExceptionOnEmptyArgs()
{
$this->expectException(\InvalidArgumentException::class);
ConfigurationProvider::chain();
}

Expand Down
Loading

0 comments on commit ea3df80

Please sign in to comment.