Skip to content

Commit

Permalink
minor #1565 [make:controller] add tests to confirm twig templates gen…
Browse files Browse the repository at this point in the history
…erated
  • Loading branch information
jrushlow authored May 20, 2024
1 parent 9060cd1 commit 9c85a83
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Resources/help/MakeController.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ The <info>%command.name%</info> command generates a new controller class.

If the argument is missing, the command will ask for the controller class name interactively.

If you have the <info>symfony/twig-bundle</info> installed, a Twig template will also be
generated for the controller.

<info>composer require symfony/twig-bundle</info>

You can also generate the controller alone, without template with this option:

<info>php %command.full_name% --no-template</info>
18 changes: 18 additions & 0 deletions tests/Maker/MakeControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public function getTestDetails(): \Generator
'FooTwig',
]);

$controllerPath = $runner->getPath('templates/foo_twig/index.html.twig');
self::assertFileExists($controllerPath);

$this->runControllerTest($runner, 'it_generates_a_controller_with_twig.php');
}),
];
Expand All @@ -59,6 +62,9 @@ public function getTestDetails(): \Generator
'FooTwig',
]);

$controllerPath = $runner->getPath('templates/foo_twig/index.html.twig');
self::assertFileExists($controllerPath);

$this->runControllerTest($runner, 'it_generates_a_controller_with_twig.php');
}),
];
Expand Down Expand Up @@ -100,6 +106,9 @@ public function getTestDetails(): \Generator
'Admin\\FooBar',
]);

$controllerPath = $runner->getPath('templates/admin/foo_bar/index.html.twig');
self::assertFileExists($controllerPath);

$this->assertFileExists($runner->getPath('templates/admin/foo_bar/index.html.twig'));
}),
];
Expand All @@ -112,6 +121,9 @@ public function getTestDetails(): \Generator
'\App\Foo\Bar\CoolController',
]);

$controllerPath = $runner->getPath('templates/foo/bar/cool/index.html.twig');
self::assertFileExists($controllerPath);

$this->assertStringContainsString('src/Foo/Bar/CoolController.php', $output);
$this->assertStringContainsString('templates/foo/bar/cool/index.html.twig', $output);
}),
Expand All @@ -125,6 +137,9 @@ public function getTestDetails(): \Generator
'FooInvokable',
], '--invokable');

$controllerPath = $runner->getPath('templates/foo_invokable.html.twig');
self::assertFileExists($controllerPath);

$this->assertStringContainsString('src/Controller/FooInvokableController.php', $output);
$this->assertStringContainsString('templates/foo_invokable.html.twig', $output);
$this->runControllerTest($runner, 'it_generates_an_invokable_controller.php');
Expand All @@ -139,6 +154,9 @@ public function getTestDetails(): \Generator
'Admin\\FooInvokable',
], '--invokable');

$controllerPath = $runner->getPath('templates/admin/foo_invokable.html.twig');
self::assertFileExists($controllerPath);

$this->assertStringContainsString('src/Controller/Admin/FooInvokableController.php', $output);
$this->assertStringContainsString('templates/admin/foo_invokable.html.twig', $output);
}),
Expand Down

0 comments on commit 9c85a83

Please sign in to comment.