12
12
use AsyncAws \Symfony \Bundle \AsyncAwsBundle ;
13
13
use AsyncAws \Symfony \Bundle \Secrets \SsmVault ;
14
14
use Nyholm \BundleTest \TestKernel ;
15
+ use Symfony \Bundle \FrameworkBundle \EventListener \ConsoleProfilerListener ;
15
16
use Symfony \Bundle \FrameworkBundle \Test \KernelTestCase ;
16
17
use Symfony \Component \Config \Definition \Exception \InvalidConfigurationException ;
17
18
use Symfony \Component \HttpKernel \KernelInterface ;
@@ -20,9 +21,9 @@ class BundleInitializationTest extends KernelTestCase
20
21
{
21
22
public function testInitBundle ()
22
23
{
23
- self :: bootKernel ([ ' config ' => static function ( TestKernel $ kernel ) {
24
- $ kernel -> addTestConfig ( __DIR__ . ' /Resources/config/ default.yaml ');
25
- } ]);
24
+ $ this -> bootWithConfig ([
25
+ ' default.yaml ',
26
+ ]);
26
27
27
28
self ::assertServiceExists ('async_aws.client.s3 ' , S3Client::class);
28
29
self ::assertServiceExists ('async_aws.client.sqs ' , SqsClient::class);
@@ -48,9 +49,9 @@ public function testInitBundle()
48
49
49
50
public function testEmptyConfig ()
50
51
{
51
- self :: bootKernel ([ ' config ' => static function ( TestKernel $ kernel ) {
52
- $ kernel -> addTestConfig ( __DIR__ . ' /Resources/config/ empty.yaml ');
53
- } ]);
52
+ $ this -> bootWithConfig ([
53
+ ' empty.yaml ',
54
+ ]);
54
55
55
56
self ::assertServiceExists ('async_aws.client.s3 ' , S3Client::class);
56
57
self ::assertServiceExists ('async_aws.client.sqs ' , SqsClient::class);
@@ -64,9 +65,9 @@ public function testEmptyConfig()
64
65
65
66
public function testNotRegisterServices ()
66
67
{
67
- self :: bootKernel ([ ' config ' => static function ( TestKernel $ kernel ) {
68
- $ kernel -> addTestConfig ( __DIR__ . ' /Resources/config/ no_services.yaml ');
69
- } ]);
68
+ $ this -> bootWithConfig ([
69
+ ' no_services.yaml ',
70
+ ]);
70
71
71
72
$ container = self ::$ kernel ->getContainer ();
72
73
self ::assertFalse ($ container ->has ('async_aws.client.s3 ' ));
@@ -76,9 +77,9 @@ public function testNotRegisterServices()
76
77
77
78
public function testEmptyClientsKey ()
78
79
{
79
- self :: bootKernel ([ ' config ' => static function ( TestKernel $ kernel ) {
80
- $ kernel -> addTestConfig ( __DIR__ . ' /Resources/config/ empty_clients_key.yaml ');
81
- } ]);
80
+ $ this -> bootWithConfig ([
81
+ ' empty_clients_key.yaml ',
82
+ ]);
82
83
83
84
$ container = self ::$ kernel ->getContainer ();
84
85
self ::assertTrue ($ container ->has ('async_aws.client.s3 ' ));
@@ -88,9 +89,9 @@ public function testEmptyClientsKey()
88
89
89
90
public function testNotRegisterSqs ()
90
91
{
91
- self :: bootKernel ([ ' config ' => static function ( TestKernel $ kernel ) {
92
- $ kernel -> addTestConfig ( __DIR__ . ' /Resources/config/ no_service_sqs.yaml ');
93
- } ]);
92
+ $ this -> bootWithConfig ([
93
+ ' no_service_sqs.yaml ',
94
+ ]);
94
95
95
96
$ container = self ::$ kernel ->getContainer ();
96
97
self ::assertTrue ($ container ->has ('async_aws.client.s3 ' ));
@@ -100,9 +101,9 @@ public function testNotRegisterSqs()
100
101
101
102
public function testConfigOverride ()
102
103
{
103
- self :: bootKernel ([ ' config ' => static function ( TestKernel $ kernel ) {
104
- $ kernel -> addTestConfig ( __DIR__ . ' /Resources/config/ override.yaml ');
105
- } ]);
104
+ $ this -> bootWithConfig ([
105
+ ' override.yaml ',
106
+ ]);
106
107
107
108
$ container = self ::$ kernel ->getContainer ();
108
109
self ::assertTrue ($ container ->has ('async_aws.client.s3 ' ));
@@ -134,17 +135,17 @@ public function testExceptionWhenConfigureServiceNotInstalled()
134
135
135
136
$ this ->expectException (InvalidConfigurationException::class);
136
137
137
- self :: bootKernel ([ ' config ' => static function ( TestKernel $ kernel ) {
138
- $ kernel -> addTestConfig ( __DIR__ . ' /Resources/config/ not_installed_service.yaml ');
139
- } ]);
138
+ $ this -> bootWithConfig ([
139
+ ' not_installed_service.yaml ',
140
+ ]);
140
141
}
141
142
142
143
public function testIssue793 ()
143
144
{
144
- self :: bootKernel ([ ' config ' => static function ( TestKernel $ kernel ) {
145
- $ kernel -> addTestConfig ( __DIR__ . ' /Resources/config/ issue-793/default.yaml ');
146
- $ kernel -> addTestConfig ( __DIR__ . ' /Resources/config/ issue-793/dev.yaml ');
147
- } ]);
145
+ $ this -> bootWithConfig ([
146
+ ' issue-793/default.yaml ',
147
+ ' issue-793/dev.yaml ',
148
+ ]);
148
149
149
150
$ container = self ::$ kernel ->getContainer ();
150
151
$ x = $ container ->get (S3Client::class);
@@ -175,4 +176,18 @@ private function assertServiceExists(string $serviceId, string $instance)
175
176
self ::assertTrue ($ container ->has ($ serviceId ));
176
177
self ::assertInstanceOf ($ instance , $ container ->get ($ serviceId ));
177
178
}
179
+
180
+ private function bootWithConfig (array $ configs ): void
181
+ {
182
+ self ::bootKernel (['config ' => static function (TestKernel $ kernel ) use ($ configs ) {
183
+ foreach ($ configs as $ config ) {
184
+ $ kernel ->addTestConfig (__DIR__ . '/Resources/config/ ' . $ config );
185
+ }
186
+
187
+ // hack to assert the version of the bundle
188
+ if (class_exists (ConsoleProfilerListener::class)) {
189
+ $ kernel ->addTestConfig (__DIR__ . '/Resources/config/default_sf64.yaml ' );
190
+ }
191
+ }]);
192
+ }
178
193
}
0 commit comments