@@ -22,15 +22,9 @@ class SecurityConfigUpdaterTest extends TestCase
2222 /**
2323 * Set to true to enable low level debug logging during tests for
2424 * the YamlSourceManipulator.
25- *
26- * @var bool
2725 */
28- private $ enableYsmLogging = false ;
29-
30- /**
31- * @var Logger|null
32- */
33- private $ ysmLogger = null ;
26+ private bool $ enableYsmLogging = false ;
27+ private ?Logger $ ysmLogger = null ;
3428
3529 /**
3630 * @dataProvider getUserClassTests
@@ -45,9 +39,9 @@ public function testUpdateForUserClass(UserClassConfiguration $userConfig, strin
4539 }
4640
4741 $ updater = new SecurityConfigUpdater ($ this ->ysmLogger );
48- $ source = file_get_contents ( __DIR__ . ' /yaml_fixtures/source/ ' . $ startingSourceFilename );
42+ $ source = $ this -> getYamlSource ( $ startingSourceFilename );
4943 $ actualSource = $ updater ->updateForUserClass ($ source , $ userConfig , $ userClass );
50- $ expectedSource = file_get_contents ( __DIR__ . ' /yaml_fixtures/ expected_user_class/5.3/ ' . $ expectedSourceFilename );
44+ $ expectedSource = $ this -> getExpectedYaml ( ' expected_user_class/5.3 ' , $ expectedSourceFilename );
5145
5246 $ expectedSource = str_replace ('{BCRYPT_OR_AUTO} ' , 'auto ' , $ expectedSource );
5347
@@ -115,9 +109,9 @@ public function testUpdateForAuthenticator(string $firewallName, $entryPoint, st
115109 $ this ->createLogger ();
116110
117111 $ updater = new SecurityConfigUpdater ($ this ->ysmLogger );
118- $ source = file_get_contents ( __DIR__ . ' /yaml_fixtures/source/ ' . $ startingSourceFilename );
112+ $ source = $ this -> getYamlSource ( $ startingSourceFilename );
119113 $ actualSource = $ updater ->updateForAuthenticator ($ source , $ firewallName , $ entryPoint , 'App \\Security \\AppCustomAuthenticator ' , $ logoutSetup );
120- $ expectedSource = file_get_contents ( __DIR__ . ' /yaml_fixtures/ expected_authenticator/ ' . $ expectedSourceFilename );
114+ $ expectedSource = $ this -> getExpectedYaml ( ' expected_authenticator ' , $ expectedSourceFilename );
121115
122116 $ this ->assertSame ($ expectedSource , $ actualSource );
123117 }
@@ -173,6 +167,51 @@ public function getAuthenticatorTests(): \Generator
173167 ];
174168 }
175169
170+ public function testUpdateForFormLogin (): void
171+ {
172+ $ this ->createLogger ();
173+
174+ $ updater = new SecurityConfigUpdater ($ this ->ysmLogger );
175+ $ source = $ this ->getYamlSource ('empty_security.yaml ' );
176+
177+ $ actualSource = $ updater ->updateForFormLogin ($ source , 'main ' , 'a_login_path ' , 'a_check_path ' );
178+
179+ $ this ->assertSame (
180+ $ this ->getExpectedYaml ('expected_form_login ' , 'form_login.yaml ' ),
181+ $ actualSource
182+ );
183+ }
184+
185+ public function testUpdateForJsonLogin (): void
186+ {
187+ $ this ->createLogger ();
188+
189+ $ updater = new SecurityConfigUpdater ($ this ->ysmLogger );
190+ $ source = $ this ->getYamlSource ('empty_security.yaml ' );
191+
192+ $ actualSource = $ updater ->updateForJsonLogin ($ source , 'main ' , 'a_check_path ' );
193+
194+ $ this ->assertSame (
195+ $ this ->getExpectedYaml ('expected_json_login ' , 'json_login.yaml ' ),
196+ $ actualSource
197+ );
198+ }
199+
200+ public function testUpdateForLogout (): void
201+ {
202+ $ this ->createLogger ();
203+
204+ $ updater = new SecurityConfigUpdater ($ this ->ysmLogger );
205+ $ source = $ this ->getYamlSource ('simple_security_with_firewalls.yaml ' );
206+
207+ $ actualSource = $ updater ->updateForLogout ($ source , 'main ' );
208+
209+ $ this ->assertSame (
210+ $ this ->getExpectedYaml ('expected_logout ' , 'logout.yaml ' ),
211+ $ actualSource
212+ );
213+ }
214+
176215 private function createLogger (): void
177216 {
178217 if (!$ this ->enableYsmLogging ) {
@@ -194,4 +233,14 @@ private function createLogger(): void
194233 return $ message ."\n\n" ;
195234 });
196235 }
236+
237+ private function getYamlSource (string $ yamlFileName ): string
238+ {
239+ return file_get_contents (sprintf ('%s/yaml_fixtures/source/%s ' , __DIR__ , $ yamlFileName ));
240+ }
241+
242+ private function getExpectedYaml (string $ subDirectory , string $ yamlFileName ): string
243+ {
244+ return file_get_contents (sprintf ('%s/yaml_fixtures/%s/%s ' , __DIR__ , $ subDirectory , $ yamlFileName ));
245+ }
197246}
0 commit comments