1212use AsyncAws \Symfony \Bundle \AsyncAwsBundle ;
1313use AsyncAws \Symfony \Bundle \Secrets \SsmVault ;
1414use Nyholm \BundleTest \TestKernel ;
15+ use Symfony \Bundle \FrameworkBundle \EventListener \ConsoleProfilerListener ;
1516use Symfony \Bundle \FrameworkBundle \Test \KernelTestCase ;
1617use Symfony \Component \Config \Definition \Exception \InvalidConfigurationException ;
1718use Symfony \Component \HttpKernel \KernelInterface ;
@@ -20,9 +21,9 @@ class BundleInitializationTest extends KernelTestCase
2021{
2122 public function testInitBundle ()
2223 {
23- self :: bootKernel ([ ' config ' => static function ( TestKernel $ kernel ) {
24- $ kernel -> addTestConfig ( __DIR__ . ' /Resources/config/ default.yaml ');
25- } ]);
24+ $ this -> bootWithConfig ([
25+ ' default.yaml ',
26+ ]);
2627
2728 self ::assertServiceExists ('async_aws.client.s3 ' , S3Client::class);
2829 self ::assertServiceExists ('async_aws.client.sqs ' , SqsClient::class);
@@ -48,9 +49,9 @@ public function testInitBundle()
4849
4950 public function testEmptyConfig ()
5051 {
51- self :: bootKernel ([ ' config ' => static function ( TestKernel $ kernel ) {
52- $ kernel -> addTestConfig ( __DIR__ . ' /Resources/config/ empty.yaml ');
53- } ]);
52+ $ this -> bootWithConfig ([
53+ ' empty.yaml ',
54+ ]);
5455
5556 self ::assertServiceExists ('async_aws.client.s3 ' , S3Client::class);
5657 self ::assertServiceExists ('async_aws.client.sqs ' , SqsClient::class);
@@ -64,9 +65,9 @@ public function testEmptyConfig()
6465
6566 public function testNotRegisterServices ()
6667 {
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+ ]);
7071
7172 $ container = self ::$ kernel ->getContainer ();
7273 self ::assertFalse ($ container ->has ('async_aws.client.s3 ' ));
@@ -76,9 +77,9 @@ public function testNotRegisterServices()
7677
7778 public function testEmptyClientsKey ()
7879 {
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+ ]);
8283
8384 $ container = self ::$ kernel ->getContainer ();
8485 self ::assertTrue ($ container ->has ('async_aws.client.s3 ' ));
@@ -88,9 +89,9 @@ public function testEmptyClientsKey()
8889
8990 public function testNotRegisterSqs ()
9091 {
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+ ]);
9495
9596 $ container = self ::$ kernel ->getContainer ();
9697 self ::assertTrue ($ container ->has ('async_aws.client.s3 ' ));
@@ -100,9 +101,9 @@ public function testNotRegisterSqs()
100101
101102 public function testConfigOverride ()
102103 {
103- self :: bootKernel ([ ' config ' => static function ( TestKernel $ kernel ) {
104- $ kernel -> addTestConfig ( __DIR__ . ' /Resources/config/ override.yaml ');
105- } ]);
104+ $ this -> bootWithConfig ([
105+ ' override.yaml ',
106+ ]);
106107
107108 $ container = self ::$ kernel ->getContainer ();
108109 self ::assertTrue ($ container ->has ('async_aws.client.s3 ' ));
@@ -134,17 +135,17 @@ public function testExceptionWhenConfigureServiceNotInstalled()
134135
135136 $ this ->expectException (InvalidConfigurationException::class);
136137
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+ ]);
140141 }
141142
142143 public function testIssue793 ()
143144 {
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+ ]);
148149
149150 $ container = self ::$ kernel ->getContainer ();
150151 $ x = $ container ->get (S3Client::class);
@@ -175,4 +176,18 @@ private function assertServiceExists(string $serviceId, string $instance)
175176 self ::assertTrue ($ container ->has ($ serviceId ));
176177 self ::assertInstanceOf ($ instance , $ container ->get ($ serviceId ));
177178 }
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+ }
178193}
0 commit comments