Skip to content

Commit 052734c

Browse files
committed
Try to fix tests
1 parent 860d340 commit 052734c

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

src/Maker/MakeController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function configureCommand(Command $command, InputConfiguration $inputConf
3939
$command
4040
->setDescription('Creates a new controller class')
4141
->addArgument('controller-class', InputArgument::OPTIONAL, sprintf('Choose a name for your controller class (e.g. <fg=yellow>%sController</>)', Str::asClassName(Str::getRandomTerm())))
42-
->addOption('--no-template', '-n', InputOption::VALUE_OPTIONAL)
42+
->addOption('no-template', 'n', InputOption::VALUE_NONE, 'Use this option to disable template generation')
4343
->setHelp(file_get_contents(__DIR__.'/../Resources/help/MakeController.txt'))
4444
;
4545
}
@@ -52,20 +52,20 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
5252
'Controller'
5353
);
5454

55-
$withTemplate = !$input->getOption('--no-template');
55+
$noTemplate = $input->getOption('no-template');
5656
$templateName = Str::asFilePath($controllerClassNameDetails->getRelativeNameWithoutSuffix()).'/index.html.twig';
5757
$controllerPath = $generator->generateController(
5858
$controllerClassNameDetails->getFullName(),
5959
'controller/Controller.tpl.php',
6060
[
6161
'route_path' => Str::asRoutePath($controllerClassNameDetails->getRelativeNameWithoutSuffix()),
6262
'route_name' => Str::asRouteName($controllerClassNameDetails->getRelativeNameWithoutSuffix()),
63-
'twig_installed' => $this->isTwigInstalled() && $withTemplate,
63+
'with_template' => $this->isTwigInstalled() && !$noTemplate,
6464
'template_name' => $templateName,
6565
]
6666
);
6767

68-
if ($this->isTwigInstalled() && $withTemplate) {
68+
if ($this->isTwigInstalled() && !$noTemplate) {
6969
$generator->generateFile(
7070
'templates/'.$templateName,
7171
'controller/twig_template.tpl.php',

src/Resources/help/MakeController.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ The <info>%command.name%</info> command generates a new controller class.
33
<info>php %command.full_name% CoolStuffController</info>
44

55
If the argument is missing, the command will ask for the controller class name interactively.
6+
7+
You can also generate the controller alone, without template with this option:
8+
9+
<info>php %command.full_name% --no-template</info>

src/Resources/skeleton/controller/Controller.tpl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class <?= $class_name; ?> extends <?= $parent_class_name; ?><?= "\n" ?>
1212
*/
1313
public function index()
1414
{
15-
<?php if ($twig_installed) { ?>
15+
<?php if ($with_template) { ?>
1616
return $this->render('<?= $template_name ?>', [
1717
'controller_name' => '<?= $class_name ?>',
1818
]);

tests/Maker/FunctionalTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,16 @@ public function getCommandTests()
125125
$this->getMakerInstance(MakeController::class),
126126
[
127127
// controller class name
128-
'FooTwig',
128+
'FooNoTemplate',
129129
// option to disable template generation
130130
'--no-template'
131131
])
132-
->setFixtureFilesPath(__DIR__.'/../fixtures/MakeController')
133132
->addExtraDependencies('twig')
134133
->assert(function (string $output, string $directory) {
135134
// make sure the template was not configured
136135
$this->assertContainsCount('created: ', $output, 1);
136+
$this->assertContains('created: src/Controller/FooNoTemplateController.php', $output);
137+
$this->assertNotContains('created: templates/foo_no_template/index.html.twig', $output);
137138
})
138139
];
139140

0 commit comments

Comments
 (0)