diff --git a/.github/workflows/ci-windows.yaml b/.github/workflows/ci-windows.yaml index e35abb645..e99e6c559 100644 --- a/.github/workflows/ci-windows.yaml +++ b/.github/workflows/ci-windows.yaml @@ -13,6 +13,7 @@ env: SYMFONY_PHPUNIT_DIR: "$HOME/symfony-bridge/.phpunit" MAKER_SKIP_MERCURE_TEST: 1 MAKER_SKIP_PANTHER_TEST: 1 + MAKER_TEST_WINDOWS: 1 MAKER_DISABLE_FILE_LINKS: 1 MAKER_ALLOW_DEV_DEPS_IN_APP: 0 SYMFONY_VERSION: '7.0.x-dev' diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 979591eb4..8cf19ce2a 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -19,6 +19,7 @@ + diff --git a/tests/Maker/MakeControllerTest.php b/tests/Maker/MakeControllerTest.php index 026d390c5..bce5e787f 100644 --- a/tests/Maker/MakeControllerTest.php +++ b/tests/Maker/MakeControllerTest.php @@ -15,6 +15,11 @@ use Symfony\Bundle\MakerBundle\Test\MakerTestCase; use Symfony\Bundle\MakerBundle\Test\MakerTestRunner; +/** + * Passing namespaces interactively can be done like "App\Controller\MyController" + * but passing as a command argument, you must add a double set of slashes. e.g. + * "App\\\\Controller\\\\MyController". + */ class MakeControllerTest extends MakerTestCase { protected function getMakerClass(): string @@ -37,6 +42,18 @@ public function getTestDetails(): \Generator }), ]; + yield 'it_generates_a_controller__no_input' => [$this->createMakerTest() + ->run(function (MakerTestRunner $runner) { + $output = $runner->runMaker([], 'FooBar'); + + $this->assertContainsCount('created: ', $output, 1); + + $this->assertFileExists($runner->getPath('src/Controller/FooBarController.php')); + + $this->runControllerTest($runner, 'it_generates_a_controller.php'); + }), + ]; + yield 'it_generates_a_controller_with_twig' => [$this->createMakerTest() ->addExtraDependencies('twig') ->run(function (MakerTestRunner $runner) { @@ -52,6 +69,18 @@ public function getTestDetails(): \Generator }), ]; + yield 'it_generates_a_controller_with_twig__no_input' => [$this->createMakerTest() + ->addExtraDependencies('twig') + ->run(function (MakerTestRunner $runner) { + $runner->runMaker([], 'FooTwig'); + + $this->assertFileExists($runner->getPath('src/Controller/FooTwigController.php')); + $this->assertFileExists($runner->getPath('templates/foo_twig/index.html.twig')); + + $this->runControllerTest($runner, 'it_generates_a_controller_with_twig.php'); + }), + ]; + yield 'it_generates_a_controller_with_twig_no_base_template' => [$this->createMakerTest() ->addExtraDependencies('twig') ->run(function (MakerTestRunner $runner) { @@ -98,6 +127,19 @@ public function getTestDetails(): \Generator }), ]; + yield 'it_generates_a_controller_in_sub_namespace__no_input' => [$this->createMakerTest() + ->skipTest( + message: 'Test Skipped - MAKER_TEST_WINDOWS is true.', + skipped: getenv('MAKER_TEST_WINDOWS') + ) + ->run(function (MakerTestRunner $runner) { + $output = $runner->runMaker([], 'Admin\\\\FooBar'); + + $this->assertFileExists($runner->getPath('src/Controller/Admin/FooBarController.php')); + $this->assertStringContainsString('src/Controller/Admin/FooBarController.php', $output); + }), + ]; + yield 'it_generates_a_controller_in_sub_namespace_with_template' => [$this->createMakerTest() ->addExtraDependencies('twig') ->run(function (MakerTestRunner $runner) { @@ -129,6 +171,22 @@ public function getTestDetails(): \Generator }), ]; + yield 'it_generates_a_controller_with_full_custom_namespace__no_input' => [$this->createMakerTest() + ->skipTest( + message: 'Test Skipped - MAKER_TEST_WINDOWS is true.', + skipped: getenv('MAKER_TEST_WINDOWS') + ) + ->addExtraDependencies('twig') + ->run(function (MakerTestRunner $runner) { + $output = $runner->runMaker([], '\\\\App\\\\Foo\\\\Bar\\\\CoolController'); + + self::assertFileExists($runner->getPath('templates/foo/bar/cool/index.html.twig')); + + $this->assertStringContainsString('src/Foo/Bar/CoolController.php', $output); + $this->assertStringContainsString('templates/foo/bar/cool/index.html.twig', $output); + }), + ]; + yield 'it_generates_a_controller_with_invoke' => [$this->createMakerTest() ->addExtraDependencies('twig') ->run(function (MakerTestRunner $runner) {