1111use AsyncAws \Ssm \SsmClient ;
1212use AsyncAws \Symfony \Bundle \AsyncAwsBundle ;
1313use AsyncAws \Symfony \Bundle \Secrets \SsmVault ;
14- use Nyholm \BundleTest \BaseBundleTestCase ;
15- use Nyholm \ BundleTest \ CompilerPass \ PublicServicePass ;
14+ use Nyholm \BundleTest \TestKernel ;
15+ use Symfony \ Bundle \ FrameworkBundle \ Test \ KernelTestCase ;
1616use Symfony \Component \Config \Definition \Exception \InvalidConfigurationException ;
17+ use Symfony \Component \HttpKernel \KernelInterface ;
1718
18- class BundleInitializationTest extends BaseBundleTestCase
19+ class BundleInitializationTest extends KernelTestCase
1920{
20- protected function setUp (): void
21- {
22- parent ::setUp ();
23-
24- $ this ->addCompilerPass (new PublicServicePass ('|async_aws.*| ' ));
25- $ this ->addCompilerPass (new PublicServicePass ('|AsyncAws\.*| ' ));
26- }
27-
2821 public function testInitBundle ()
2922 {
30- $ kernel = $ this -> createKernel ();
31- $ kernel ->addConfigFile (__DIR__ . '/Resources/config/default.yaml ' );
32- $ this -> bootKernel ( );
23+ self :: bootKernel ([ ' config ' => static function ( TestKernel $ kernel ) {
24+ $ kernel ->addTestConfig (__DIR__ . '/Resources/config/default.yaml ' );
25+ }] );
3326
3427 self ::assertServiceExists ('async_aws.client.s3 ' , S3Client::class);
3528 self ::assertServiceExists ('async_aws.client.sqs ' , SqsClient::class);
@@ -48,16 +41,16 @@ public function testInitBundle()
4841 // Test secret
4942 self ::assertServiceExists (SsmVault::class, SsmVault::class);
5043
51- $ container = $ this ->getContainer ();
44+ $ container = self :: $ kernel ->getContainer ();
5245 self ::assertFalse ($ container ->has (SqsClient::class . ' $notFound ' ));
5346 self ::assertFalse ($ container ->has (S3Client::class . ' $foobar ' ));
5447 }
5548
5649 public function testEmptyConfig ()
5750 {
58- $ kernel = $ this -> createKernel ();
59- $ kernel ->addConfigFile (__DIR__ . '/Resources/config/empty.yaml ' );
60- $ this -> bootKernel ( );
51+ self :: bootKernel ([ ' config ' => static function ( TestKernel $ kernel ) {
52+ $ kernel ->addTestConfig (__DIR__ . '/Resources/config/empty.yaml ' );
53+ }] );
6154
6255 self ::assertServiceExists ('async_aws.client.s3 ' , S3Client::class);
6356 self ::assertServiceExists ('async_aws.client.sqs ' , SqsClient::class);
@@ -71,47 +64,47 @@ public function testEmptyConfig()
7164
7265 public function testNotRegisterServices ()
7366 {
74- $ kernel = $ this -> createKernel ();
75- $ kernel ->addConfigFile (__DIR__ . '/Resources/config/no_services.yaml ' );
76- $ this -> bootKernel ( );
67+ self :: bootKernel ([ ' config ' => static function ( TestKernel $ kernel ) {
68+ $ kernel ->addTestConfig (__DIR__ . '/Resources/config/no_services.yaml ' );
69+ }] );
7770
78- $ container = $ this ->getContainer ();
71+ $ container = self :: $ kernel ->getContainer ();
7972 self ::assertFalse ($ container ->has ('async_aws.client.s3 ' ));
8073 self ::assertFalse ($ container ->has ('async_aws.client.sqs ' ));
8174 self ::assertFalse ($ container ->has (SqsClient::class));
8275 }
8376
8477 public function testEmptyClientsKey ()
8578 {
86- $ kernel = $ this -> createKernel ();
87- $ kernel ->addConfigFile (__DIR__ . '/Resources/config/empty_clients_key.yaml ' );
88- $ this -> bootKernel ( );
79+ self :: bootKernel ([ ' config ' => static function ( TestKernel $ kernel ) {
80+ $ kernel ->addTestConfig (__DIR__ . '/Resources/config/empty_clients_key.yaml ' );
81+ }] );
8982
90- $ container = $ this ->getContainer ();
83+ $ container = self :: $ kernel ->getContainer ();
9184 self ::assertTrue ($ container ->has ('async_aws.client.s3 ' ));
9285 self ::assertTrue ($ container ->has ('async_aws.client.sqs ' ));
9386 self ::assertTrue ($ container ->has (SqsClient::class));
9487 }
9588
9689 public function testNotRegisterSqs ()
9790 {
98- $ kernel = $ this -> createKernel ();
99- $ kernel ->addConfigFile (__DIR__ . '/Resources/config/no_service_sqs.yaml ' );
100- $ this -> bootKernel ( );
91+ self :: bootKernel ([ ' config ' => static function ( TestKernel $ kernel ) {
92+ $ kernel ->addTestConfig (__DIR__ . '/Resources/config/no_service_sqs.yaml ' );
93+ }] );
10194
102- $ container = $ this ->getContainer ();
95+ $ container = self :: $ kernel ->getContainer ();
10396 self ::assertTrue ($ container ->has ('async_aws.client.s3 ' ));
10497 self ::assertFalse ($ container ->has ('async_aws.client.sqs ' ));
10598 self ::assertFalse ($ container ->has (SqsClient::class));
10699 }
107100
108101 public function testConfigOverride ()
109102 {
110- $ kernel = $ this -> createKernel ();
111- $ kernel ->addConfigFile (__DIR__ . '/Resources/config/override.yaml ' );
112- $ this -> bootKernel ( );
103+ self :: bootKernel ([ ' config ' => static function ( TestKernel $ kernel ) {
104+ $ kernel ->addTestConfig (__DIR__ . '/Resources/config/override.yaml ' );
105+ }] );
113106
114- $ container = $ this ->getContainer ();
107+ $ container = self :: $ kernel ->getContainer ();
115108 self ::assertTrue ($ container ->has ('async_aws.client.s3 ' ));
116109 self ::assertTrue ($ container ->has ('async_aws.client.ses ' ));
117110 self ::assertTrue ($ container ->has ('async_aws.client.sqs ' ));
@@ -139,33 +132,46 @@ public function testExceptionWhenConfigureServiceNotInstalled()
139132 self ::markTestSkipped ('SNSClient is installed.. ' );
140133 }
141134
142- $ kernel = $ this ->createKernel ();
143- $ kernel ->addConfigFile (__DIR__ . '/Resources/config/not_installed_service.yaml ' );
144-
145135 $ this ->expectException (InvalidConfigurationException::class);
146- $ this ->bootKernel ();
136+
137+ self ::bootKernel (['config ' => static function (TestKernel $ kernel ) {
138+ $ kernel ->addTestConfig (__DIR__ . '/Resources/config/not_installed_service.yaml ' );
139+ }]);
147140 }
148141
149142 public function testIssue793 ()
150143 {
151- $ kernel = $ this ->createKernel ();
152- $ kernel ->addConfigFile (__DIR__ . '/Resources/config/issue-793/default.yaml ' );
153- $ kernel ->addConfigFile (__DIR__ . '/Resources/config/issue-793/dev.yaml ' );
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+ }]);
154148
155- $ this ->bootKernel ();
156- $ container = $ this ->getContainer ();
149+ $ container = self ::$ kernel ->getContainer ();
157150 $ x = $ container ->get (S3Client::class);
158151 self ::assertSame ('./docker/dynamodb/credentials ' , $ x ->getConfiguration ()->get ('sharedCredentialsFile ' ));
159152 }
160153
161- protected function getBundleClass (): string
154+ protected static function getKernelClass (): string
162155 {
163- return AsyncAwsBundle::class;
156+ return TestKernel::class;
157+ }
158+
159+ protected static function createKernel (array $ options = []): KernelInterface
160+ {
161+ $ kernel = parent ::createKernel ($ options );
162+ \assert ($ kernel instanceof TestKernel);
163+
164+ $ kernel ->addTestBundle (AsyncAwsBundle::class);
165+ $ kernel ->addTestCompilerPass (new PublicServicePass ('|async_aws.*| ' ));
166+ $ kernel ->addTestCompilerPass (new PublicServicePass ('|AsyncAws\.*| ' ));
167+ $ kernel ->handleOptions ($ options );
168+
169+ return $ kernel ;
164170 }
165171
166172 private function assertServiceExists (string $ serviceId , string $ instance )
167173 {
168- $ container = $ this ->getContainer ();
174+ $ container = self :: $ kernel ->getContainer ();
169175 self ::assertTrue ($ container ->has ($ serviceId ));
170176 self ::assertInstanceOf ($ instance , $ container ->get ($ serviceId ));
171177 }
0 commit comments