1515use Symfony \Bundle \MakerBundle \Test \MakerTestCase ;
1616use Symfony \Bundle \MakerBundle \Test \MakerTestRunner ;
1717
18+ /**
19+ * Passing namespaces interactively can be done like "App\Controller\MyController"
20+ * but passing as a command argument, you must add a double set of slashes. e.g.
21+ * "App\\\\Controller\\\\MyController".
22+ */
1823class MakeControllerTest extends MakerTestCase
1924{
2025 protected function getMakerClass (): string
@@ -37,6 +42,18 @@ public function getTestDetails(): \Generator
3742 }),
3843 ];
3944
45+ yield 'it_generates_a_controller__no_input ' => [$ this ->createMakerTest ()
46+ ->run (function (MakerTestRunner $ runner ) {
47+ $ output = $ runner ->runMaker ([], 'FooBar ' );
48+
49+ $ this ->assertContainsCount ('created: ' , $ output , 1 );
50+
51+ $ this ->assertFileExists ($ runner ->getPath ('src/Controller/FooBarController.php ' ));
52+
53+ $ this ->runControllerTest ($ runner , 'it_generates_a_controller.php ' );
54+ }),
55+ ];
56+
4057 yield 'it_generates_a_controller_with_twig ' => [$ this ->createMakerTest ()
4158 ->addExtraDependencies ('twig ' )
4259 ->run (function (MakerTestRunner $ runner ) {
@@ -52,6 +69,18 @@ public function getTestDetails(): \Generator
5269 }),
5370 ];
5471
72+ yield 'it_generates_a_controller_with_twig__no_input ' => [$ this ->createMakerTest ()
73+ ->addExtraDependencies ('twig ' )
74+ ->run (function (MakerTestRunner $ runner ) {
75+ $ runner ->runMaker ([], 'FooTwig ' );
76+
77+ $ this ->assertFileExists ($ runner ->getPath ('src/Controller/FooTwigController.php ' ));
78+ $ this ->assertFileExists ($ runner ->getPath ('templates/foo_twig/index.html.twig ' ));
79+
80+ $ this ->runControllerTest ($ runner , 'it_generates_a_controller_with_twig.php ' );
81+ }),
82+ ];
83+
5584 yield 'it_generates_a_controller_with_twig_no_base_template ' => [$ this ->createMakerTest ()
5685 ->addExtraDependencies ('twig ' )
5786 ->run (function (MakerTestRunner $ runner ) {
@@ -98,6 +127,19 @@ public function getTestDetails(): \Generator
98127 }),
99128 ];
100129
130+ yield 'it_generates_a_controller_in_sub_namespace__no_input ' => [$ this ->createMakerTest ()
131+ ->skipTest (
132+ message: 'Test Skipped - MAKER_TEST_WINDOWS is true. ' ,
133+ skipped: getenv ('MAKER_TEST_WINDOWS ' )
134+ )
135+ ->run (function (MakerTestRunner $ runner ) {
136+ $ output = $ runner ->runMaker ([], 'Admin \\\\FooBar ' );
137+
138+ $ this ->assertFileExists ($ runner ->getPath ('src/Controller/Admin/FooBarController.php ' ));
139+ $ this ->assertStringContainsString ('src/Controller/Admin/FooBarController.php ' , $ output );
140+ }),
141+ ];
142+
101143 yield 'it_generates_a_controller_in_sub_namespace_with_template ' => [$ this ->createMakerTest ()
102144 ->addExtraDependencies ('twig ' )
103145 ->run (function (MakerTestRunner $ runner ) {
@@ -129,6 +171,22 @@ public function getTestDetails(): \Generator
129171 }),
130172 ];
131173
174+ yield 'it_generates_a_controller_with_full_custom_namespace__no_input ' => [$ this ->createMakerTest ()
175+ ->skipTest (
176+ message: 'Test Skipped - MAKER_TEST_WINDOWS is true. ' ,
177+ skipped: getenv ('MAKER_TEST_WINDOWS ' )
178+ )
179+ ->addExtraDependencies ('twig ' )
180+ ->run (function (MakerTestRunner $ runner ) {
181+ $ output = $ runner ->runMaker ([], '\\\\App \\\\Foo \\\\Bar \\\\CoolController ' );
182+
183+ self ::assertFileExists ($ runner ->getPath ('templates/foo/bar/cool/index.html.twig ' ));
184+
185+ $ this ->assertStringContainsString ('src/Foo/Bar/CoolController.php ' , $ output );
186+ $ this ->assertStringContainsString ('templates/foo/bar/cool/index.html.twig ' , $ output );
187+ }),
188+ ];
189+
132190 yield 'it_generates_a_controller_with_invoke ' => [$ this ->createMakerTest ()
133191 ->addExtraDependencies ('twig ' )
134192 ->run (function (MakerTestRunner $ runner ) {
0 commit comments