Skip to content

Commit 6ee6fc4

Browse files
yenfryherrerafelizSean O'Brien
and
Sean O'Brien
authored
feat: add Symfony-7 support & deprecates old PHPvs (symfony#104)
Co-authored-by: Sean O'Brien <[email protected]>
1 parent 73495ac commit 6ee6fc4

File tree

8 files changed

+91
-65
lines changed

8 files changed

+91
-65
lines changed

.github/workflows/tests.yml

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,57 @@ on:
77
pull_request:
88
branches: [ master ]
99

10+
permissions:
11+
contents: read
12+
1013
jobs:
1114
run:
12-
runs-on: ubuntu-18.04
15+
runs-on: ubuntu-20.04
1316
strategy:
1417
#for each of the following versions of PHP, with and without --prefer-lowest
1518
matrix:
16-
php-versions: ['5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4']
17-
19+
php-versions: ['7.2.5', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
20+
composer-options: ['', '--prefer-lowest']
1821
#set the name for each job
19-
name: PHP ${{ matrix.php-versions }}
22+
name: PHP ${{ matrix.php-versions }} ${{ matrix.composer-options }}
23+
#set up environment variables used by unit tests
24+
env:
25+
AWS_ACCESS_KEY_ID: foo
26+
AWS_SECRET_ACCESS_KEY: bar
27+
AWS_CSM_ENABLED: false
28+
AWS_SUPPRESS_PHP_DEPRECATION_WARNING: true
2029
steps:
2130
#sets up the correct version of PHP with necessary config options
22-
- name: Setup PHP
31+
- name: Setup PHP with Xdebug
2332
uses: shivammathur/setup-php@v2
2433
with:
34+
coverage: xdebug
2535
php-version: ${{ matrix.php-versions }}
26-
ini-values: memory_limit=4G, phar.readonly=false
36+
ini-values: xdebug.overload_var_dump=0, memory_limit=4G, phar.readonly=false
2737

2838
#checkout the codebase from github
2939
- name: Checkout codebase
30-
uses: actions/checkout@v3
40+
uses: actions/checkout@v4
41+
42+
#validate composer files
43+
- name: Validate composer.json and composer.lock
44+
run: composer validate
3145

32-
#run composer
33-
- name: Composer install
34-
run: composer install
46+
#get dependencies
47+
- name: Install dependencies
48+
run: composer update ${{ matrix.composer-options }} --no-interaction --prefer-source
49+
50+
#php 8.x requirements
51+
- if: ${{ matrix.php-versions >= '8.0' && matrix.composer-options != '' }}
52+
name: PHP 8.x
53+
run: composer require --dev phpunit/phpunit "^9.5" --no-interaction --prefer-source --with-all-dependencies
54+
55+
#php 8.1+ requirements
56+
- if: ${{ matrix.php-versions >= '8.1' && matrix.composer-options != '' }}
57+
name: PHP 8.1+
58+
run: composer require --dev guzzlehttp/guzzle "^7.4.5" --no-interaction --prefer-source --with-all-dependencies
3559

3660
#run tests
3761
- name: Run test suite
38-
run: vendor/bin/phpunit
62+
run: make test
63+

composer.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
}
1313
],
1414
"require": {
15-
"php": ">=5.5",
16-
"aws/aws-sdk-php": "^3.2.6",
17-
"symfony/config": "~2.3|~3.0|~4.0|~5.0|~6.0",
18-
"symfony/dependency-injection": "~2.3|~3.0|~4.0|~5.0|~6.0",
19-
"symfony/http-kernel": "~2.3|~3.0|~4.0|~5.0|~6.0"
15+
"php": ">=7.2.5",
16+
"aws/aws-sdk-php": "^3.279.0",
17+
"symfony/config": "~5.0|~6.0|~7.0",
18+
"symfony/dependency-injection": "~5.0|~6.0|~7.0",
19+
"symfony/http-kernel": "~5.0|~6.0|~7.0"
2020
},
2121
"require-dev": {
22-
"phpunit/phpunit": "^4.8.35|^5.6.3|^6.0.0",
23-
"symfony/framework-bundle": "~2.3|~3.0|~4.0|~5.0|~6.0",
24-
"symfony/yaml": "~2.3|~3.0|~4.0|~5.0|~6.0"
22+
"phpunit/phpunit": "^8.5|^9.5",
23+
"symfony/framework-bundle": "~5.0|~6.0|~7.0",
24+
"symfony/yaml": "~5.0|~6.0|~7.0"
2525
},
2626
"autoload": {
2727
"psr-4": {

src/DependencyInjection/AwsExtension.php

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515

1616
class AwsExtension extends Extension
1717
{
18-
public function load(array $configs, ContainerBuilder $container)
18+
/**
19+
* @throws \Exception
20+
*/
21+
public function load(array $configs, ContainerBuilder $container): void
1922
{
2023
$loader = new YamlFileLoader(
2124
$container,
@@ -44,7 +47,7 @@ public function load(array $configs, ContainerBuilder $container)
4447
}
4548

4649

47-
private function createServiceDefinition($name)
50+
private function createServiceDefinition($name): Definition
4851
{
4952
$clientClass = "Aws\\{$name}\\{$name}Client";
5053
$serviceDefinition = new Definition(
@@ -53,21 +56,13 @@ class_exists($clientClass) ? $clientClass : AwsClient::class
5356

5457
$serviceDefinition->setLazy(true);
5558

56-
// Handle Symfony >= 2.6
57-
if (method_exists($serviceDefinition, 'setFactory')) {
58-
return $serviceDefinition->setFactory([
59-
new Reference('aws_sdk'),
60-
'createClient',
61-
])->setArguments([$name]);
62-
}
63-
64-
return $serviceDefinition
65-
->setFactoryService('aws_sdk')
66-
->setFactoryMethod('createClient')
67-
->setArguments([$name]);
59+
return $serviceDefinition->setFactory([
60+
new Reference('aws_sdk'),
61+
'createClient',
62+
])->setArguments([$name]);
6863
}
6964

70-
private function inflateServicesInConfig(array &$config)
65+
private function inflateServicesInConfig(array &$config): void
7166
{
7267
array_walk($config, function (&$value) {
7368
if (is_array($value)) {

src/DependencyInjection/Configuration.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class Configuration implements ConfigurationInterface
1010
{
11-
public function getConfigTreeBuilder()
11+
public function getConfigTreeBuilder(): TreeBuilder
1212
{
1313
// Maintain backwars compatibility, only merge when AWS_MERGE_CONFIG is set
1414
$mergeConfig = $this->shouldMergeConfig();
@@ -70,8 +70,7 @@ public function getConfigTreeBuilder()
7070
->variableNode('ua_append')->end()
7171
->variableNode('validate')->end()
7272
->scalarNode('version')->end()
73-
->end()
74-
;
73+
->end();
7574

7675
//Setup config trees for each of the services
7776
foreach (array_column(Aws\manifest(), 'namespace') as $awsService) {
@@ -111,14 +110,13 @@ public function getConfigTreeBuilder()
111110
->scalarNode('version')->end()
112111
->end()
113112
->end()
114-
->end()
115-
;
113+
->end();
116114
}
117115

118116
return $treeBuilder;
119117
}
120118

121-
protected function shouldMergeConfig()
119+
protected function shouldMergeConfig(): ?string
122120
{
123121
# works with symfony/dotenv
124122
if (isset($_ENV['AWS_MERGE_CONFIG'])) {

tests/DependencyInjection/AwsExtensionTest.php

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PHPUnit\Framework\TestCase;
1111
use Symfony\Component\DependencyInjection\ContainerBuilder;
1212
use Symfony\Component\DependencyInjection\ContainerInterface;
13+
use Symfony\Component\DependencyInjection\Definition;
1314
use Symfony\Component\DependencyInjection\Reference;
1415

1516
class AwsExtensionTest extends TestCase
@@ -24,7 +25,7 @@ class AwsExtensionTest extends TestCase
2425
*/
2526
protected $container;
2627

27-
public function setUp()
28+
public function setUp(): void
2829
{
2930
$this->kernel = new AppKernel('test', true);
3031
$this->kernel->boot();
@@ -38,9 +39,9 @@ public function setUp()
3839
public function sdk_config_should_be_passed_directly_to_the_constructor_and_resolved_by_the_sdk()
3940
{
4041
$config = $this->kernel->getTestConfig()['aws'];
41-
$s3Region = isset($config['S3']['region']) ? $config['S3']['region'] : $config['region'];
42-
$lambdaRegion = isset($config['Lambda']['region']) ? $config['Lambda']['region'] : $config['region'];
43-
$codeDeployRegion = isset($config['CodeDeploy']['region']) ? $config['CodeDeploy']['region'] : $config['region'];
42+
$s3Region = $config['S3']['region'] ?? $config['region'];
43+
$lambdaRegion = $config['Lambda']['region'] ?? $config['region'];
44+
$codeDeployRegion = $config['CodeDeploy']['region'] ?? $config['region'];
4445

4546
$testService = $this->container->get('test_service');
4647

@@ -76,13 +77,16 @@ public function extension_should_escape_strings_that_begin_with_at_sign()
7677
'secret' => '@@secret'
7778
]];
7879
$container = $this->getMockBuilder(ContainerBuilder::class)
79-
->setMethods(['getDefinition', 'replaceArgument'])
80+
->onlyMethods(['getDefinition'])
81+
->getMock();
82+
$definition = $this->getMockBuilder(Definition::class)
83+
->onlyMethods(['replaceArgument'])
8084
->getMock();
8185
$container->expects($this->once())
8286
->method('getDefinition')
8387
->with('aws_sdk')
84-
->willReturnSelf();
85-
$container->expects($this->once())
88+
->willReturn($definition);
89+
$definition->expects($this->once())
8690
->method('replaceArgument')
8791
->with(0, $this->callback(function ($arg) {
8892
return is_array($arg)
@@ -104,13 +108,16 @@ public function extension_should_expand_service_references()
104108
$extension = new AwsExtension;
105109
$config = ['credentials' => '@aws_sdk'];
106110
$container = $this->getMockBuilder(ContainerBuilder::class)
107-
->setMethods(['getDefinition', 'replaceArgument'])
111+
->onlyMethods(['getDefinition'])
112+
->getMock();
113+
$definition = $this->getMockBuilder(Definition::class)
114+
->onlyMethods(['replaceArgument'])
108115
->getMock();
109116
$container->expects($this->once())
110117
->method('getDefinition')
111118
->with('aws_sdk')
112-
->willReturnSelf();
113-
$container->expects($this->once())
119+
->willReturn($definition);
120+
$definition->expects($this->once())
114121
->method('replaceArgument')
115122
->with(0, $this->callback(function ($arg) {
116123
return is_array($arg)
@@ -137,7 +144,6 @@ public function extension_should_validate_and_merge_configs()
137144
'stats' => [
138145
'http' => true
139146
],
140-
'retries' => 5,
141147
'endpoint' => 'http://localhost:8000',
142148
'endpoint_discovery' => [
143149
'enabled' => true,
@@ -181,13 +187,16 @@ public function extension_should_validate_and_merge_configs()
181187
'validate' => true,
182188
];
183189
$container = $this->getMockBuilder(ContainerBuilder::class)
184-
->setMethods(['getDefinition', 'replaceArgument'])
190+
->onlyMethods(['getDefinition'])
191+
->getMock();
192+
$definition = $this->getMockBuilder(Definition::class)
193+
->onlyMethods(['replaceArgument'])
185194
->getMock();
186195
$container->expects($this->once())
187196
->method('getDefinition')
188197
->with('aws_sdk')
189-
->willReturnSelf();
190-
$container->expects($this->once())
198+
->willReturn($definition);
199+
$definition->expects($this->once())
191200
->method('replaceArgument')
192201
->with(0, $this->callback(function ($arg) {
193202
return is_array($arg)
@@ -230,9 +239,8 @@ public function extension_should_error_merging_unknown_config_options()
230239
'foo' => 'baz'
231240
];
232241
$container = $this->getMockBuilder(ContainerBuilder::class)
233-
->setMethods(['getDefinition', 'replaceArgument'])
242+
->onlyMethods(['getDefinition'])
234243
->getMock();
235-
236244
try {
237245
$extension->load([$config, $configDev], $container);
238246
$this->fail('Should have thrown an Error or RuntimeException');

tests/DependencyInjection/ConfigurationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class ConfigurationTest extends TestCase
1212
{
13-
public function setUp()
13+
public function setUp(): void
1414
{
1515
(new Filesystem)
1616
->remove(implode(DIRECTORY_SEPARATOR, [
@@ -39,7 +39,7 @@ public function container_should_compile_and_load($format)
3939
$this->assertNotInstanceOf(DynamoDbClient::class, $testService->getCodeDeployClient());
4040
}
4141

42-
public function formatProvider()
42+
public function formatProvider(): array
4343
{
4444
return [
4545
['yml'],

tests/fixtures/AppKernel.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ public function __construct($env, $debug, $extension = 'yml')
1616
parent::__construct($env, $debug);
1717
}
1818

19-
public function registerBundles()
19+
public function registerBundles(): iterable
2020
{
2121
return [
2222
new FrameworkBundle(),
2323
new AwsBundle(),
2424
];
2525
}
2626

27-
public function registerContainerConfiguration(LoaderInterface $loader)
27+
public function registerContainerConfiguration(LoaderInterface $loader): void
2828
{
2929
$loader->load($this->getTestConfigFile($this->extension));
3030
}
@@ -35,7 +35,7 @@ public function getTestConfig()
3535
}
3636

3737

38-
private function getTestConfigFile($extension)
38+
private function getTestConfigFile($extension): string
3939
{
4040
return __DIR__ . '/config.' . $extension;
4141
}

tests/fixtures/TestService.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,31 @@ public function __construct(
3535
/**
3636
* @return S3Client
3737
*/
38-
public function getS3Client()
38+
public function getS3Client(): S3Client
3939
{
4040
return $this->s3Client;
4141
}
4242

4343
/**
4444
* @return LambdaClient
4545
*/
46-
public function getLambdaClient()
46+
public function getLambdaClient(): LambdaClient
4747
{
4848
return $this->lambdaClient;
4949
}
5050

5151
/**
5252
* @return CodeDeployClient
5353
*/
54-
public function getCodeDeployClient()
54+
public function getCodeDeployClient(): CodeDeployClient
5555
{
5656
return $this->codeDeployClient;
5757
}
5858

5959
/**
6060
* @return array
6161
*/
62-
public function getClients()
62+
public function getClients(): array
6363
{
6464
return [
6565
$this->s3Client,

0 commit comments

Comments
 (0)