Skip to content

Commit d0cfae6

Browse files
authored
minor #1602 [make:controller] add tests for command argument names
* [make:controller] add failing tests for command argument names * skip tests on windows
1 parent 2067b29 commit d0cfae6

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

.github/workflows/ci-windows.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ env:
1313
SYMFONY_PHPUNIT_DIR: "$HOME/symfony-bridge/.phpunit"
1414
MAKER_SKIP_MERCURE_TEST: 1
1515
MAKER_SKIP_PANTHER_TEST: 1
16+
MAKER_TEST_WINDOWS: 1
1617
MAKER_DISABLE_FILE_LINKS: 1
1718
MAKER_ALLOW_DEV_DEPS_IN_APP: 0
1819
SYMFONY_VERSION: '7.0.x-dev'

phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<env name="SYMFONY_PHPUNIT_VERSION" value="9.6" />
2020
<env name="MAKER_SKIP_MERCURE_TEST" value="false"/>
2121
<env name="MAKER_SKIP_PANTHER_TEST" value="false" />
22+
<env name="MAKER_TEST_WINDOWS" value="false" />
2223
<!-- Overrides process timeout when step debugging -->
2324
<!-- <env name="MAKER_PROCESS_TIMEOUT" value="null" /> -->
2425
<!-- Dump the CLI output for a test runner process immediately after running a test -->

tests/Maker/MakeControllerTest.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
use Symfony\Bundle\MakerBundle\Test\MakerTestCase;
1616
use 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+
*/
1823
class 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

Comments
 (0)