diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 671a5a8..c58fede 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,32 +7,57 @@ on: pull_request: branches: [ master ] +permissions: + contents: read + jobs: run: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 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: ['7.2.5', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] + composer-options: ['', '--prefer-lowest'] #set the name for each job - name: PHP ${{ matrix.php-versions }} + name: PHP ${{ matrix.php-versions }} ${{ matrix.composer-options }} + #set up environment variables used by unit tests + env: + AWS_ACCESS_KEY_ID: foo + AWS_SECRET_ACCESS_KEY: bar + AWS_CSM_ENABLED: false + AWS_SUPPRESS_PHP_DEPRECATION_WARNING: true steps: #sets up the correct version of PHP with necessary config options - - name: Setup PHP + - name: Setup PHP with Xdebug uses: shivammathur/setup-php@v2 with: + coverage: xdebug php-version: ${{ matrix.php-versions }} - ini-values: memory_limit=4G, phar.readonly=false + ini-values: xdebug.overload_var_dump=0, memory_limit=4G, phar.readonly=false #checkout the codebase from github - name: Checkout codebase - uses: actions/checkout@v3 + uses: actions/checkout@v4 + + #validate composer files + - name: Validate composer.json and composer.lock + run: composer validate - #run composer - - name: Composer install - run: composer install + #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.4.5" --no-interaction --prefer-source --with-all-dependencies #run tests - name: Run test suite - run: vendor/bin/phpunit \ No newline at end of file + run: make test + diff --git a/composer.json b/composer.json index 9f9240d..2c37c14 100644 --- a/composer.json +++ b/composer.json @@ -12,16 +12,16 @@ } ], "require": { - "php": ">=5.5", - "aws/aws-sdk-php": "^3.2.6", - "symfony/config": "~2.3|~3.0|~4.0|~5.0|~6.0", - "symfony/dependency-injection": "~2.3|~3.0|~4.0|~5.0|~6.0", - "symfony/http-kernel": "~2.3|~3.0|~4.0|~5.0|~6.0" + "php": ">=7.2.5", + "aws/aws-sdk-php": "^3.279.0", + "symfony/config": "~5.0|~6.0|~7.0", + "symfony/dependency-injection": "~5.0|~6.0|~7.0", + "symfony/http-kernel": "~5.0|~6.0|~7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8.35|^5.6.3|^6.0.0", - "symfony/framework-bundle": "~2.3|~3.0|~4.0|~5.0|~6.0", - "symfony/yaml": "~2.3|~3.0|~4.0|~5.0|~6.0" + "phpunit/phpunit": "^8.5|^9.5", + "symfony/framework-bundle": "~5.0|~6.0|~7.0", + "symfony/yaml": "~5.0|~6.0|~7.0" }, "autoload": { "psr-4": { diff --git a/src/DependencyInjection/AwsExtension.php b/src/DependencyInjection/AwsExtension.php index c51ac76..b496eb5 100644 --- a/src/DependencyInjection/AwsExtension.php +++ b/src/DependencyInjection/AwsExtension.php @@ -15,7 +15,10 @@ class AwsExtension extends Extension { - public function load(array $configs, ContainerBuilder $container) + /** + * @throws \Exception + */ + public function load(array $configs, ContainerBuilder $container): void { $loader = new YamlFileLoader( $container, @@ -44,7 +47,7 @@ public function load(array $configs, ContainerBuilder $container) } - private function createServiceDefinition($name) + private function createServiceDefinition($name): Definition { $clientClass = "Aws\\{$name}\\{$name}Client"; $serviceDefinition = new Definition( @@ -53,21 +56,13 @@ class_exists($clientClass) ? $clientClass : AwsClient::class $serviceDefinition->setLazy(true); - // Handle Symfony >= 2.6 - if (method_exists($serviceDefinition, 'setFactory')) { - return $serviceDefinition->setFactory([ - new Reference('aws_sdk'), - 'createClient', - ])->setArguments([$name]); - } - - return $serviceDefinition - ->setFactoryService('aws_sdk') - ->setFactoryMethod('createClient') - ->setArguments([$name]); + return $serviceDefinition->setFactory([ + new Reference('aws_sdk'), + 'createClient', + ])->setArguments([$name]); } - private function inflateServicesInConfig(array &$config) + private function inflateServicesInConfig(array &$config): void { array_walk($config, function (&$value) { if (is_array($value)) { diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 6dc866f..2a13fbe 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -8,7 +8,7 @@ class Configuration implements ConfigurationInterface { - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { // Maintain backwars compatibility, only merge when AWS_MERGE_CONFIG is set $mergeConfig = $this->shouldMergeConfig(); @@ -70,8 +70,7 @@ public function getConfigTreeBuilder() ->variableNode('ua_append')->end() ->variableNode('validate')->end() ->scalarNode('version')->end() - ->end() - ; + ->end(); //Setup config trees for each of the services foreach (array_column(Aws\manifest(), 'namespace') as $awsService) { @@ -111,14 +110,13 @@ public function getConfigTreeBuilder() ->scalarNode('version')->end() ->end() ->end() - ->end() - ; + ->end(); } return $treeBuilder; } - protected function shouldMergeConfig() + protected function shouldMergeConfig(): ?string { # works with symfony/dotenv if (isset($_ENV['AWS_MERGE_CONFIG'])) { diff --git a/tests/DependencyInjection/AwsExtensionTest.php b/tests/DependencyInjection/AwsExtensionTest.php index 6c9fd1b..7db8c61 100644 --- a/tests/DependencyInjection/AwsExtensionTest.php +++ b/tests/DependencyInjection/AwsExtensionTest.php @@ -10,6 +10,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; class AwsExtensionTest extends TestCase @@ -24,7 +25,7 @@ class AwsExtensionTest extends TestCase */ protected $container; - public function setUp() + public function setUp(): void { $this->kernel = new AppKernel('test', true); $this->kernel->boot(); @@ -38,9 +39,9 @@ public function setUp() public function sdk_config_should_be_passed_directly_to_the_constructor_and_resolved_by_the_sdk() { $config = $this->kernel->getTestConfig()['aws']; - $s3Region = isset($config['S3']['region']) ? $config['S3']['region'] : $config['region']; - $lambdaRegion = isset($config['Lambda']['region']) ? $config['Lambda']['region'] : $config['region']; - $codeDeployRegion = isset($config['CodeDeploy']['region']) ? $config['CodeDeploy']['region'] : $config['region']; + $s3Region = $config['S3']['region'] ?? $config['region']; + $lambdaRegion = $config['Lambda']['region'] ?? $config['region']; + $codeDeployRegion = $config['CodeDeploy']['region'] ?? $config['region']; $testService = $this->container->get('test_service'); @@ -76,13 +77,16 @@ public function extension_should_escape_strings_that_begin_with_at_sign() 'secret' => '@@secret' ]]; $container = $this->getMockBuilder(ContainerBuilder::class) - ->setMethods(['getDefinition', 'replaceArgument']) + ->onlyMethods(['getDefinition']) + ->getMock(); + $definition = $this->getMockBuilder(Definition::class) + ->onlyMethods(['replaceArgument']) ->getMock(); $container->expects($this->once()) ->method('getDefinition') ->with('aws_sdk') - ->willReturnSelf(); - $container->expects($this->once()) + ->willReturn($definition); + $definition->expects($this->once()) ->method('replaceArgument') ->with(0, $this->callback(function ($arg) { return is_array($arg) @@ -104,13 +108,16 @@ public function extension_should_expand_service_references() $extension = new AwsExtension; $config = ['credentials' => '@aws_sdk']; $container = $this->getMockBuilder(ContainerBuilder::class) - ->setMethods(['getDefinition', 'replaceArgument']) + ->onlyMethods(['getDefinition']) + ->getMock(); + $definition = $this->getMockBuilder(Definition::class) + ->onlyMethods(['replaceArgument']) ->getMock(); $container->expects($this->once()) ->method('getDefinition') ->with('aws_sdk') - ->willReturnSelf(); - $container->expects($this->once()) + ->willReturn($definition); + $definition->expects($this->once()) ->method('replaceArgument') ->with(0, $this->callback(function ($arg) { return is_array($arg) @@ -137,7 +144,6 @@ public function extension_should_validate_and_merge_configs() 'stats' => [ 'http' => true ], - 'retries' => 5, 'endpoint' => 'http://localhost:8000', 'endpoint_discovery' => [ 'enabled' => true, @@ -181,13 +187,16 @@ public function extension_should_validate_and_merge_configs() 'validate' => true, ]; $container = $this->getMockBuilder(ContainerBuilder::class) - ->setMethods(['getDefinition', 'replaceArgument']) + ->onlyMethods(['getDefinition']) + ->getMock(); + $definition = $this->getMockBuilder(Definition::class) + ->onlyMethods(['replaceArgument']) ->getMock(); $container->expects($this->once()) ->method('getDefinition') ->with('aws_sdk') - ->willReturnSelf(); - $container->expects($this->once()) + ->willReturn($definition); + $definition->expects($this->once()) ->method('replaceArgument') ->with(0, $this->callback(function ($arg) { return is_array($arg) @@ -230,9 +239,8 @@ public function extension_should_error_merging_unknown_config_options() 'foo' => 'baz' ]; $container = $this->getMockBuilder(ContainerBuilder::class) - ->setMethods(['getDefinition', 'replaceArgument']) + ->onlyMethods(['getDefinition']) ->getMock(); - try { $extension->load([$config, $configDev], $container); $this->fail('Should have thrown an Error or RuntimeException'); diff --git a/tests/DependencyInjection/ConfigurationTest.php b/tests/DependencyInjection/ConfigurationTest.php index 49e2454..ef66fdc 100644 --- a/tests/DependencyInjection/ConfigurationTest.php +++ b/tests/DependencyInjection/ConfigurationTest.php @@ -10,7 +10,7 @@ class ConfigurationTest extends TestCase { - public function setUp() + public function setUp(): void { (new Filesystem) ->remove(implode(DIRECTORY_SEPARATOR, [ @@ -39,7 +39,7 @@ public function container_should_compile_and_load($format) $this->assertNotInstanceOf(DynamoDbClient::class, $testService->getCodeDeployClient()); } - public function formatProvider() + public function formatProvider(): array { return [ ['yml'], diff --git a/tests/fixtures/AppKernel.php b/tests/fixtures/AppKernel.php index 733d86d..b3f79f6 100644 --- a/tests/fixtures/AppKernel.php +++ b/tests/fixtures/AppKernel.php @@ -16,7 +16,7 @@ public function __construct($env, $debug, $extension = 'yml') parent::__construct($env, $debug); } - public function registerBundles() + public function registerBundles(): iterable { return [ new FrameworkBundle(), @@ -24,7 +24,7 @@ public function registerBundles() ]; } - public function registerContainerConfiguration(LoaderInterface $loader) + public function registerContainerConfiguration(LoaderInterface $loader): void { $loader->load($this->getTestConfigFile($this->extension)); } @@ -35,7 +35,7 @@ public function getTestConfig() } - private function getTestConfigFile($extension) + private function getTestConfigFile($extension): string { return __DIR__ . '/config.' . $extension; } diff --git a/tests/fixtures/TestService.php b/tests/fixtures/TestService.php index 8f48792..2a7868b 100644 --- a/tests/fixtures/TestService.php +++ b/tests/fixtures/TestService.php @@ -35,7 +35,7 @@ public function __construct( /** * @return S3Client */ - public function getS3Client() + public function getS3Client(): S3Client { return $this->s3Client; } @@ -43,7 +43,7 @@ public function getS3Client() /** * @return LambdaClient */ - public function getLambdaClient() + public function getLambdaClient(): LambdaClient { return $this->lambdaClient; } @@ -51,7 +51,7 @@ public function getLambdaClient() /** * @return CodeDeployClient */ - public function getCodeDeployClient() + public function getCodeDeployClient(): CodeDeployClient { return $this->codeDeployClient; } @@ -59,7 +59,7 @@ public function getCodeDeployClient() /** * @return array */ - public function getClients() + public function getClients(): array { return [ $this->s3Client,