|
4 | 4 |
|
5 | 5 | use AppKernel; |
6 | 6 | use Aws\AwsClient; |
| 7 | +use Aws\CodeDeploy\CodeDeployClient; |
| 8 | +use Aws\Lambda\LambdaClient; |
| 9 | +use Aws\S3\S3Client; |
7 | 10 | use PHPUnit\Framework\TestCase; |
8 | 11 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
9 | 12 | use Symfony\Component\DependencyInjection\ContainerInterface; |
10 | 13 | use Symfony\Component\DependencyInjection\Reference; |
11 | 14 |
|
12 | 15 | class AwsExtensionTest extends TestCase |
13 | 16 | { |
| 17 | + /** |
| 18 | + * @var AppKernel |
| 19 | + */ |
| 20 | + protected $kernel; |
| 21 | + |
14 | 22 | /** |
15 | 23 | * @var ContainerInterface |
16 | 24 | */ |
17 | 25 | protected $container; |
18 | 26 |
|
19 | 27 | public function setUp() |
20 | 28 | { |
21 | | - $kernel = new AppKernel('test', true); |
22 | | - $kernel->boot(); |
| 29 | + $this->kernel = new AppKernel('test', true); |
| 30 | + $this->kernel->boot(); |
23 | 31 |
|
24 | | - $this->container = $kernel->getContainer(); |
| 32 | + $this->container = $this->kernel->getContainer(); |
25 | 33 | } |
26 | 34 |
|
27 | 35 | /** |
28 | 36 | * @test |
29 | 37 | */ |
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() |
31 | 39 | { |
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']; |
34 | 44 |
|
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()); |
55 | 50 | } |
56 | 51 |
|
57 | 52 | /** |
58 | 53 | * @test |
59 | | - * @dataProvider serviceRegionProvider |
60 | 54 | * |
61 | | - * @param string $serviceName |
62 | | - * @param string $serviceRegion |
63 | 55 | */ |
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()); |
69 | 62 |
|
70 | | - $this->assertSame($serviceRegion, $service->getRegion()); |
| 63 | + foreach ($testService->getClients() as $client) { |
| 64 | + $this->assertInstanceOf(AwsClient::class, $client); |
| 65 | + } |
71 | 66 | } |
72 | 67 |
|
73 | 68 | /** |
@@ -126,54 +121,4 @@ public function extension_should_expand_service_references() |
126 | 121 |
|
127 | 122 | $extension->load([$config], $container); |
128 | 123 | } |
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 | | - } |
179 | 124 | } |
0 commit comments