From 579007f2264b7a61f3eca47af17b7040a1195973 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Thu, 26 Sep 2024 11:29:00 -0400 Subject: [PATCH 1/2] [make:controller] add failing tests for command argument names --- tests/Maker/MakeControllerTest.php | 50 ++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tests/Maker/MakeControllerTest.php b/tests/Maker/MakeControllerTest.php index 026d390c5..fcb28d094 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,15 @@ public function getTestDetails(): \Generator }), ]; + yield 'it_generates_a_controller_in_sub_namespace__no_input' => [$this->createMakerTest() + ->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 +167,18 @@ public function getTestDetails(): \Generator }), ]; + yield 'it_generates_a_controller_with_full_custom_namespace__no_input' => [$this->createMakerTest() + ->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) { From 5f5ea99ff64f8fe1aca5e0a745d15e8188612e41 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Thu, 26 Sep 2024 13:00:43 -0400 Subject: [PATCH 2/2] skip tests on windows --- .github/workflows/ci-windows.yaml | 1 + phpunit.xml.dist | 1 + tests/Maker/MakeControllerTest.php | 8 ++++++++ 3 files changed, 10 insertions(+) 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 fcb28d094..bce5e787f 100644 --- a/tests/Maker/MakeControllerTest.php +++ b/tests/Maker/MakeControllerTest.php @@ -128,6 +128,10 @@ 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'); @@ -168,6 +172,10 @@ 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');