8000 Merge pull request #34 from brianfreytag/symfony4 · stobrien89/symfony@cee5d93 · GitHub
[go: up one dir, main page]

Skip to content

Commit cee5d93

Browse files
authored
Merge pull request symfony#34 from brianfreytag/symfony4
Make bundle compatible with Symfony 4
2 parents e11e987 + d552edb commit cee5d93

File tree

8 files changed

+147
-91
lines changed

8 files changed

+147
-91
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ php:
66
- 5.6
77
- 7.0
88
- 7.1
9+
- 7.2
910
- hhvm
1011

1112
env:

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
"require": {
1515
"php": ">=5.5",
1616
"aws/aws-sdk-php": "^3.2.6",
17-
"symfony/config": "~2.3|~3.0",
18-
"symfony/dependency-injection": "~2.3|~3.0",
19-
"symfony/http-kernel": "~2.3|~3.0"
17+
"symfony/config": "~2.3|~3.0|~4.0",
18+
"symfony/dependency-injection": "~2.3|~3.0|~4.0",
19+
"symfony/http-kernel": "~2.3|~3.0|~4.0"
2020
},
2121
"require-dev": {
2222
"phpunit/phpunit": "^4.8.35|^5.4.0|^6.0.0",
23-
"symfony/framework-bundle": "~2.3|~3.0",
24-
"symfony/yaml": "~2.3|~3.0"
23+
"symfony/framework-bundle": "~2.3|~3.0|~4.0",
24+
"symfony/yaml": "~2.3|~3.0|~4.0"
2525
},
2626
"autoload": {
2727
"psr-4": {

tests/DependencyInjection/AwsExtensionTest.php

Lines changed: 30 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -4,70 +4,65 @@
44

55
use AppKernel;
66
use Aws\AwsClient;
7+
use Aws\CodeDeploy\CodeDeployClient;
8+
use Aws\Lambda\LambdaClient;
9+
use Aws\S3\S3Client;
710
use PHPUnit\Framework\TestCase;
811
use Symfony\Component\DependencyInjection\ContainerBuilder;
912
use Symfony\Component\DependencyInjection\ContainerInterface;
1013
use Symfony\Component\DependencyInjection\Reference;
1114

1215
class AwsExtensionTest extends TestCase
1316
{
17+
/**
18+
* @var AppKernel
19+
*/
20+
protected $kernel;
21+
1422
/**
1523
* @var ContainerInterface
1624
*/
1725
protected $container;
1826

1927
public function setUp()
2028
{
21-
$kernel = new AppKernel('test', true);
22-
$kernel->boot();
29+
$this->kernel = new AppKernel('test', true);
30+
$this->kernel->boot();
2331

24-
$this->container = $kernel->getContainer();
32+
$this->container = $this->kernel->getContainer();
2533
}
2634

2735
/**
2836
* @test
2937
*/
30-
public function sdk_should_be_accessible_as_a_service()
38+
public function sdk_config_should_be_passed_directly_to_the_constructor_and_resolved_by_the_sdk()
3139
{
32-
$this->assertTrue($this->container->has('aws_sdk'));
33-
}
40+
$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'];
3444

35-
/**
36-
* @test
37-
* @dataProvider serviceProvider
38-
*
39-
* @param string $webServiceName
40-
* @param string $containerServiceName
41-
* @param string $clientClassName
42-
*/
43-
public function all_web_services_in_sdk_manifest_should_be_accessible_as_container_services(
44-
$webServiceName,
45-
$containerServiceName,
46-
$clientClassName
47-
) {
48-
$this->assertTrue(
49-
$this->container->has($containerServiceName)
50-
);
51-
52-
$service = $this->container->get($containerServiceName);
53-
$this->assertInstanceOf($clientClassName, $service);
54-
$this->assertInstanceOf(AwsClient::class, $service);
45+
$testService = $this->container->get('test_service');
46+
47+
$this->assertSame($s3Region, $testService->getS3Client()->getRegion());
48+
$this->assertSame($lambdaRegion, $testService->getLambdaClient()->getRegion());
49+
$this->assertSame($codeDeployRegion, $testService->getCodeDeployClient()->getRegion());
5550
}
5651

5752
/**
5853
* @test
59-
* @dataProvider serviceRegionProvider
6054
*
61-
* @param string $serviceName
62-
* @param string $serviceRegion
6355
*/
64-
public function sdk_config_should_be_passed_directly_to_the_constructor_and_resolved_by_the_sdk(
65-
$serviceName,
66-
$serviceRegion
67-
) {
68-
$service = $this->container->get($serviceName);
56+
public function all_web_services_in_sdk_manifest_should_be_accessible_as_container_services() {
57+
$testService = $this->container->get('test_service');
58+
59+
$this->assertInstanceOf(S3Client::class, $testService->getS3Client());
60+
$this->assertInstanceOf(LambdaClient::class, $testService->getLambdaClient());
61+
$this->assertInstanceOf(CodeDeployClient::class, $testService->getCodeDeployClient());
6962

70-
$this->assertSame($serviceRegion, $service->getRegion());
63+
foreach ($testService->getClients() as $client) {
64+
$this->assertInstanceOf(AwsClient::class, $client);
65+
}
7166
}
7267

7368
/**
@@ -126,54 +121,4 @@ public function extension_should_expand_service_references()
126121

127122
$extension->load([$config], $container);
128123
}
129-
130-
public function serviceProvider()
131-
{
132-
$services = [];
133-
134-
foreach (array_column(\Aws\manifest(), 'namespace') as $serviceNamespace) {
135-
$clientClass = "Aws\\{$serviceNamespace}\\{$serviceNamespace}Client";
136-
$services []= [
137-
$serviceNamespace,
138-
'aws.' . strtolower($serviceNamespace),
139-
class_exists($clientClass) ? $clientClass : AwsClient::class,
140-
];
141-
}
142-
143-
return $services;
144-
}
145-
146-
public function serviceRegionProvider()
147-
{
148-
$kernel = new AppKernel('test', false);
149-
$config = $kernel->getTestConfig()['aws'];
150-
151-
return array_map(
152-
function (array $service) use ($config) {
153-
return [
154-
$service[1],
155-
isset($config[$service[0]]['region']) ?
156-
$config[$service[0]]['region']
157-
: $config['region']
158-
];
159-
},
160-
$this->serviceProvider()
161-
);
162-
}
163-
164-
/**
165-
* @test
166-
*
167-
* @dataProvider serviceProvider
168-
*/
169-
public function extension_should_load_services_by_class_name(
170-
$webServiceName,
171-
$containerServiceName,
172-
$clientClassName
173-
) {
174-
$this->assertInstanceOf(
175-
$clientClassName,
176-
$this->container->get($clientClassName)
177-
);
178-
}
179124
}

tests/DependencyInjection/ConfigurationTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
namespace Aws\Symfony\DependencyInjection;
33

44
use AppKernel;
5+
use Aws\DynamoDb\DynamoDbClient;
6+
use Aws\Lambda\LambdaClient;
7+
use Aws\S3\S3Client;
58
use PHPUnit\Framework\TestCase;
69
use Symfony\Component\Filesystem\Filesystem;
710

@@ -29,7 +32,11 @@ public function container_should_compile_and_load($format)
2932
$kernel = new AppKernel('test', true, $format);
3033
$kernel->boot();
3134

32-
$this->assertTrue($kernel->getContainer()->has('aws_sdk'));
35+
$testService = $kernel->getContainer()->get('test_service');
36+
37+
$this->assertInstanceOf(S3Client::class, $testService->getS3Client());
38+
$this->assertInstanceOf(LambdaClient::class, $testService->getLambdaClient());
39+
$this->assertNotInstanceOf(DynamoDbClient::class, $testService->getCodeDeployClient());
3340
}
3441

3542
public function formatProvider()

tests/fixtures/TestService.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
namespace Aws\Symfony\fixtures;
4+
5+
use Aws\CodeDeploy\CodeDeployClient;
6+
use Aws\Lambda\LambdaClient;
7+
use Aws\S3\S3Client;
8+
9+
class TestService
10+
{
11+
/** @var S3Client */
12+
protected $s3Client;
13+
14+
/** @var LambdaClient */
15+
protected $lambdaClient;
16+
17+
/** @var CodeDeployClient */
18+
protected $codeDeployClient;
19+
20+
/**
21+
* @param S3Client $s3Client
22+
* @param LambdaClient $lambdaClient
23+
* @param CodeDeployClient $codeDeployClient
24+
*/
25+
public function __construct(
26+
S3Client $s3Client,
27+
LambdaClient $lambdaClient,
28+
CodeDeployClient $codeDeployClient
29+
) {
30+
$this->s3Client = $s3Client;
31+
$this->lambdaClient = $lambdaClient;
32+
$this->codeDeployClient = $codeDeployClient;
33+
}
34+
35+
/**
36+
* @return S3Client
37+
*/
38+
public function getS3Client()
39+
{
40+
return $this->s3Client;
41+
}
42+
43+
/**
44+
* @return LambdaClient
45+
*/
46+
public function getLambdaClient()
47+
{
48+
return $this->lambdaClient;
49+
}
50+
51+
/**
52+
* @return CodeDeployClient
53+
*/
54+
public function getCodeDeployClient()
55+
{
56+
return $this->codeDeployClient;
57+
}
58+
59+
/**
60+
* @return array
61+
*/
62+
public function getClients()
63+
{
64+
return [
65+
$this->s3Client,
66+
$this->lambdaClient,
67+
$this->codeDeployClient
68+
];
69+
}
70+
}

tests/fixtures/config.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
'S3' => [
2121
'version' => '2006-03-01',
2222
],
23+
'Lambda' => [
24+
'region' => 'us-central-1'
25+
],
26+
'CodeDeploy' => [
27+
'region' => 'us-west-2'
28+
],
2329
'Sqs' =>[
2430
'credentials' => new Reference('a_service'), // '@a_service' would also work in a PHP config
2531
],
@@ -33,6 +39,13 @@
3339
->addArgument('a-different-fake-key')
3440
->addArgument('a-different-fake-secret');
3541

42+
$container
43+
->register('test_service', 'Aws\\Symfony\\fixtures\\TestService')
44+
->setPublic(true)
45+
->addArgument(new Reference('aws.s3'))
46+
->addArgument(new Reference('aws.lambda'))
47+
->addArgument(new Reference('aws.codedeploy'));
48+
3649
$container
3750
->register(DynamoDbClient::class, DynamoDbClient::class)
3851
->addArgument([

tests/fixtures/config.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
<aws:DynamoDb region="us-west-2"/>
1717
<aws:S3 version="2006-03-01"/>
1818
<aws:Sqs credentials="@a_service"/>
19+
<aws:Lambda region="us-central-1"/>
20+
<aws:CodeDeploy region="us-west-2"/>
1921
</aws:config>
2022

2123
<parameters>
@@ -34,5 +36,11 @@
3436
<service id="Aws\DynamoDb\DynamoDbClient" class="Aws\DynamoDb\DynamoDbClient">
3537
<argument>%dynamodb_client_config%</argument>
3638
</service>
39+
40+
<service id="test_service" class="Aws\Symfony\fixtures\TestService" public="true">
41+
<argument type="service" id="aws.s3" />
42+
<argument type="service" id="aws.lambda" />
43+
<argument type="service" id="aws.codedeploy" />
44+
</service>
3745
</services>
3846
</container>

tests/fixtures/config.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ aws:
1313
version: '2006-03-01'
1414
Sqs:
1515
credentials: "@a_service"
16+
Lambda:
17+
region: us-central-1
18+
CodeDeploy:
19+
region: us-west-2
1620
CloudSearchDomain:
1721
endpoint: https://search-with-some-subdomain.us-east-1.cloudsearch.amazonaws.com
1822

@@ -28,3 +32,11 @@ services:
2832
arguments:
2933
- a-different-fake-key
3034
- a-different-fake-secret
35+
36+
test_service:
37+
class: Aws\Symfony\fixtures\TestService
38+
public: true
39+
arguments:
40+
- '@aws.s3'
41+
- '@aws.lambda'
42+
- '@aws.codedeploy'

0 commit comments

Comments
 (0)
0