Skip to content

Changing make:stimulus-controller to require StimulusBundle #1321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/Maker/MakeStimulusController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Question\Question;
use Symfony\UX\StimulusBundle\StimulusBundle;
use Symfony\WebpackEncoreBundle\WebpackEncoreBundle;

/**
Expand Down Expand Up @@ -227,9 +228,20 @@ private function getValuesTypes(): array

public function configureDependencies(DependencyBuilder $dependencies): void
{
// lower than 8.1, allow WebpackEncoreBundle
if (\PHP_VERSION_ID < 80100) {
$dependencies->addClassDependency(
WebpackEncoreBundle::class,
'symfony/webpack-encore-bundle'
);

return;
}

// else: encourage StimulusBundle by requiring it
$dependencies->addClassDependency(
WebpackEncoreBundle::class,
'webpack-encore-bundle'
StimulusBundle::class,
'symfony/stimulus-bundle'
);
}
}
4 changes: 1 addition & 3 deletions src/Maker/MakeTwigComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,15 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
$factory = $generator->createClassNameDetails(
$name,
'Twig\\Components',
'Component'
);

$shortName = Str::asSnakeCase(Str::removeSuffix($factory->getShortName(), 'Component'));
$shortName = Str::getShortClassName($factory->getShortName());

$generator->generateClass(
$factory->getFullName(),
sprintf('%s/../Resources/skeleton/twig/%s', __DIR__, $live ? 'LiveComponent.tpl.php' : 'Component.tpl.php'),
[
'live' => $live,
'short_name' => $shortName,
]
);
$generator->generateTemplate(
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/skeleton/twig/Component.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;

#[AsTwigComponent('<?= $short_name; ?>')]
#[AsTwigComponent()]
final class <?= $class_name."\n" ?>
{
}
2 changes: 1 addition & 1 deletion src/Resources/skeleton/twig/LiveComponent.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\DefaultActionTrait;

#[AsLiveComponent('<?= $short_name; ?>')]
#[AsLiveComponent()]
final class <?= $class_name."\n" ?>
{
use DefaultActionTrait;
Expand Down
4 changes: 4 additions & 0 deletions src/Test/MakerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ protected function executeMakerCommand(MakerTestDetails $testDetails)
$this->markTestSkipped();
}

if ($testDetails->skipOnWindows() && '\\' === \DIRECTORY_SEPARATOR) {
$this->markTestSkipped('This test is not supported on Windows');
}

$testEnv = MakerTestEnvironment::create($testDetails);

// prepare environment to test
Expand Down
8 changes: 8 additions & 0 deletions src/Test/MakerTestDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ final class MakerTestDetails
private array $requiredPackageVersions = [];
private int $blockedPhpVersionUpper = 0;
private int $blockedPhpVersionLower = 0;
private bool $skipOnWindows = false;

public function __construct(
private MakerInterface $maker,
Expand Down Expand Up @@ -175,4 +176,11 @@ public function getPreRunCallbacks(): array
{
return $this->preRunCallbacks;
}

public function skipOnWindows(): self
{
$this->skipOnWindows = true;

return $this;
}
}
10 changes: 5 additions & 5 deletions tests/Maker/MakeControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public function getTestDetails(): \Generator

// make sure the template was not configured
$this->assertContainsCount('created: ', $output, 1);
$this->assertStringContainsString('created: src/Controller/FooNoTemplateController.php', $output);
$this->assertStringNotContainsString('created: templates/foo_no_template/index.html.twig', $output);
$this->assertStringContainsString('src/Controller/FooNoTemplateController.php', $output);
$this->assertStringNotContainsString('templates/foo_no_template/index.html.twig', $output);
}),
];

Expand All @@ -88,7 +88,7 @@ public function getTestDetails(): \Generator
]);

$this->assertFileExists($runner->getPath('src/Controller/Admin/FooBarController.php'));
$this->assertStringContainsString('created: src/Controller/Admin/FooBarController.php', $output);
$this->assertStringContainsString('src/Controller/Admin/FooBarController.php', $output);
}),
];

Expand All @@ -112,8 +112,8 @@ public function getTestDetails(): \Generator
'\App\Foo\Bar\CoolController',
]);

$this->assertStringContainsString('created: src/Foo/Bar/CoolController.php', $output);
$this->assertStringContainsString('created: templates/foo/bar/cool/index.html.twig', $output);
$this->assertStringContainsString('src/Foo/Bar/CoolController.php', $output);
$this->assertStringContainsString('templates/foo/bar/cool/index.html.twig', $output);
}),
];
}
Expand Down
32 changes: 16 additions & 16 deletions tests/Maker/MakeCrudTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public function getTestDetails(): \Generator
'n', // Generate Tests
]);

$this->assertStringContainsString('created: src/Controller/SweetFoodController.php', $output);
$this->assertStringContainsString('created: src/Form/SweetFoodType.php', $output);
$this->assertStringContainsString('src/Controller/SweetFoodController.php', $output);
$this->assertStringContainsString('src/Form/SweetFoodType.php', $output);

$this->runCrudTest($runner, 'it_generates_basic_crud.php');
}),
Expand All @@ -58,8 +58,8 @@ public function getTestDetails(): \Generator
'y', // Generate Tests
]);

$this->assertStringContainsString('created: src/Controller/SweetFoodAdminController.php', $output);
$this->assertStringContainsString('created: src/Form/SweetFoodType.php', $output);
$this->assertStringContainsString('src/Controller/SweetFoodAdminController.php', $output);
$this->assertStringContainsString('src/Form/SweetFoodType.php', $output);

$this->runCrudTest($runner, 'it_generates_crud_with_custom_controller.php');
}),
Expand All @@ -79,9 +79,9 @@ public function getTestDetails(): \Generator
'y', // Generate Tests
]);

$this->assertStringContainsString('created: src/Controller/SweetFoodController.php', $output);
$this->assertStringContainsString('created: src/Form/SweetFoodType.php', $output);
$this->assertStringContainsString('created: tests/Controller/SweetFoodControllerTest.php', $output);
$this->assertStringContainsString('src/Controller/SweetFoodController.php', $output);
$this->assertStringContainsString('src/Form/SweetFoodType.php', $output);
$this->assertStringContainsString('tests/Controller/SweetFoodControllerTest.php', $output);

$this->runCrudTest($runner, 'it_generates_basic_crud.php');
}),
Expand All @@ -106,9 +106,9 @@ public function getTestDetails(): \Generator
'y', // Generate Tests
]);

$this->assertStringContainsString('created: src/Controller/SweetFoodController.php', $output);
$this->assertStringContainsString('created: src/Form/SweetFoodType.php', $output);
$this->assertStringContainsString('created: tests/Controller/SweetFoodControllerTest.php', $output);
$this->assertStringContainsString('src/Controller/SweetFoodController.php', $output);
$this->assertStringContainsString('src/Form/SweetFoodType.php', $output);
$this->assertStringContainsString('tests/Controller/SweetFoodControllerTest.php', $output);

$this->runCrudTest($runner, 'it_generates_basic_crud.php');
}),
Expand Down Expand Up @@ -147,8 +147,8 @@ public function getTestDetails(): \Generator
'n', // Generate Tests
]);

$this->assertStringContainsString('created: src/Controller/SweetFoodController.php', $output);
$this->assertStringContainsString('created: src/Form/SweetFoodType.php', $output);
$this->assertStringContainsString('src/Controller/SweetFoodController.php', $output);
$this->assertStringContainsString('src/Form/SweetFoodType.php', $output);

$this->runCrudTest($runner, 'it_generates_crud_with_custom_root_namespace.php');
}),
Expand All @@ -171,8 +171,8 @@ public function getTestDetails(): \Generator
'n', // Generate Tests
]);

$this->assertStringContainsString('created: src/Controller/SweetFoodController.php', $output);
$this->assertStringContainsString('created: src/Form/SweetFoodType.php', $output);
$this->assertStringContainsString('src/Controller/SweetFoodController.php', $output);
$this->assertStringContainsString('src/Form/SweetFoodType.php', $output);

$this->runCrudTest($runner, 'it_generates_basic_crud.php');

Expand All @@ -198,8 +198,8 @@ public function getTestDetails(): \Generator
'n', // Generate Tests
]);

$this->assertStringContainsString('created: src/Controller/SweetFoodController.php', $output);
$this->assertStringContainsString('created: src/Form/SweetFoodType.php', $output);
$this->assertStringContainsString('src/Controller/SweetFoodController.php', $output);
$this->assertStringContainsString('src/Form/SweetFoodType.php', $output);

$this->runCrudTest($runner, 'it_generates_basic_crud.php');
}),
Expand Down
2 changes: 1 addition & 1 deletion tests/Maker/MakeEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public function getTestDetails(): \Generator
'',
]);

$this->assertStringContainsString('updated: src/Entity/User.php', $output);
$this->assertStringContainsString('src/Entity/User.php', $output);
$this->assertStringNotContainsString('updated: vendor/', $output);

// sanity checks on the generated code
Expand Down
2 changes: 1 addition & 1 deletion tests/Maker/MakeFixturesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getTestDetails()
'FooFixtures',
]);

$this->assertStringContainsString('created: src/DataFixtures/FooFixtures.php', $output);
$this->assertStringContainsString('src/DataFixtures/FooFixtures.php', $output);
}),
];
}
Expand Down
32 changes: 16 additions & 16 deletions tests/Maker/MakeTwigComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ public function getTestDetails(): \Generator
->run(function (MakerTestRunner $runner) {
$output = $runner->runMaker(['Alert']);

$this->assertStringContainsString('created: src/Twig/Components/AlertComponent.php', $output);
$this->assertStringContainsString('created: templates/components/alert.html.twig', $output);
$this->assertStringContainsString("To render the component, use {{ component('alert') }}.", $output);
$this->assertStringContainsString('src/Twig/Components/Alert.php', $output);
$this->assertStringContainsString('templates/components/Alert.html.twig', $output);
$this->assertStringContainsString("To render the component, use {{ component('Alert') }}.", $output);

$runner->copy(
'make-twig-component/tests/it_generates_twig_component.php',
'tests/GeneratedTwigComponentTest.php'
);
$runner->replaceInFile('tests/GeneratedTwigComponentTest.php', '{name}', 'alert');
$runner->replaceInFile('tests/GeneratedTwigComponentTest.php', '{name}', 'Alert');
$runner->runTests();
}),
];
Expand All @@ -42,15 +42,15 @@ public function getTestDetails(): \Generator
->run(function (MakerTestRunner $runner) {
$output = $runner->runMaker(['FormInput']);

$this->assertStringContainsString('created: src/Twig/Components/FormInputComponent.php', $output);
$this->assertStringContainsString('created: templates/components/form_input.html.twig', $output);
$this->assertStringContainsString("To render the component, use {{ component('form_input') }}.", $output);
$this->assertStringContainsString('src/Twig/Components/FormInput.php', $output);
$this->assertStringContainsString('templates/components/FormInput.html.twig', $output);
$this->assertStringContainsString("To render the component, use {{ component('FormInput') }}.", $output);

$runner->copy(
'make-twig-component/tests/it_generates_twig_component.php',
'tests/GeneratedTwigComponentTest.php'
);
$runner->replaceInFile('tests/GeneratedTwigComponentTest.php', '{name}', 'form_input');
$runner->replaceInFile('tests/GeneratedTwigComponentTest.php', '{name}', 'FormInput');
$runner->runTests();
}),
];
Expand All @@ -60,15 +60,15 @@ public function getTestDetails(): \Generator
->run(function (MakerTestRunner $runner) {
$output = $runner->runMaker(['Alert']);

$this->assertStringContainsString('created: src/Twig/Components/AlertComponent.php', $output);
$this->assertStringContainsString('created: templates/components/alert.html.twig', $output);
$this->assertStringContainsString("To render the component, use {{ component('alert') }}.", $output);
$this->assertStringContainsString('src/Twig/Components/Alert.php', $output);
$this->assertStringContainsString('templates/components/Alert.html.twig', $output);
$this->assertStringContainsString("To render the component, use {{ component('Alert') }}.", $output);

$runner->copy(
'make-twig-component/tests/it_generates_live_component.php',
'tests/GeneratedLiveComponentTest.php'
);
$runner->replaceInFile('tests/GeneratedLiveComponentTest.php', '{name}', 'alert');
$runner->replaceInFile('tests/GeneratedLiveComponentTest.php', '{name}', 'Alert');
$runner->runTests();
}),
];
Expand All @@ -78,15 +78,15 @@ public function getTestDetails(): \Generator
->run(function (MakerTestRunner $runner) {
$output = $runner->runMaker(['FormInput']);

$this->assertStringContainsString('created: src/Twig/Components/FormInputComponent.php', $output);
$this->assertStringContainsString('created: templates/components/form_input.html.twig', $output);
$this->assertStringContainsString("To render the component, use {{ component('form_input') }}.", $output);
$this->assertStringContainsString('src/Twig/Components/FormInput.php', $output);
$this->assertStringContainsString('templates/components/FormInput.html.twig', $output);
$this->assertStringContainsString("To render the component, use {{ component('FormInput') }}.", $output);

$runner->copy(
'make-twig-component/tests/it_generates_live_component.php',
'tests/GeneratedLiveComponentTest.php'
);
$runner->replaceInFile('tests/GeneratedLiveComponentTest.php', '{name}', 'form_input');
$runner->replaceInFile('tests/GeneratedLiveComponentTest.php', '{name}', 'FormInput');
$runner->runTests();
}),
];
Expand Down
4 changes: 4 additions & 0 deletions tests/Maker/TemplateLinterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public function getTestDetails(): \Generator
{
yield 'lints_templates_with_custom_php_cs_fixer_and_config' => [$this->createMakerTest()
->addExtraDependencies('friendsofphp/php-cs-fixer')
// these tests are troublesome on Windows
->skipOnWindows()
->run(function (MakerTestRunner $runner) {
$runner->copy('template-linter/php-cs-fixer.test.php', 'php-cs-fixer.test.php');

Expand All @@ -60,6 +62,8 @@ public function getTestDetails(): \Generator

yield 'lints_templates_with_flex_generated_config_file' => [$this->createMakerTest()
->addExtraDependencies('friendsofphp/php-cs-fixer')
// these tests are troublesome on Windows
->skipOnWindows()
->run(function (MakerTestRunner $runner) {
$runner->replaceInFile(
'.php-cs-fixer.dist.php',
Expand Down