11
11
use AsyncAws \Ssm \SsmClient ;
12
12
use AsyncAws \Symfony \Bundle \AsyncAwsBundle ;
13
13
use 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 ;
16
16
use Symfony \Component \Config \Definition \Exception \InvalidConfigurationException ;
17
+ use Symfony \Component \HttpKernel \KernelInterface ;
17
18
18
- class BundleInitializationTest extends BaseBundleTestCase
19
+ class BundleInitializationTest extends KernelTestCase
19
20
{
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
-
28
21
public function testInitBundle ()
29
22
{
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
+ }] );
33
26
34
27
self ::assertServiceExists ('async_aws.client.s3 ' , S3Client::class);
35
28
self ::assertServiceExists ('async_aws.client.sqs ' , SqsClient::class);
@@ -48,16 +41,16 @@ public function testInitBundle()
48
41
// Test secret
49
42
self ::assertServiceExists (SsmVault::class, SsmVault::class);
50
43
51
- $ container = $ this ->getContainer ();
44
+ $ container = self :: $ kernel ->getContainer ();
52
45
self ::assertFalse ($ container ->has (SqsClient::class . ' $notFound ' ));
53
46
self ::assertFalse ($ container ->has (S3Client::class . ' $foobar ' ));
54
47
}
55
48
56
49
public function testEmptyConfig ()
57
50
{
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
+ }] );
61
54
62
55
self ::assertServiceExists ('async_aws.client.s3 ' , S3Client::class);
63
56
self ::assertServiceExists ('async_aws.client.sqs ' , SqsClient::class);
@@ -71,47 +64,47 @@ public function testEmptyConfig()
71
64
72
65
public function testNotRegisterServices ()
73
66
{
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
+ }] );
77
70
78
- $ container = $ this ->getContainer ();
71
+ $ container = self :: $ kernel ->getContainer ();
79
72
self ::assertFalse ($ container ->has ('async_aws.client.s3 ' ));
80
73
self ::assertFalse ($ container ->has ('async_aws.client.sqs ' ));
81
74
self ::assertFalse ($ container ->has (SqsClient::class));
82
75
}
83
76
84
77
public function testEmptyClientsKey ()
85
78
{
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
+ }] );
89
82
90
- $ container = $ this ->getContainer ();
83
+ $ container = self :: $ kernel ->getContainer ();
91
84
self ::assertTrue ($ container ->has ('async_aws.client.s3 ' ));
92
85
self ::assertTrue ($ container ->has ('async_aws.client.sqs ' ));
93
86
self ::assertTrue ($ container ->has (SqsClient::class));
94
87
}
95
88
96
89
public function testNotRegisterSqs ()
97
90
{
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
+ }] );
101
94
102
- $ container = $ this ->getContainer ();
95
+ $ container = self :: $ kernel ->getContainer ();
103
96
self ::assertTrue ($ container ->has ('async_aws.client.s3 ' ));
104
97
self ::assertFalse ($ container ->has ('async_aws.client.sqs ' ));
105
98
self ::assertFalse ($ container ->has (SqsClient::class));
106
99
}
107
100
108
101
public function testConfigOverride ()
109
102
{
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
+ }] );
113
106
114
- $ container = $ this ->getContainer ();
107
+ $ container = self :: $ kernel ->getContainer ();
115
108
self ::assertTrue ($ container ->has ('async_aws.client.s3 ' ));
116
109
self ::assertTrue ($ container ->has ('async_aws.client.ses ' ));
117
110
self ::assertTrue ($ container ->has ('async_aws.client.sqs ' ));
@@ -139,33 +132,46 @@ public function testExceptionWhenConfigureServiceNotInstalled()
139
132
self ::markTestSkipped ('SNSClient is installed.. ' );
140
133
}
141
134
142
- $ kernel = $ this ->createKernel ();
143
- $ kernel ->addConfigFile (__DIR__ . '/Resources/config/not_installed_service.yaml ' );
144
-
145
135
$ 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
+ }]);
147
140
}
148
141
149
142
public function testIssue793 ()
150
143
{
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
+ }]);
154
148
155
- $ this ->bootKernel ();
156
- $ container = $ this ->getContainer ();
149
+ $ container = self ::$ kernel ->getContainer ();
157
150
$ x = $ container ->get (S3Client::class);
158
151
self ::assertSame ('./docker/dynamodb/credentials ' , $ x ->getConfiguration ()->get ('sharedCredentialsFile ' ));
159
152
}
160
153
161
- protected function getBundleClass (): string
154
+ protected static function getKernelClass (): string
162
155
{
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 ;
164
170
}
165
171
166
172
private function assertServiceExists (string $ serviceId , string $ instance )
167
173
{
168
- $ container = $ this ->getContainer ();
174
+ $ container = self :: $ kernel ->getContainer ();
169
175
self ::assertTrue ($ container ->has ($ serviceId ));
170
176
self ::assertInstanceOf ($ instance , $ container ->get ($ serviceId ));
171
177
}
0 commit comments