1313
1414use Symfony \Bundle \FrameworkBundle \Command \AssetsInstallCommand ;
1515use Symfony \Bundle \FrameworkBundle \Console \Application ;
16- use Symfony \Bundle \FrameworkBundle \Tests \Functional \Bundle \ModernBundle \src \Entity \Person ;
1716use Symfony \Component \Console \Tester \CommandTester ;
1817use Symfony \Component \Filesystem \Filesystem ;
1918
2019class BundlePathsTest extends AbstractWebTestCase
2120{
22- public function testDefaultBundlePaths ()
21+ public function testLegacyBundleDir ()
2322 {
2423 static ::bootKernel (['test_case ' => 'BundlePaths ' ]);
2524 $ bundlesMetadata = static ::$ container ->getParameter ('kernel.bundles_metadata ' );
26- $ bundlePath = $ bundlesMetadata ['FrameworkBundle ' ]['path ' ];
25+ $ bundlePath = $ bundlesMetadata ['LegacyBundle ' ]['path ' ];
2726
28- $ this ->assertSame ($ bundlePath , $ bundlesMetadata ['FrameworkBundle ' ]['dir ' ]);
27+ $ this ->assertSame ($ bundlePath , $ bundlesMetadata ['LegacyBundle ' ]['dir ' ]);
2928 }
3029
31- public function testCustomBundlePaths ()
30+ public function testBundleDir ()
3231 {
3332 static ::bootKernel (['test_case ' => 'BundlePaths ' ]);
3433 $ bundlesMetadata = static ::$ container ->getParameter ('kernel.bundles_metadata ' );
@@ -37,56 +36,95 @@ public function testCustomBundlePaths()
3736 $ this ->assertSame (\dirname ($ bundlePath ), $ bundlesMetadata ['ModernBundle ' ]['dir ' ]);
3837 }
3938
40- public function testCustomBundlePublicPath ()
39+ /**
40+ * @dataProvider getPublicDirProvider
41+ */
42+ public function testBundlePublicDir (string $ expectedFilename )
4143 {
4244 $ kernel = static ::bootKernel (['test_case ' => 'BundlePaths ' ]);
43- $ projectDir = sys_get_temp_dir ().'/ ' .uniqid ('sf_modern ' , true );
45+ $ projectDir = sys_get_temp_dir ().'/ ' .uniqid ('sf_project ' , true );
4446
4547 $ fs = new Filesystem ();
4648 $ fs ->mkdir ($ projectDir .'/public ' );
4749 $ command = (new Application ($ kernel ))->add (new AssetsInstallCommand ($ fs , $ projectDir ));
4850 $ commandTester = new CommandTester ($ command );
4951
5052 $ this ->assertSame (0 , $ commandTester ->execute (['target ' => $ projectDir .'/public ' ]));
51- $ this ->assertFileExists ($ projectDir .' /public/bundles/modern/modern.css ' );
53+ $ this ->assertFileExists ($ projectDir .$ expectedFilename );
5254
5355 $ fs ->remove ($ projectDir );
5456 }
5557
56- public function testCustomBundleTwigTemplatesPath ()
58+ /**
59+ * @dataProvider getTemplatesDirProvider
60+ */
61+ public function testBundleTwigTemplatesDir (string $ bundleName , string $ twigNamespace , string $ templateDir , string $ twigTemplate )
5762 {
5863 static ::bootKernel (['test_case ' => 'BundlePaths ' ]);
5964 $ bundlesMetadata = static ::$ container ->getParameter ('kernel.bundles_metadata ' );
60- $ bundleDir = $ bundlesMetadata [' ModernBundle ' ]['dir ' ];
65+ $ bundleDir = $ bundlesMetadata [$ bundleName ]['dir ' ];
6166
6267 $ twig = static ::$ container ->get ('twig ' );
63- $ this ->assertSame ([$ bundleDir .' /templates ' ], $ twig ->getLoader ()->getPaths (' Modern ' ));
64- $ this ->assertSame ("OK \n" , $ twig ->render (' @Modern/index.html.twig ' ));
68+ $ this ->assertSame ([$ bundleDir .$ templateDir ], $ twig ->getLoader ()->getPaths ($ twigNamespace ));
69+ $ this ->assertSame ("OK \n" , $ twig ->render ($ twigTemplate ));
6570 }
6671
67- public function testCustomBundleTranslationsPath ()
72+ /**
73+ * @dataProvider getTranslationsDirProvider
74+ */
75+ public function testBundleTranslationsDir (string $ translationDomain )
6876 {
6977 static ::bootKernel (['test_case ' => 'BundlePaths ' ]);
7078
7179 $ translator = static ::$ container ->get ('translator ' );
72- $ this ->assertSame ('OK ' , $ translator ->trans ('ok_label ' , [], ' modern ' ));
80+ $ this ->assertSame ('OK ' , $ translator ->trans ('ok_label ' , [], $ translationDomain ));
7381 }
7482
75- public function testCustomBundleValidationConfigPath ()
83+ /**
84+ * @dataProvider getConfigDirProvider
85+ */
86+ public function testBundleValidationConfigDir (string $ personClass )
7687 {
7788 static ::bootKernel (['test_case ' => 'BundlePaths ' ]);
7889
7990 $ validator = static ::$ container ->get ('validator ' );
80- $ this ->assertTrue ($ validator ->hasMetadataFor (Person::class ));
81- $ this ->assertCount (1 , $ constraintViolationList = $ validator ->validate (new Person ('john ' , 5 )));
91+ $ this ->assertTrue ($ validator ->hasMetadataFor ($ personClass ));
92+ $ this ->assertCount (1 , $ constraintViolationList = $ validator ->validate (new $ personClass ('john ' , 5 )));
8293 $ this ->assertSame ('This value should be greater than 18. ' , $ constraintViolationList ->get (0 )->getMessage ());
8394 }
8495
85- public function testCustomBundleSerializationConfigPath ()
96+ /**
97+ * @dataProvider getConfigDirProvider
98+ */
99+ public function testBundleSerializationConfigDir (string $ personClass )
86100 {
87101 static ::bootKernel (['test_case ' => 'BundlePaths ' ]);
88102
89103 $ serializer = static ::$ container ->get ('serializer ' );
90- $ this ->assertEquals (['full_name ' => 'john ' , 'age ' => 5 ], $ serializer ->normalize (new Person ('john ' , 5 ), 'json ' ));
104+ $ this ->assertEquals (['full_name ' => 'john ' , 'age ' => 5 ], $ serializer ->normalize (new $ personClass ('john ' , 5 ), 'json ' ));
105+ }
106+
107+ public function getPublicDirProvider ()
108+ {
109+ yield ['/public/bundles/modern/modern.css ' ];
110+ yield ['/public/bundles/legacy/legacy.css ' ];
111+ }
112+
113+ public function getTemplatesDirProvider ()
114+ {
115+ yield ['ModernBundle ' , 'Modern ' , '/templates ' , '@Modern/index.html.twig ' ];
116+ yield ['LegacyBundle ' , 'Legacy ' , '/Resources/views ' , '@Legacy/index.html.twig ' ];
117+ }
118+
119+ public function getTranslationsDirProvider ()
120+ {
121+ yield ['modern ' ];
122+ yield ['legacy ' ];
123+ }
124+
125+ public function getConfigDirProvider ()
126+ {
127+ yield [\Symfony \Bundle \FrameworkBundle \Tests \Functional \Bundle \ModernBundle \src \Entity \Person::class];
128+ yield [\Symfony \Bundle \FrameworkBundle \Tests \Functional \Bundle \LegacyBundle \Entity \Person::class];
91129 }
92130}
0 commit comments