Skip to content

Commit

Permalink
minor #1602 [make:controller] add tests for command argument names
Browse files Browse the repository at this point in the history
* [make:controller] add failing tests for command argument names

* skip tests on windows
  • Loading branch information
jrushlow authored Sep 26, 2024
1 parent 2067b29 commit d0cfae6
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci-windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<env name="SYMFONY_PHPUNIT_VERSION" value="9.6" />
<env name="MAKER_SKIP_MERCURE_TEST" value="false"/>
<env name="MAKER_SKIP_PANTHER_TEST" value="false" />
<env name="MAKER_TEST_WINDOWS" value="false" />
<!-- Overrides process timeout when step debugging -->
<!-- <env name="MAKER_PROCESS_TIMEOUT" value="null" /> -->
<!-- Dump the CLI output for a test runner process immediately after running a test -->
Expand Down
58 changes: 58 additions & 0 deletions tests/Maker/MakeControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit d0cfae6

Please sign in to comment.