15
15
use Symfony \Bundle \MakerBundle \Test \MakerTestCase ;
16
16
use Symfony \Bundle \MakerBundle \Test \MakerTestRunner ;
17
17
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
+ */
18
23
class MakeControllerTest extends MakerTestCase
19
24
{
20
25
protected function getMakerClass (): string
@@ -37,6 +42,18 @@ public function getTestDetails(): \Generator
37
42
}),
38
43
];
39
44
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
+
40
57
yield 'it_generates_a_controller_with_twig ' => [$ this ->createMakerTest ()
41
58
->addExtraDependencies ('twig ' )
42
59
->run (function (MakerTestRunner $ runner ) {
@@ -52,6 +69,18 @@ public function getTestDetails(): \Generator
52
69
}),
53
70
];
54
71
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
+
55
84
yield 'it_generates_a_controller_with_twig_no_base_template ' => [$ this ->createMakerTest ()
56
85
->addExtraDependencies ('twig ' )
57
86
->run (function (MakerTestRunner $ runner ) {
@@ -98,6 +127,19 @@ public function getTestDetails(): \Generator
98
127
}),
99
128
];
100
129
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
+
101
143
yield 'it_generates_a_controller_in_sub_namespace_with_template ' => [$ this ->createMakerTest ()
102
144
->addExtraDependencies ('twig ' )
103
145
->run (function (MakerTestRunner $ runner ) {
@@ -129,6 +171,22 @@ public function getTestDetails(): \Generator
129
171
}),
130
172
];
131
173
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
+
132
190
yield 'it_generates_a_controller_with_invoke ' => [$ this ->createMakerTest ()
133
191
->addExtraDependencies ('twig ' )
134
192
->run (function (MakerTestRunner $ runner ) {
0 commit comments