diff --git a/src/Maker/MakeStimulusController.php b/src/Maker/MakeStimulusController.php index 029d6c770..6900de082 100644 --- a/src/Maker/MakeStimulusController.php +++ b/src/Maker/MakeStimulusController.php @@ -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; /** @@ -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' ); } } diff --git a/src/Maker/MakeTwigComponent.php b/src/Maker/MakeTwigComponent.php index 4be28208b..d1639dccd 100644 --- a/src/Maker/MakeTwigComponent.php +++ b/src/Maker/MakeTwigComponent.php @@ -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( diff --git a/src/Resources/skeleton/twig/Component.tpl.php b/src/Resources/skeleton/twig/Component.tpl.php index c25d2b0cc..1a29d2491 100644 --- a/src/Resources/skeleton/twig/Component.tpl.php +++ b/src/Resources/skeleton/twig/Component.tpl.php @@ -4,7 +4,7 @@ use Symfony\UX\TwigComponent\Attribute\AsTwigComponent; -#[AsTwigComponent('')] +#[AsTwigComponent()] final class { } diff --git a/src/Resources/skeleton/twig/LiveComponent.tpl.php b/src/Resources/skeleton/twig/LiveComponent.tpl.php index 896922fa7..613468bc7 100644 --- a/src/Resources/skeleton/twig/LiveComponent.tpl.php +++ b/src/Resources/skeleton/twig/LiveComponent.tpl.php @@ -5,7 +5,7 @@ use Symfony\UX\LiveComponent\Attribute\AsLiveComponent; use Symfony\UX\LiveComponent\DefaultActionTrait; -#[AsLiveComponent('')] +#[AsLiveComponent()] final class { use DefaultActionTrait; diff --git a/src/Test/MakerTestCase.php b/src/Test/MakerTestCase.php index daabf99c4..f2f4175f3 100644 --- a/src/Test/MakerTestCase.php +++ b/src/Test/MakerTestCase.php @@ -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 diff --git a/src/Test/MakerTestDetails.php b/src/Test/MakerTestDetails.php index 34e68f4c6..3b3a51b78 100644 --- a/src/Test/MakerTestDetails.php +++ b/src/Test/MakerTestDetails.php @@ -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, @@ -175,4 +176,11 @@ public function getPreRunCallbacks(): array { return $this->preRunCallbacks; } + + public function skipOnWindows(): self + { + $this->skipOnWindows = true; + + return $this; + } } diff --git a/tests/Maker/MakeControllerTest.php b/tests/Maker/MakeControllerTest.php index 908163bf9..f177b161a 100644 --- a/tests/Maker/MakeControllerTest.php +++ b/tests/Maker/MakeControllerTest.php @@ -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); }), ]; @@ -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); }), ]; @@ -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); }), ]; } diff --git a/tests/Maker/MakeCrudTest.php b/tests/Maker/MakeCrudTest.php index 040b56fae..d3da7ef09 100644 --- a/tests/Maker/MakeCrudTest.php +++ b/tests/Maker/MakeCrudTest.php @@ -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'); }), @@ -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'); }), @@ -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'); }), @@ -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'); }), @@ -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'); }), @@ -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'); @@ -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'); }), diff --git a/tests/Maker/MakeEntityTest.php b/tests/Maker/MakeEntityTest.php index bc640b7a3..2803fd9c2 100644 --- a/tests/Maker/MakeEntityTest.php +++ b/tests/Maker/MakeEntityTest.php @@ -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 diff --git a/tests/Maker/MakeFixturesTest.php b/tests/Maker/MakeFixturesTest.php index b9443076b..f26f4be23 100644 --- a/tests/Maker/MakeFixturesTest.php +++ b/tests/Maker/MakeFixturesTest.php @@ -30,7 +30,7 @@ public function getTestDetails() 'FooFixtures', ]); - $this->assertStringContainsString('created: src/DataFixtures/FooFixtures.php', $output); + $this->assertStringContainsString('src/DataFixtures/FooFixtures.php', $output); }), ]; } diff --git a/tests/Maker/MakeTwigComponentTest.php b/tests/Maker/MakeTwigComponentTest.php index 7c62e3609..fa110bc35 100644 --- a/tests/Maker/MakeTwigComponentTest.php +++ b/tests/Maker/MakeTwigComponentTest.php @@ -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(); }), ]; @@ -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(); }), ]; @@ -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(); }), ]; @@ -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(); }), ]; diff --git a/tests/Maker/TemplateLinterTest.php b/tests/Maker/TemplateLinterTest.php index 3ab000a06..e5cf24940 100644 --- a/tests/Maker/TemplateLinterTest.php +++ b/tests/Maker/TemplateLinterTest.php @@ -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'); @@ -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',