From a692d64acc64e5f41e8e3211cb52b4c9cab5bb4d Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Tue, 17 May 2022 16:20:43 -0400 Subject: [PATCH 01/17] require php 8 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d65c7e288..5c378a8ac 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ ], "minimum-stability": "dev", "require": { - "php": ">=7.2.5", + "php": ">=8.0", "doctrine/inflector": "^2.0", "nikic/php-parser": "^4.11", "symfony/config": "^5.4.7|^6.0", From 7b9ef401263b11de396773f25dcb3816a6a0600b Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Tue, 17 May 2022 16:52:58 -0400 Subject: [PATCH 02/17] [internal] partially implement constructor prop promotion --- src/Command/MakerCommand.php | 17 +++++------------ src/Maker/MakeAuthenticator.php | 20 +++++++------------- src/Maker/MakeCommand.php | 5 +---- src/Maker/MakeController.php | 2 +- src/Maker/MakeCrud.php | 13 +++++-------- src/Maker/MakeEntity.php | 15 +++++---------- src/Maker/MakeForm.php | 7 +------ src/Maker/MakeMessage.php | 5 +---- src/Maker/MakeMigration.php | 10 ++-------- src/Maker/MakeRegistrationForm.php | 17 ++++++----------- src/Maker/MakeResetPassword.php | 30 +++++++++++++----------------- src/Maker/MakeSubscriber.php | 5 +---- src/Maker/MakeUser.php | 20 +++++++------------- 13 files changed, 55 insertions(+), 111 deletions(-) diff --git a/src/Command/MakerCommand.php b/src/Command/MakerCommand.php index 172ca0a93..7453dc6ba 100644 --- a/src/Command/MakerCommand.php +++ b/src/Command/MakerCommand.php @@ -32,20 +32,13 @@ */ final class MakerCommand extends Command { - private $maker; - private $fileManager; - private $inputConfig; - /** @var ConsoleStyle */ - private $io; - private $checkDependencies = true; - private $generator; - - public function __construct(MakerInterface $maker, FileManager $fileManager, Generator $generator) + private InputConfiguration $inputConfig; + private ConsoleStyle $io; + private bool $checkDependencies = true; + + public function __construct(private MakerInterface $maker, private FileManager $fileManager, private Generator $generator) { - $this->maker = $maker; - $this->fileManager = $fileManager; $this->inputConfig = new InputConfiguration(); - $this->generator = $generator; parent::__construct(); } diff --git a/src/Maker/MakeAuthenticator.php b/src/Maker/MakeAuthenticator.php index ad3c4fc63..73a5f0ecf 100644 --- a/src/Maker/MakeAuthenticator.php +++ b/src/Maker/MakeAuthenticator.php @@ -65,19 +65,13 @@ final class MakeAuthenticator extends AbstractMaker private const AUTH_TYPE_EMPTY_AUTHENTICATOR = 'empty-authenticator'; private const AUTH_TYPE_FORM_LOGIN = 'form-login'; - private $fileManager; - private $configUpdater; - private $generator; - private $doctrineHelper; - private $securityControllerBuilder; - - public function __construct(FileManager $fileManager, SecurityConfigUpdater $configUpdater, Generator $generator, DoctrineHelper $doctrineHelper, SecurityControllerBuilder $securityControllerBuilder) - { - $this->fileManager = $fileManager; - $this->configUpdater = $configUpdater; - $this->generator = $generator; - $this->doctrineHelper = $doctrineHelper; - $this->securityControllerBuilder = $securityControllerBuilder; + public function __construct( + private FileManager $fileManager, + private SecurityConfigUpdater $configUpdater, + private Generator $generator, + private DoctrineHelper $doctrineHelper, + private SecurityControllerBuilder $securityControllerBuilder + ) { } public static function getCommandName(): string diff --git a/src/Maker/MakeCommand.php b/src/Maker/MakeCommand.php index 5331d9db0..5ab22e461 100644 --- a/src/Maker/MakeCommand.php +++ b/src/Maker/MakeCommand.php @@ -33,11 +33,8 @@ */ final class MakeCommand extends AbstractMaker { - private $phpCompatUtil; - - public function __construct(PhpCompatUtil $phpCompatUtil) + public function __construct(private PhpCompatUtil $phpCompatUtil) { - $this->phpCompatUtil = $phpCompatUtil; } public static function getCommandName(): string diff --git a/src/Maker/MakeController.php b/src/Maker/MakeController.php index 40bf421f7..7fac2defe 100644 --- a/src/Maker/MakeController.php +++ b/src/Maker/MakeController.php @@ -36,7 +36,7 @@ */ final class MakeController extends AbstractMaker { - private $phpCompatUtil; + private PhpCompatUtil $phpCompatUtil; public function __construct(PhpCompatUtil $phpCompatUtil = null) { diff --git a/src/Maker/MakeCrud.php b/src/Maker/MakeCrud.php index b2817e35d..89169922f 100644 --- a/src/Maker/MakeCrud.php +++ b/src/Maker/MakeCrud.php @@ -12,6 +12,7 @@ namespace Symfony\Bundle\MakerBundle\Maker; use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; +use Doctrine\Inflector\Inflector; use Doctrine\Inflector\InflectorFactory; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; @@ -45,16 +46,12 @@ */ final class MakeCrud extends AbstractMaker { - private $doctrineHelper; - private $formTypeRenderer; - private $inflector; - private $controllerClassName; - private $generateTests = false; + private Inflector $inflector; + private string $controllerClassName; + private bool $generateTests = false; - public function __construct(DoctrineHelper $doctrineHelper, FormTypeRenderer $formTypeRenderer) + public function __construct(private DoctrineHelper $doctrineHelper, private FormTypeRenderer $formTypeRenderer) { - $this->doctrineHelper = $doctrineHelper; - $this->formTypeRenderer = $formTypeRenderer; $this->inflector = InflectorFactory::create()->build(); } diff --git a/src/Maker/MakeEntity.php b/src/Maker/MakeEntity.php index dc9a87045..6bb6ab5d6 100644 --- a/src/Maker/MakeEntity.php +++ b/src/Maker/MakeEntity.php @@ -45,23 +45,18 @@ */ final class MakeEntity extends AbstractMaker implements InputAwareMakerInterface { - private $fileManager; - private $doctrineHelper; - private $generator; - private $entityClassGenerator; - private $phpCompatUtil; + private Generator $generator; + private EntityClassGenerator $entityClassGenerator; + private PhpCompatUtil $phpCompatUtil; public function __construct( - FileManager $fileManager, - DoctrineHelper $doctrineHelper, + private FileManager $fileManager, + private DoctrineHelper $doctrineHelper, string $projectDirectory = null, Generator $generator = null, EntityClassGenerator $entityClassGenerator = null, PhpCompatUtil $phpCompatUtil = null ) { - $this->fileManager = $fileManager; - $this->doctrineHelper = $doctrineHelper; - if (null !== $projectDirectory) { @trigger_error('The $projectDirectory constructor argument is no longer used since 1.41.0', \E_USER_DEPRECATED); } diff --git a/src/Maker/MakeForm.php b/src/Maker/MakeForm.php index 562902eb8..4c93a3527 100644 --- a/src/Maker/MakeForm.php +++ b/src/Maker/MakeForm.php @@ -34,13 +34,8 @@ */ final class MakeForm extends AbstractMaker { - private $entityHelper; - private $formTypeRenderer; - - public function __construct(DoctrineHelper $entityHelper, FormTypeRenderer $formTypeRenderer) + public function __construct(private DoctrineHelper $entityHelper, private FormTypeRenderer $formTypeRenderer) { - $this->entityHelper = $entityHelper; - $this->formTypeRenderer = $formTypeRenderer; } public static function getCommandName(): string diff --git a/src/Maker/MakeMessage.php b/src/Maker/MakeMessage.php index 74b62eeca..feaabdc55 100644 --- a/src/Maker/MakeMessage.php +++ b/src/Maker/MakeMessage.php @@ -32,11 +32,8 @@ */ final class MakeMessage extends AbstractMaker { - private $fileManager; - - public function __construct(FileManager $fileManager) + public function __construct(private FileManager $fileManager) { - $this->fileManager = $fileManager; } public static function getCommandName(): string diff --git a/src/Maker/MakeMigration.php b/src/Maker/MakeMigration.php index 41f1d3752..e52d8ed15 100644 --- a/src/Maker/MakeMigration.php +++ b/src/Maker/MakeMigration.php @@ -31,16 +31,10 @@ */ final class MakeMigration extends AbstractMaker implements ApplicationAwareMakerInterface { - private $projectDir; + private Application $application; - /** - * @var Application - */ - private $application; - - public function __construct(string $projectDir) + public function __construct(private string $projectDir) { - $this->projectDir = $projectDir; } public static function getCommandName(): string diff --git a/src/Maker/MakeRegistrationForm.php b/src/Maker/MakeRegistrationForm.php index dbfc7bbb4..f2cac912e 100644 --- a/src/Maker/MakeRegistrationForm.php +++ b/src/Maker/MakeRegistrationForm.php @@ -67,11 +67,6 @@ */ final class MakeRegistrationForm extends AbstractMaker { - private $fileManager; - private $formTypeRenderer; - private $router; - private $doctrineHelper; - private $userClass; private $usernameField; private $passwordField; @@ -87,12 +82,12 @@ final class MakeRegistrationForm extends AbstractMaker private $addUniqueEntityConstraint; private $useNewAuthenticatorSystem = false; - public function __construct(FileManager $fileManager, FormTypeRenderer $formTypeRenderer, RouterInterface $router, DoctrineHelper $doctrineHelper) - { - $this->fileManager = $fileManager; - $this->formTypeRenderer = $formTypeRenderer; - $this->router = $router; - $this->doctrineHelper = $doctrineHelper; + public function __construct( + private FileManager $fileManager, + private FormTypeRenderer $formTypeRenderer, + private RouterInterface $router, + private DoctrineHelper $doctrineHelper + ) { } public static function getCommandName(): string diff --git a/src/Maker/MakeResetPassword.php b/src/Maker/MakeResetPassword.php index e70ab8cc1..bdde8ebb7 100644 --- a/src/Maker/MakeResetPassword.php +++ b/src/Maker/MakeResetPassword.php @@ -78,23 +78,19 @@ */ class MakeResetPassword extends AbstractMaker { - private $fileManager; - private $doctrineHelper; - private $entityClassGenerator; - - private $fromEmailAddress; - private $fromEmailName; - private $controllerResetSuccessRedirect; - private $userClass; - private $emailPropertyName; - private $emailGetterMethodName; - private $passwordSetterMethodName; - - public function __construct(FileManager $fileManager, DoctrineHelper $doctrineHelper, EntityClassGenerator $entityClassGenerator) - { - $this->fileManager = $fileManager; - $this->doctrineHelper = $doctrineHelper; - $this->entityClassGenerator = $entityClassGenerator; + private string $fromEmailAddress; + private string $fromEmailName; + private string $controllerResetSuccessRedirect; + private string $userClass; + private string $emailPropertyName; + private string $emailGetterMethodName; + private string $passwordSetterMethodName; + + public function __construct( + private FileManager $fileManager, + private DoctrineHelper $doctrineHelper, + private EntityClassGenerator $entityClassGenerator + ) { } public static function getCommandName(): string diff --git a/src/Maker/MakeSubscriber.php b/src/Maker/MakeSubscriber.php index 818a2c455..1f7cdb148 100644 --- a/src/Maker/MakeSubscriber.php +++ b/src/Maker/MakeSubscriber.php @@ -31,11 +31,8 @@ */ final class MakeSubscriber extends AbstractMaker { - private $eventRegistry; - - public function __construct(EventRegistry $eventRegistry) + public function __construct(private EventRegistry $eventRegistry) { - $this->eventRegistry = $eventRegistry; } public static function getCommandName(): string diff --git a/src/Maker/MakeUser.php b/src/Maker/MakeUser.php index a6aca4f19..cb0c476d0 100644 --- a/src/Maker/MakeUser.php +++ b/src/Maker/MakeUser.php @@ -48,19 +48,13 @@ */ final class MakeUser extends AbstractMaker { - private $fileManager; - private $userClassBuilder; - private $configUpdater; - private $entityClassGenerator; - private $doctrineHelper; - - public function __construct(FileManager $fileManager, UserClassBuilder $userClassBuilder, SecurityConfigUpdater $configUpdater, EntityClassGenerator $entityClassGenerator, DoctrineHelper $doctrineHelper) - { - $this->fileManager = $fileManager; - $this->userClassBuilder = $userClassBuilder; - $this->configUpdater = $configUpdater; - $this->entityClassGenerator = $entityClassGenerator; - $this->doctrineHelper = $doctrineHelper; + public function __construct( + private FileManager $fileManager, + private UserClassBuilder $userClassBuilder, + private SecurityConfigUpdater $configUpdater, + private EntityClassGenerator $entityClassGenerator, + private DoctrineHelper $doctrineHelper + ) { } public static function getCommandName(): string From 514ae733d7e9c26b52773945023cc0c40eb0a976 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Tue, 17 May 2022 17:27:47 -0400 Subject: [PATCH 03/17] always use typed properties and attributes in generated templates --- .../LoginFormAuthenticator.tpl.php | 5 +-- .../skeleton/command/Command.tpl.php | 7 ---- .../crud/controller/Controller.tpl.php | 6 ---- .../crud/test/Test.EntityManager.tpl.php | 11 +++--- src/Resources/skeleton/crud/test/Test.tpl.php | 8 ++--- .../ResetPasswordController.tpl.php | 35 +++---------------- .../skeleton/serializer/Normalizer.tpl.php | 5 +-- .../verifyEmail/EmailVerifier.tpl.php | 14 +++----- 8 files changed, 18 insertions(+), 73 deletions(-) diff --git a/src/Resources/skeleton/authenticator/LoginFormAuthenticator.tpl.php b/src/Resources/skeleton/authenticator/LoginFormAuthenticator.tpl.php index fa960f107..a7d6ba04f 100644 --- a/src/Resources/skeleton/authenticator/LoginFormAuthenticator.tpl.php +++ b/src/Resources/skeleton/authenticator/LoginFormAuthenticator.tpl.php @@ -10,11 +10,8 @@ class extends AbstractLoginFormAuthenticator public const LOGIN_ROUTE = 'app_login'; - private $urlGenerator; - - public function __construct(UrlGeneratorInterface $urlGenerator) + public function __construct(private UrlGeneratorInterface $urlGenerator) { - $this->urlGenerator = $urlGenerator; } public function authenticate(Request $request): Passport diff --git a/src/Resources/skeleton/command/Command.tpl.php b/src/Resources/skeleton/command/Command.tpl.php index 27c39d937..c6a7a895c 100644 --- a/src/Resources/skeleton/command/Command.tpl.php +++ b/src/Resources/skeleton/command/Command.tpl.php @@ -4,19 +4,12 @@ - #[AsCommand( name: '', description: 'Add a short description for your command', )] - class extends Command { - - protected static $defaultName = ''; - protected static $defaultDescription = 'Add a short description for your command'; - - protected function configure(): void { $this diff --git a/src/Resources/skeleton/crud/controller/Controller.tpl.php b/src/Resources/skeleton/crud/controller/Controller.tpl.php index 2842a0c02..e457515b2 100644 --- a/src/Resources/skeleton/crud/controller/Controller.tpl.php +++ b/src/Resources/skeleton/crud/controller/Controller.tpl.php @@ -4,13 +4,7 @@ - #[Route('')] - -/** - * @Route("") - */ - class extends AbstractController { generateRouteForControllerMethod('/', sprintf('%s_index', $route_name), ['GET']) ?> diff --git a/src/Resources/skeleton/crud/test/Test.EntityManager.tpl.php b/src/Resources/skeleton/crud/test/Test.EntityManager.tpl.php index a951d7088..5d6ed55d3 100644 --- a/src/Resources/skeleton/crud/test/Test.EntityManager.tpl.php +++ b/src/Resources/skeleton/crud/test/Test.EntityManager.tpl.php @@ -7,13 +7,10 @@ class extends WebTestCase { - - private $client; - - private $manager; - - private $repository; - private $path = '/'; + private KernelBrowser $client; + private EntityManagerInterface $manager; + private EntityRepository $repository; + private string $path = '/'; protected function setUp(): void { diff --git a/src/Resources/skeleton/crud/test/Test.tpl.php b/src/Resources/skeleton/crud/test/Test.tpl.php index d98a9d837..7b7a6e8c9 100644 --- a/src/Resources/skeleton/crud/test/Test.tpl.php +++ b/src/Resources/skeleton/crud/test/Test.tpl.php @@ -7,11 +7,9 @@ class extends WebTestCase { - - private $client; - - private $repository; - private $path = '/'; + private KernelBrowser $client; + private $repository; + private string $path = '/'; protected function setUp(): void { diff --git a/src/Resources/skeleton/resetPassword/ResetPasswordController.tpl.php b/src/Resources/skeleton/resetPassword/ResetPasswordController.tpl.php index 6b43b8746..e0ea1da27 100644 --- a/src/Resources/skeleton/resetPassword/ResetPasswordController.tpl.php +++ b/src/Resources/skeleton/resetPassword/ResetPasswordController.tpl.php @@ -4,36 +4,21 @@ - #[Route('/reset-password')] - -/** - * @Route("/reset-password") - */ - class extends AbstractController { use ResetPasswordControllerTrait; - private $resetPasswordHelper; - private $entityManager; - - public function __construct(ResetPasswordHelperInterface $resetPasswordHelper, EntityManagerInterface $entityManager) - { - $this->resetPasswordHelper = $resetPasswordHelper; - $this->entityManager = $entityManager; + public function __construct( + private ResetPasswordHelperInterface $resetPasswordHelper, + private EntityManagerInterface $entityManager + ) { } /** * Display & process form to request a password reset. - */ #[Route('', name: 'app_forgot_password_request')] - - * - * @Route("", name="app_forgot_password_request") - */ - public function request(Request $request, MailerInterface $mailer, TranslatorInterface $translator): Response { $form = $this->createForm(::class); @@ -54,14 +39,8 @@ public function request(Request $request, MailerInterface $mailer */ #[Route('/check-email', name: 'app_check_email')] - - * - * @Route("/check-email", name="app_check_email") - */ - public function checkEmail(): Response { // Generate a fake token if the user does not exist or someone hit this page directly. @@ -77,14 +56,8 @@ public function checkEmail(): Response /** * Validates and process the reset URL that the user clicked in their email. - */ #[Route('/reset/{token}', name: 'app_reset_password')] - - * - * @Route("/reset/{token}", name="app_reset_password") - */ - public function reset(Request $request, getShortName() ?> , TranslatorInterface $translator, string $token = null): Response { if ($token) { diff --git a/src/Resources/skeleton/serializer/Normalizer.tpl.php b/src/Resources/skeleton/serializer/Normalizer.tpl.php index ed4d4ec96..bad18426a 100644 --- a/src/Resources/skeleton/serializer/Normalizer.tpl.php +++ b/src/Resources/skeleton/serializer/Normalizer.tpl.php @@ -6,11 +6,8 @@ class implements NormalizerInterface, CacheableSupportsMethodInterface { - private $normalizer; - - public function __construct(ObjectNormalizer $normalizer) + public function __construct(private ObjectNormalizer $normalizer) { - $this->normalizer = $normalizer; } public function normalize($object, string $format = null, array $context = []): array diff --git a/src/Resources/skeleton/verifyEmail/EmailVerifier.tpl.php b/src/Resources/skeleton/verifyEmail/EmailVerifier.tpl.php index 100faf491..24c649aee 100644 --- a/src/Resources/skeleton/verifyEmail/EmailVerifier.tpl.php +++ b/src/Resources/skeleton/verifyEmail/EmailVerifier.tpl.php @@ -6,15 +6,11 @@ class { - private $verifyEmailHelper; - private $mailer; - private $entityManager; - - public function __construct(VerifyEmailHelperInterface $helper, MailerInterface $mailer, EntityManagerInterface $manager) - { - $this->verifyEmailHelper = $helper; - $this->mailer = $mailer; - $this->entityManager = $manager; + public function __construct( + private VerifyEmailHelperInterface $helper, + private MailerInterface $mailer, + private EntityManagerInterface $manager + ) { } public function sendEmailConfirmation(string $verifyEmailRouteName, UserInterface $user, TemplatedEmail $email): void From 08ba7b25576b31c641d56e27d0864dd219256f0e Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Tue, 17 May 2022 17:38:59 -0400 Subject: [PATCH 04/17] [internal] remove route annotation support --- src/Util/TemplateComponentGenerator.php | 37 ++------- tests/Util/TemplateComponentGeneratorTest.php | 78 +++---------------- 2 files changed, 17 insertions(+), 98 deletions(-) diff --git a/src/Util/TemplateComponentGenerator.php b/src/Util/TemplateComponentGenerator.php index a5e927639..bbea3c004 100644 --- a/src/Util/TemplateComponentGenerator.php +++ b/src/Util/TemplateComponentGenerator.php @@ -28,48 +28,25 @@ public function __construct(PhpCompatUtil $phpCompatUtil) $this->phpCompatUtil = $phpCompatUtil; } - /** @legacy Annotation Support can be dropped w/ Symfony 6 LTS */ public function generateRouteForControllerMethod(string $routePath, string $routeName, array $methods = [], bool $indent = true, bool $trailingNewLine = true): string { - if ($this->phpCompatUtil->canUseAttributes()) { - $attribute = sprintf('%s#[Route(\'%s\', name: \'%s\'', $indent ? ' ' : null, $routePath, $routeName); - - if (!empty($methods)) { - $attribute .= ', methods: ['; - - foreach ($methods as $method) { - $attribute .= sprintf('\'%s\', ', $method); - } - - $attribute = rtrim($attribute, ', '); - - $attribute .= ']'; - } - - $attribute .= sprintf(')]%s', $trailingNewLine ? "\n" : null); - - return $attribute; - } - - $annotation = sprintf('%s/**%s', $indent ? ' ' : null, "\n"); - $annotation .= sprintf('%s * @Route("%s", name="%s"', $indent ? ' ' : null, $routePath, $routeName); + $attribute = sprintf('%s#[Route(\'%s\', name: \'%s\'', $indent ? ' ' : null, $routePath, $routeName); if (!empty($methods)) { - $annotation .= ', methods={'; + $attribute .= ', methods: ['; foreach ($methods as $method) { - $annotation .= sprintf('"%s", ', $method); + $attribute .= sprintf('\'%s\', ', $method); } - $annotation = rtrim($annotation, ', '); + $attribute = rtrim($attribute, ', '); - $annotation .= '}'; + $attribute .= ']'; } - $annotation .= sprintf(')%s', "\n"); - $annotation .= sprintf('%s */%s', $indent ? ' ' : null, $trailingNewLine ? "\n" : null); + $attribute .= sprintf(')]%s', $trailingNewLine ? "\n" : null); - return $annotation; + return $attribute; } public function getPropertyType(ClassNameDetails $classNameDetails): ?string diff --git a/tests/Util/TemplateComponentGeneratorTest.php b/tests/Util/TemplateComponentGeneratorTest.php index d74afa1cf..4c756e104 100644 --- a/tests/Util/TemplateComponentGeneratorTest.php +++ b/tests/Util/TemplateComponentGeneratorTest.php @@ -22,59 +22,19 @@ class TemplateComponentGeneratorTest extends TestCase { public function testRouteAttributes(): void { - $mockPhpCompatUtil = $this->createMock(PhpCompatUtil::class); - $mockPhpCompatUtil - ->expects(self::once()) - ->method('canUseAttributes') - ->willReturn(true) - ; - - $generator = new TemplateComponentGenerator($mockPhpCompatUtil); + $generator = new TemplateComponentGenerator($this->createMock(PhpCompatUtil::class)); $expected = " #[Route('/', name: 'app_home')]\n"; self::assertSame($expected, $generator->generateRouteForControllerMethod('/', 'app_home')); } - public function testRouteAnnotations(): void - { - $mockPhpCompatUtil = $this->createMock(PhpCompatUtil::class); - $mockPhpCompatUtil - ->expects(self::once()) - ->method('canUseAttributes') - ->willReturn(false) - ; - - $generator = new TemplateComponentGenerator($mockPhpCompatUtil); - - $expected = " /**\n"; - $expected .= " * @Route(\"/\", name=\"app_home\")\n"; - $expected .= " */\n"; - - self::assertSame($expected, $generator->generateRouteForControllerMethod('/', 'app_home')); - } - /** * @dataProvider routeMethodDataProvider */ - public function testRouteMethods(string $expected, bool $useAttribute, array $methods): void + public function testRouteMethods(string $expected, array $methods): void { - $mockPhpCompatUtil = $this->createMock(PhpCompatUtil::class); - $mockPhpCompatUtil - ->expects(self::once()) - ->method('canUseAttributes') - ->willReturn($useAttribute) - ; - - $generator = new TemplateComponentGenerator($mockPhpCompatUtil); - - if (!$useAttribute) { - $annotation = " /**\n"; - $annotation .= $expected; - $annotation .= " */\n"; - - $expected = $annotation; - } + $generator = new TemplateComponentGenerator($this->createMock(PhpCompatUtil::class)); self::assertSame($expected, $generator->generateRouteForControllerMethod( '/', @@ -85,25 +45,16 @@ public function testRouteMethods(string $expected, bool $useAttribute, array $me public function routeMethodDataProvider(): \Generator { - yield [" #[Route('/', name: 'app_home', methods: ['GET'])]\n", true, ['GET']]; - yield [" * @Route(\"/\", name=\"app_home\", methods={\"GET\"})\n", false, ['GET']]; - yield [" #[Route('/', name: 'app_home', methods: ['GET', 'POST'])]\n", true, ['GET', 'POST']]; - yield [" * @Route(\"/\", name=\"app_home\", methods={\"GET\", \"POST\"})\n", false, ['GET', 'POST']]; + yield [" #[Route('/', name: 'app_home', methods: ['GET'])]\n", ['GET']]; + yield [" #[Route('/', name: 'app_home', methods: ['GET', 'POST'])]\n", ['GET', 'POST']]; } /** * @dataProvider routeIndentationDataProvider */ - public function testRouteIndentation(string $expected, bool $useAttribute): void + public function testRouteIndentation(string $expected): void { - $mockPhpCompatUtil = $this->createMock(PhpCompatUtil::class); - $mockPhpCompatUtil - ->expects(self::once()) - ->method('canUseAttributes') - ->willReturn($useAttribute) - ; - - $generator = new TemplateComponentGenerator($mockPhpCompatUtil); + $generator = new TemplateComponentGenerator($this->createMock(PhpCompatUtil::class)); self::assertSame($expected, $generator->generateRouteForControllerMethod( '/', @@ -115,23 +66,15 @@ public function testRouteIndentation(string $expected, bool $useAttribute): void public function routeIndentationDataProvider(): \Generator { - yield ["#[Route('/', name: 'app_home')]\n", true]; - yield ["/**\n * @Route(\"/\", name=\"app_home\")\n */\n", false]; + yield ["#[Route('/', name: 'app_home')]\n"]; } /** * @dataProvider routeTrailingNewLineDataProvider */ - public function testRouteTrailingNewLine(string $expected, bool $useAttribute): void + public function testRouteTrailingNewLine(string $expected): void { - $mockPhpCompatUtil = $this->createMock(PhpCompatUtil::class); - $mockPhpCompatUtil - ->expects(self::once()) - ->method('canUseAttributes') - ->willReturn($useAttribute) - ; - - $generator = new TemplateComponentGenerator($mockPhpCompatUtil); + $generator = new TemplateComponentGenerator($this->createMock(PhpCompatUtil::class)); self::assertSame($expected, $generator->generateRouteForControllerMethod( '/', @@ -145,6 +88,5 @@ public function testRouteTrailingNewLine(string $expected, bool $useAttribute): public function routeTrailingNewLineDataProvider(): \Generator { yield ["#[Route('/', name: 'app_home')]", true]; - yield ["/**\n * @Route(\"/\", name=\"app_home\")\n */", false]; } } From b35ab231e638274db4936f60d1353fbbc10328c9 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Tue, 17 May 2022 17:40:44 -0400 Subject: [PATCH 05/17] [ci] wip - remove 7.x tests --- .github/workflows/ci.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index dfb42ded7..90146d0e0 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -22,7 +22,7 @@ jobs: fail-fast: false matrix: php-version: - - '7.4' + - '8.0' steps: - @@ -99,11 +99,11 @@ jobs: allow-dev-deps-in-apps: ['0'] include: # testing lowest PHP version with LTS - - php-version: '7.2.5' + - php-version: '8.0.0' symfony-version: '5.4.*' dependency-versions: 'lowest' # testing lowest php version with highest 5.x stable - - php-version: '7.2.5' + - php-version: '8.0.0' symfony-version: '5.4.*' dependency-versions: 'highest' # testing bleeding edge PHP with highest 5.x stable From e257e7f669982a7efb02f4577f2f6f2574bdf9ce Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Tue, 17 May 2022 17:46:13 -0400 Subject: [PATCH 06/17] [internal][make-crud] remove legacy 7.4 tests --- tests/Maker/MakeCrudTest.php | 24 ++--- .../legacy/SweetFood-custom-namespace.php | 44 --------- tests/fixtures/make-crud/legacy/SweetFood.php | 44 --------- .../legacy/SweetFoodCustomRepository.php | 45 ---------- .../make-crud/legacy/SweetFoodRepository.php | 41 --------- .../legacy/expected/WithCustomRepository.php | 90 ------------------- 6 files changed, 8 insertions(+), 280 deletions(-) delete mode 100644 tests/fixtures/make-crud/legacy/SweetFood-custom-namespace.php delete mode 100644 tests/fixtures/make-crud/legacy/SweetFood.php delete mode 100644 tests/fixtures/make-crud/legacy/SweetFoodCustomRepository.php delete mode 100644 tests/fixtures/make-crud/legacy/SweetFoodRepository.php delete mode 100644 tests/fixtures/make-crud/legacy/expected/WithCustomRepository.php diff --git a/tests/Maker/MakeCrudTest.php b/tests/Maker/MakeCrudTest.php index 5d81d1eaf..9e6081740 100644 --- a/tests/Maker/MakeCrudTest.php +++ b/tests/Maker/MakeCrudTest.php @@ -30,7 +30,7 @@ public function getTestDetails(): \Generator yield 'it_generates_basic_crud' => [$this->createMakerTest() ->run(function (MakerTestRunner $runner) { $runner->copy( - $this->getFixturePath('SweetFood.php', $runner), + 'make-crud/SweetFood.php', 'src/Entity/SweetFood.php' ); @@ -50,7 +50,7 @@ public function getTestDetails(): \Generator yield 'it_generates_crud_with_custom_controller' => [$this->createMakerTest() ->run(function (MakerTestRunner $runner) { $runner->copy( - $this->getFixturePath('SweetFood.php', $runner), + 'make-crud/SweetFood.php', 'src/Entity/SweetFood.php' ); @@ -71,7 +71,7 @@ public function getTestDetails(): \Generator ->addExtraDependencies('symfony/test-pack') ->run(function (MakerTestRunner $runner) { $runner->copy( - $this->getFixturePath('SweetFood.php', $runner), + 'make-crud/SweetFood.php', 'src/Entity/SweetFood.php' ); @@ -93,7 +93,7 @@ public function getTestDetails(): \Generator ->addExtraDependencies('symfony/test-pack') ->run(function (MakerTestRunner $runner) { $runner->copy( - $this->getFixturePath('SweetFoodCustomRepository.php', $runner), + 'make-crud/SweetFoodCustomRepository.php', 'src/Entity/SweetFood.php' ); @@ -125,7 +125,7 @@ public function getTestDetails(): \Generator ); $runner->copy( - $this->getFixturePath('SweetFood-custom-namespace.php', $runner), + 'make-crud/SweetFood-custom-namespace.php', 'src/Entity/SweetFood.php' ); @@ -145,7 +145,7 @@ public function getTestDetails(): \Generator yield 'it_generates_crud_using_custom_repository' => [$this->createMakerTest() ->run(function (MakerTestRunner $runner) { $runner->copy( - $this->getFixturePath('SweetFoodCustomRepository.php', $runner), + 'make-crud/SweetFoodCustomRepository.php', 'src/Entity/SweetFood.php' ); $runner->copy( @@ -165,7 +165,7 @@ public function getTestDetails(): \Generator $this->runCrudTest($runner, 'it_generates_basic_crud.php'); self::assertFileEquals( - sprintf('%s/fixtures/%s', \dirname(__DIR__), $this->getFixturePath('expected/WithCustomRepository.php', $runner)), + sprintf('%s/fixtures/%s', \dirname(__DIR__), 'make-crud/expected/WithCustomRepository.php'), $runner->getPath('src/Controller/SweetFoodController.php') ); }), @@ -174,7 +174,7 @@ public function getTestDetails(): \Generator yield 'it_generates_crud_with_no_base_template' => [$this->createMakerTest() ->run(function (MakerTestRunner $runner) { $runner->copy( - $this->getFixturePath('SweetFood.php', $runner), + 'make-crud/SweetFood.php', 'src/Entity/SweetFood.php' ); @@ -194,14 +194,6 @@ public function getTestDetails(): \Generator ]; } - // @legacy - remove when annotations are no longer supported - private function getFixturePath(string $sourceName, MakerTestRunner $runner): string - { - $path = $this->useAttributes($runner) ? 'make-crud' : 'make-crud/legacy'; - - return sprintf('%s/%s', $path, $sourceName); - } - private function runCrudTest(MakerTestRunner $runner, string $filename): void { $runner->copy( diff --git a/tests/fixtures/make-crud/legacy/SweetFood-custom-namespace.php b/tests/fixtures/make-crud/legacy/SweetFood-custom-namespace.php deleted file mode 100644 index e29011735..000000000 --- a/tests/fixtures/make-crud/legacy/SweetFood-custom-namespace.php +++ /dev/null @@ -1,44 +0,0 @@ -id; - } - - /** - * @return mixed - */ - public function getTitle() - { - return $this->title; - } - - /** - * @param mixed $title - */ - public function setTitle($title) - { - $this->title = $title; - } -} diff --git a/tests/fixtures/make-crud/legacy/SweetFood.php b/tests/fixtures/make-crud/legacy/SweetFood.php deleted file mode 100644 index 66590eaf7..000000000 --- a/tests/fixtures/make-crud/legacy/SweetFood.php +++ /dev/null @@ -1,44 +0,0 @@ -id; - } - - /** - * @return mixed - */ - public function getTitle() - { - return $this->title; - } - - /** - * @param mixed $title - */ - public function setTitle($title) - { - $this->title = $title; - } -} diff --git a/tests/fixtures/make-crud/legacy/SweetFoodCustomRepository.php b/tests/fixtures/make-crud/legacy/SweetFoodCustomRepository.php deleted file mode 100644 index 2d27b6854..000000000 --- a/tests/fixtures/make-crud/legacy/SweetFoodCustomRepository.php +++ /dev/null @@ -1,45 +0,0 @@ -id; - } - - /** - * @return mixed - */ - public function getTitle() - { - return $this->title; - } - - /** - * @param mixed $title - */ - public function setTitle($title) - { - $this->title = $title; - } -} diff --git a/tests/fixtures/make-crud/legacy/SweetFoodRepository.php b/tests/fixtures/make-crud/legacy/SweetFoodRepository.php deleted file mode 100644 index 71e7e0a45..000000000 --- a/tests/fixtures/make-crud/legacy/SweetFoodRepository.php +++ /dev/null @@ -1,41 +0,0 @@ - - * - * @method SweetFood|null find($id, $lockMode = null, $lockVersion = null) - * @method SweetFood|null findOneBy(array $criteria, array $orderBy = null) - * @method SweetFood[] findAll() - * @method SweetFood[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) - */ -class SweetFoodRepository extends ServiceEntityRepository -{ - public function __construct(ManagerRegistry $registry) - { - parent::__construct($registry, SweetFood::class); - } - - public function add(SweetFood $entity, bool $flush = false): void - { - ($em = $this->getEntityManager())->persist($entity); - - if ($flush) { - $em->flush(); - } - } - - public function remove(SweetFood $entity, bool $flush = false): void - { - ($em = $this->getEntityManager())->remove($entity); - - if ($flush) { - $em->flush(); - } - } -} diff --git a/tests/fixtures/make-crud/legacy/expected/WithCustomRepository.php b/tests/fixtures/make-crud/legacy/expected/WithCustomRepository.php deleted file mode 100644 index 53e90a985..000000000 --- a/tests/fixtures/make-crud/legacy/expected/WithCustomRepository.php +++ /dev/null @@ -1,90 +0,0 @@ -render('sweet_food/index.html.twig', [ - 'sweet_foods' => $sweetFoodRepository->findAll(), - ]); - } - - /** - * @Route("/new", name="app_sweet_food_new", methods={"GET", "POST"}) - */ - public function new(Request $request, SweetFoodRepository $sweetFoodRepository): Response - { - $sweetFood = new SweetFood(); - $form = $this->createForm(SweetFoodType::class, $sweetFood); - $form->handleRequest($request); - - if ($form->isSubmitted() && $form->isValid()) { - $sweetFoodRepository->add($sweetFood, true); - - return $this->redirectToRoute('app_sweet_food_index', [], Response::HTTP_SEE_OTHER); - } - - return $this->renderForm('sweet_food/new.html.twig', [ - 'sweet_food' => $sweetFood, - 'form' => $form, - ]); - } - - /** - * @Route("/{id}", name="app_sweet_food_show", methods={"GET"}) - */ - public function show(SweetFood $sweetFood): Response - { - return $this->render('sweet_food/show.html.twig', [ - 'sweet_food' => $sweetFood, - ]); - } - - /** - * @Route("/{id}/edit", name="app_sweet_food_edit", methods={"GET", "POST"}) - */ - public function edit(Request $request, SweetFood $sweetFood, SweetFoodRepository $sweetFoodRepository): Response - { - $form = $this->createForm(SweetFoodType::class, $sweetFood); - $form->handleRequest($request); - - if ($form->isSubmitted() && $form->isValid()) { - $sweetFoodRepository->add($sweetFood, true); - - return $this->redirectToRoute('app_sweet_food_index', [], Response::HTTP_SEE_OTHER); - } - - return $this->renderForm('sweet_food/edit.html.twig', [ - 'sweet_food' => $sweetFood, - 'form' => $form, - ]); - } - - /** - * @Route("/{id}", name="app_sweet_food_delete", methods={"POST"}) - */ - public function delete(Request $request, SweetFood $sweetFood, SweetFoodRepository $sweetFoodRepository): Response - { - if ($this->isCsrfTokenValid('delete'.$sweetFood->getId(), $request->request->get('_token'))) { - $sweetFoodRepository->remove($sweetFood, true); - } - - return $this->redirectToRoute('app_sweet_food_index', [], Response::HTTP_SEE_OTHER); - } -} From 21f4862fccf56a94e273942a71bdf9d5df99e4a4 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Tue, 17 May 2022 17:46:54 -0400 Subject: [PATCH 07/17] [internal][make-command] remove legacy 7.4 conditionals --- tests/Maker/MakeCommandTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/Maker/MakeCommandTest.php b/tests/Maker/MakeCommandTest.php index 18f4e5e9e..1ff279c19 100644 --- a/tests/Maker/MakeCommandTest.php +++ b/tests/Maker/MakeCommandTest.php @@ -26,7 +26,6 @@ protected function getMakerClass(): string public function getTestDetails(): \Generator { yield 'it_makes_a_command_no_attributes' => [$this->createMakerTest() - ->setRequiredPhpVersion(80000) ->run(function (MakerTestRunner $runner) { $runner->runMaker([ // command name @@ -38,7 +37,6 @@ public function getTestDetails(): \Generator ]; yield 'it_makes_a_command_with_attributes' => [$this->createMakerTest() - ->setRequiredPhpVersion(80000) ->run(function (MakerTestRunner $runner) { $runner->runMaker([ // command name From 2417e8a6b1a39079ecec97c5fa6320566dd1d151 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Tue, 17 May 2022 17:50:17 -0400 Subject: [PATCH 08/17] [internal][make:entity] remove annotation tests --- tests/Maker/MakeEntityTest.php | 16 ++---- .../entities/annotations/User-basic.php | 48 ----------------- .../annotations/User-custom-namespace.php | 53 ------------------- .../User-invalid-method-no-property.php | 28 ---------- .../annotations/User-invalid-method.php | 33 ------------ .../annotations/UserAvatarPhoto-basic.php | 23 -------- .../annotations/src/Entity/Food.php | 28 ---------- .../annotations/src/Entity/Recipe.php | 21 -------- .../annotations/src/Entity/Currency.php | 41 -------------- .../annotations/src/Entity/Invoice.php | 28 ---------- .../annotations/src/Entity/Money.php | 27 ---------- .../annotations/src/Entity/User.php | 48 ----------------- .../annotations/src/Entity/UserAvatar.php | 29 ---------- 13 files changed, 4 insertions(+), 419 deletions(-) delete mode 100644 tests/fixtures/make-entity/entities/annotations/User-basic.php delete mode 100644 tests/fixtures/make-entity/entities/annotations/User-custom-namespace.php delete mode 100644 tests/fixtures/make-entity/entities/annotations/User-invalid-method-no-property.php delete mode 100644 tests/fixtures/make-entity/entities/annotations/User-invalid-method.php delete mode 100644 tests/fixtures/make-entity/entities/annotations/UserAvatarPhoto-basic.php delete mode 100644 tests/fixtures/make-entity/regenerate-embeddable/annotations/src/Entity/Food.php delete mode 100644 tests/fixtures/make-entity/regenerate-embeddable/annotations/src/Entity/Recipe.php delete mode 100644 tests/fixtures/make-entity/regenerate-embedded/annotations/src/Entity/Currency.php delete mode 100644 tests/fixtures/make-entity/regenerate-embedded/annotations/src/Entity/Invoice.php delete mode 100644 tests/fixtures/make-entity/regenerate-embedded/annotations/src/Entity/Money.php delete mode 100644 tests/fixtures/make-entity/regenerate/annotations/src/Entity/User.php delete mode 100644 tests/fixtures/make-entity/regenerate/annotations/src/Entity/UserAvatar.php diff --git a/tests/Maker/MakeEntityTest.php b/tests/Maker/MakeEntityTest.php index b4a2c8750..9ab814f5f 100644 --- a/tests/Maker/MakeEntityTest.php +++ b/tests/Maker/MakeEntityTest.php @@ -90,7 +90,7 @@ public function getTestDetails(): \Generator $content = file_get_contents($runner->getPath('src/Entity/User.php')); $this->assertStringContainsString('use ApiPlatform\Core\Annotation\ApiResource;', $content); - $this->assertStringContainsString($this->useAttributes($runner) ? '#[ApiResource]' : '@ApiResource', $content); + $this->assertStringContainsString('#[ApiResource]', $content); $this->runEntityTest($runner); }), @@ -587,7 +587,7 @@ public function getTestDetails(): \Generator $content = file_get_contents($runner->getPath('src/Entity/User.php')); $this->assertStringContainsString('use Symfony\UX\Turbo\Attribute\Broadcast;', $content); - $this->assertStringContainsString($this->useAttributes($runner) ? '#[Broadcast]' : '@Broadcast', $content); + $this->assertStringContainsString('#[Broadcast]', $content); $skipMercureTest = $_SERVER['MAKER_SKIP_MERCURE_TEST'] ?? false; if (!$skipMercureTest) { @@ -681,11 +681,7 @@ private function copyEntity(MakerTestRunner $runner, string $filename): void ); $runner->copy( - sprintf( - 'make-entity/entities/%s/%s', - $this->useAttributes($runner) ? 'attributes' : 'annotations', - $filename - ), + sprintf('make-entity/entities/attributes/%s', $filename), sprintf('src/Entity/%s.php', $entityClassName) ); } @@ -693,11 +689,7 @@ private function copyEntity(MakerTestRunner $runner, string $filename): void private function copyEntityDirectory(MakerTestRunner $runner, string $directory): void { $runner->copy( - sprintf( - 'make-entity/%s/%s', - $directory, - $this->useAttributes($runner) ? 'attributes' : 'annotations' - ), + sprintf('make-entity/%s/attributes', $directory), '' ); } diff --git a/tests/fixtures/make-entity/entities/annotations/User-basic.php b/tests/fixtures/make-entity/entities/annotations/User-basic.php deleted file mode 100644 index ab0180a14..000000000 --- a/tests/fixtures/make-entity/entities/annotations/User-basic.php +++ /dev/null @@ -1,48 +0,0 @@ -id; - } - - public function getFirstName(): string - { - return $this->firstName; - } - - public function setFirstName(?string $firstName) - { - $this->firstName = $firstName; - } - - public function getCreatedAt(): ?\DateTimeInterface - { - return $this->createdAt; - } - - public function setCreatedAt(?\DateTimeInterface $createdAt) - { - $this->createdAt = $createdAt; - } -} diff --git a/tests/fixtures/make-entity/entities/annotations/User-custom-namespace.php b/tests/fixtures/make-entity/entities/annotations/User-custom-namespace.php deleted file mode 100644 index 754d4f658..000000000 --- a/tests/fixtures/make-entity/entities/annotations/User-custom-namespace.php +++ /dev/null @@ -1,53 +0,0 @@ -id; - } - - public function getFirstName() - { - return $this->firstName; - } - - public function setFirstName(?string $firstName) - { - $this->firstName = $firstName; - } - - public function getCreatedAt(): ?\DateTimeInterface - { - return $this->createdAt; - } - - public function setCreatedAt(?\DateTimeInterface $createdAt) - { - $this->createdAt = $createdAt; - } -} diff --git a/tests/fixtures/make-entity/entities/annotations/User-invalid-method-no-property.php b/tests/fixtures/make-entity/entities/annotations/User-invalid-method-no-property.php deleted file mode 100644 index fda6e89ce..000000000 --- a/tests/fixtures/make-entity/entities/annotations/User-invalid-method-no-property.php +++ /dev/null @@ -1,28 +0,0 @@ -id; - } - - public function setFirstName() - { - throw new \Exception('This does not work!'); - } -} diff --git a/tests/fixtures/make-entity/entities/annotations/User-invalid-method.php b/tests/fixtures/make-entity/entities/annotations/User-invalid-method.php deleted file mode 100644 index 27599b8e1..000000000 --- a/tests/fixtures/make-entity/entities/annotations/User-invalid-method.php +++ /dev/null @@ -1,33 +0,0 @@ -id; - } - - public function setFirstName() - { - throw new \Exception('This does not work!'); - } -} diff --git a/tests/fixtures/make-entity/entities/annotations/UserAvatarPhoto-basic.php b/tests/fixtures/make-entity/entities/annotations/UserAvatarPhoto-basic.php deleted file mode 100644 index 9d162f108..000000000 --- a/tests/fixtures/make-entity/entities/annotations/UserAvatarPhoto-basic.php +++ /dev/null @@ -1,23 +0,0 @@ -id; - } -} diff --git a/tests/fixtures/make-entity/regenerate-embeddable/annotations/src/Entity/Food.php b/tests/fixtures/make-entity/regenerate-embeddable/annotations/src/Entity/Food.php deleted file mode 100644 index ec3528443..000000000 --- a/tests/fixtures/make-entity/regenerate-embeddable/annotations/src/Entity/Food.php +++ /dev/null @@ -1,28 +0,0 @@ -currency = $currency; - } - - /** - * @return string - */ - public function getCurrency() - { - return $this->currency; - } - - /** - * @param string $currency - * - * @return Currency - */ - public function setCurrency($currency) - { - $this->currency = $currency; - - return $this; - } -} diff --git a/tests/fixtures/make-entity/regenerate-embedded/annotations/src/Entity/Invoice.php b/tests/fixtures/make-entity/regenerate-embedded/annotations/src/Entity/Invoice.php deleted file mode 100644 index 600307a78..000000000 --- a/tests/fixtures/make-entity/regenerate-embedded/annotations/src/Entity/Invoice.php +++ /dev/null @@ -1,28 +0,0 @@ -amount = $amount; - $this->currency = $currency ?? new Currency(); - } -} diff --git a/tests/fixtures/make-entity/regenerate/annotations/src/Entity/User.php b/tests/fixtures/make-entity/regenerate/annotations/src/Entity/User.php deleted file mode 100644 index b2e420f2d..000000000 --- a/tests/fixtures/make-entity/regenerate/annotations/src/Entity/User.php +++ /dev/null @@ -1,48 +0,0 @@ -id; - } - - public function getFirstName() - { - return $this->firstName; - } - - public function getCreatedAt(): ?\DateTimeInterface - { - return $this->createdAt; - } -} diff --git a/tests/fixtures/make-entity/regenerate/annotations/src/Entity/UserAvatar.php b/tests/fixtures/make-entity/regenerate/annotations/src/Entity/UserAvatar.php deleted file mode 100644 index a922a87ef..000000000 --- a/tests/fixtures/make-entity/regenerate/annotations/src/Entity/UserAvatar.php +++ /dev/null @@ -1,29 +0,0 @@ -id; - } -} From 53d2b55a50db0d0feacd43ed34bc8c5d732b4a01 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Tue, 17 May 2022 17:50:39 -0400 Subject: [PATCH 09/17] [internal][make:reset-password] remove annotation tests --- tests/Maker/MakeResetPasswordTest.php | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/tests/Maker/MakeResetPasswordTest.php b/tests/Maker/MakeResetPasswordTest.php index 637c0e590..d1debee82 100644 --- a/tests/Maker/MakeResetPasswordTest.php +++ b/tests/Maker/MakeResetPasswordTest.php @@ -173,12 +173,7 @@ public function getTestDetails(): \Generator // check ResetPasswordRequest $contentResetPasswordRequest = file_get_contents($runner->getPath('src/Entity/ResetPasswordRequest.php')); - /* @legacy Drop annotation test when annotations are no longer supported. */ - if ($this->useAttributes($runner)) { - $this->assertStringContainsString('ORM\ManyToOne(targetEntity: UserCustom::class)', $contentResetPasswordRequest); - } else { - $this->assertStringContainsString('ORM\ManyToOne(targetEntity=UserCustom::class)', $contentResetPasswordRequest); - } + $this->assertStringContainsString('ORM\ManyToOne(targetEntity: UserCustom::class)', $contentResetPasswordRequest); // check ResetPasswordRequestFormType $contentResetPasswordRequestFormType = file_get_contents($runner->getPath('/src/Form/ResetPasswordRequestFormType.php')); @@ -216,11 +211,4 @@ private function makeUser(MakerTestRunner $runner, string $identifier = 'email', $checkPassword ? 'y' : 'n', // password ]); } - - private function useAttributes(MakerTestRunner $runner): bool - { - return \PHP_VERSION_ID >= 80000 - && $runner->doesClassExist(AttributeReader::class) - && $runner->getSymfonyVersion() >= 50200; - } } From d99e159ff19574348c0db0b5a789c64cfdb76204 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Tue, 17 May 2022 17:58:52 -0400 Subject: [PATCH 10/17] ci fixes --- appveyor.yml | 2 +- tests/Maker/MakeResetPasswordTest.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 14aea3ddc..795cc5ea6 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -27,7 +27,7 @@ environment: TEST_DATABASE_DSN: mysql://root:Password12!@127.0.0.1:3306/test_maker matrix: - dependencies: highest - php_ver_target: 7.2.5 + php_ver_target: 8.0.0 install: - ps: Set-Service wuauserv -StartupType Manual diff --git a/tests/Maker/MakeResetPasswordTest.php b/tests/Maker/MakeResetPasswordTest.php index d1debee82..88981ceaf 100644 --- a/tests/Maker/MakeResetPasswordTest.php +++ b/tests/Maker/MakeResetPasswordTest.php @@ -11,7 +11,6 @@ namespace Symfony\Bundle\MakerBundle\Tests\Maker; -use Doctrine\ORM\Mapping\Driver\AttributeReader; use Symfony\Bundle\MakerBundle\Maker\MakeResetPassword; use Symfony\Bundle\MakerBundle\Test\MakerTestCase; use Symfony\Bundle\MakerBundle\Test\MakerTestRunner; From 5d92164887c2079564b3c73f12aee03892672bbf Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Tue, 17 May 2022 18:05:59 -0400 Subject: [PATCH 11/17] [internal] WIP - remove legacy compat methods --- src/Util/PhpCompatUtil.php | 25 +++++++++++-------------- tests/Util/PhpVersionTest.php | 5 +++++ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Util/PhpCompatUtil.php b/src/Util/PhpCompatUtil.php index b6d0843af..e86a991ca 100644 --- a/src/Util/PhpCompatUtil.php +++ b/src/Util/PhpCompatUtil.php @@ -20,33 +20,30 @@ */ class PhpCompatUtil { - /** @var FileManager */ - private $fileManager; - - public function __construct(FileManager $fileManager) + public function __construct(private FileManager $fileManager) { - $this->fileManager = $fileManager; + @trigger_deprecation('symfony/maker-bundle', '0.0.0', 'This utility is no longer being used. It may be removed in a future version.'); } + // @TODO - Remove before merge public function canUseAttributes(): bool { - $version = $this->getPhpVersion(); - - return version_compare($version, '8alpha', '>='); + @trigger_error('This method is no longer needed.'); + return true; } + // @TODO - Remove before merge public function canUseTypedProperties(): bool { - $version = $this->getPhpVersion(); - - return version_compare($version, '7.4', '>='); + @trigger_error('This method is no longer needed.'); + return true; } + // @TODO - Remove before merge public function canUseUnionTypes(): bool { - $version = $this->getPhpVersion(); - - return version_compare($version, '8alpha', '>='); + @trigger_error('This method is no longer needed.'); + return true; } protected function getPhpVersion(): string diff --git a/tests/Util/PhpVersionTest.php b/tests/Util/PhpVersionTest.php index c5c1ccbbf..69f5aecd5 100644 --- a/tests/Util/PhpVersionTest.php +++ b/tests/Util/PhpVersionTest.php @@ -26,6 +26,7 @@ class PhpVersionTest extends TestCase */ public function testUsesPhpPlatformFromComposerJsonFileForCanUseAttributes(string $version, bool $expectedResult): void { + $this->markTestSkipped('No longer needed. Remove me before merge.'); $mockFileManager = $this->mockFileManager(sprintf('{"platform-overrides": {"php": "%s"}}', $version)); $version = new PhpCompatUtil($mockFileManager); @@ -103,6 +104,8 @@ public function testWithoutPlatformVersionSet(): void */ public function testCanUseTypedProperties(string $version, bool $expectedResult): void { + $this->markTestSkipped('No longer needed. Remove me before merge.'); + $mockFileManager = $this->mockFileManager(sprintf('{"platform-overrides": {"php": "%s"}}', $version)); $version = new PhpCompatUtil($mockFileManager); @@ -129,6 +132,8 @@ public function phpVersionForTypedPropertiesDataProvider(): \Generator */ public function testCanUseUnionTypes(string $version, bool $expectedResult): void { + $this->markTestSkipped('No longer needed. Remove me before merge.'); + $mockFileManager = $this->mockFileManager(sprintf('{"platform-overrides": {"php": "%s"}}', $version)); $version = new PhpCompatUtil($mockFileManager); From 71830c453473905547bf0c31cd49dc8d6bbab3b7 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Wed, 18 May 2022 12:06:23 -0400 Subject: [PATCH 12/17] fix email verifier property names --- src/Resources/skeleton/verifyEmail/EmailVerifier.tpl.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Resources/skeleton/verifyEmail/EmailVerifier.tpl.php b/src/Resources/skeleton/verifyEmail/EmailVerifier.tpl.php index 24c649aee..9931d935f 100644 --- a/src/Resources/skeleton/verifyEmail/EmailVerifier.tpl.php +++ b/src/Resources/skeleton/verifyEmail/EmailVerifier.tpl.php @@ -7,9 +7,9 @@ class { public function __construct( - private VerifyEmailHelperInterface $helper, + private VerifyEmailHelperInterface $verifyEmailHelper, private MailerInterface $mailer, - private EntityManagerInterface $manager + private EntityManagerInterface $entityManager ) { } From 4760a70780b46260066e24e208d2bb2411ef8316 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Wed, 18 May 2022 12:32:42 -0400 Subject: [PATCH 13/17] remove legacy phpcompat methods --- src/Doctrine/DoctrineHelper.php | 2 +- src/Generator.php | 3 - src/Maker/MakeCommand.php | 5 +- src/Maker/MakeController.php | 2 +- src/Maker/MakeEntity.php | 4 -- .../skeleton/doctrine/Entity.tpl.php | 10 +--- src/Security/SecurityControllerBuilder.php | 24 +------- src/Util/PhpCompatUtil.php | 21 ------- src/Util/TemplateComponentGenerator.php | 4 -- .../SecurityControllerBuilderTest.php | 58 +++++++++---------- tests/Util/PhpVersionTest.php | 6 +- 11 files changed, 39 insertions(+), 100 deletions(-) diff --git a/src/Doctrine/DoctrineHelper.php b/src/Doctrine/DoctrineHelper.php index 93e7d8466..b5f7fb55c 100644 --- a/src/Doctrine/DoctrineHelper.php +++ b/src/Doctrine/DoctrineHelper.php @@ -145,7 +145,7 @@ public function doesClassUsesAttributes(string $className): bool public function isDoctrineSupportingAttributes(): bool { - return $this->isDoctrineInstalled() && $this->attributeMappingSupport && $this->phpCompatUtil->canUseAttributes(); + return $this->isDoctrineInstalled() && $this->attributeMappingSupport; } public function getEntitiesForAutocomplete(): array diff --git a/src/Generator.php b/src/Generator.php index 3c0fe271a..28ac09a9e 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -170,9 +170,6 @@ private function addOperation(string $targetPath, string $templateName, array $v } $variables['relative_path'] = $this->fileManager->relativizePath($targetPath); - $variables['use_attributes'] = $this->phpCompatUtil->canUseAttributes(); - $variables['use_typed_properties'] = $this->phpCompatUtil->canUseTypedProperties(); - $variables['use_union_types'] = $this->phpCompatUtil->canUseUnionTypes(); $templatePath = $templateName; if (!file_exists($templatePath)) { diff --git a/src/Maker/MakeCommand.php b/src/Maker/MakeCommand.php index 5ab22e461..1773df4aa 100644 --- a/src/Maker/MakeCommand.php +++ b/src/Maker/MakeCommand.php @@ -74,12 +74,9 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen InputOption::class, OutputInterface::class, SymfonyStyle::class, + AsCommand::class, ]); - if ($this->phpCompatUtil->canUseAttributes()) { - $useStatements->addUseStatement(AsCommand::class); - } - $generator->generateClass( $commandClassNameDetails->getFullName(), 'command/Command.tpl.php', diff --git a/src/Maker/MakeController.php b/src/Maker/MakeController.php index 7fac2defe..e5a8f78db 100644 --- a/src/Maker/MakeController.php +++ b/src/Maker/MakeController.php @@ -116,7 +116,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen public function configureDependencies(DependencyBuilder $dependencies): void { // @legacy - Remove method when support for Symfony 5.4 is dropped - if (null !== $this->phpCompatUtil && 60000 <= Kernel::VERSION_ID && $this->phpCompatUtil->canUseAttributes()) { + if (null !== $this->phpCompatUtil && 60000 <= Kernel::VERSION_ID) { return; } diff --git a/src/Maker/MakeEntity.php b/src/Maker/MakeEntity.php index 6bb6ab5d6..9784c029a 100644 --- a/src/Maker/MakeEntity.php +++ b/src/Maker/MakeEntity.php @@ -872,10 +872,6 @@ private function doesEntityUseAnnotationMapping(string $className): bool /** @legacy Drop when Annotations are no longer supported */ private function doesEntityUseAttributeMapping(string $className): bool { - if (!$this->phpCompatUtil->canUseAttributes()) { - return false; - } - if (!class_exists($className)) { $otherClassMetadatas = $this->doctrineHelper->getMetadata(Str::getNamespace($className).'\\', true); diff --git a/src/Resources/skeleton/doctrine/Entity.tpl.php b/src/Resources/skeleton/doctrine/Entity.tpl.php index 636f81da5..0209f2eac 100644 --- a/src/Resources/skeleton/doctrine/Entity.tpl.php +++ b/src/Resources/skeleton/doctrine/Entity.tpl.php @@ -4,12 +4,8 @@ - + /** - * @ApiResource() - - * @Broadcast() - * @ORM\Entity(repositoryClass=::class) * @ORM\Table(name="``") @@ -20,10 +16,10 @@ #[ORM\Table(name: '``')] - + #[ApiResource] - + #[Broadcast] class diff --git a/src/Security/SecurityControllerBuilder.php b/src/Security/SecurityControllerBuilder.php index 84abe0829..6123c401d 100644 --- a/src/Security/SecurityControllerBuilder.php +++ b/src/Security/SecurityControllerBuilder.php @@ -33,17 +33,7 @@ public function addLoginMethod(ClassSourceManipulator $manipulator): void { $loginMethodBuilder = $manipulator->createMethodBuilder('login', 'Response', false); - // @legacy Refactor when annotations are no longer supported - if ($this->phpCompatUtil->canUseAttributes()) { - $loginMethodBuilder->addAttribute($manipulator->buildAttributeNode(Route::class, ['path' => '/login', 'name' => 'app_login'])); - } else { - $loginMethodBuilder->setDocComment(<<< 'EOT' -/** - * @Route("/login", name="app_login") - */ -EOT - ); - } + $loginMethodBuilder->addAttribute($manipulator->buildAttributeNode(Route::class, ['path' => '/login', 'name' => 'app_login'])); $manipulator->addUseStatementIfNecessary(Response::class); $manipulator->addUseStatementIfNecessary(Route::class); @@ -88,17 +78,7 @@ public function addLogoutMethod(ClassSourceManipulator $manipulator): void { $logoutMethodBuilder = $manipulator->createMethodBuilder('logout', 'void', false); - // @legacy Refactor when annotations are no longer supported - if ($this->phpCompatUtil->canUseAttributes()) { - $logoutMethodBuilder->addAttribute($manipulator->buildAttributeNode(Route::class, ['path' => '/logout', 'name' => 'app_logout'])); - } else { - $logoutMethodBuilder->setDocComment(<<< 'EOT' -/** - * @Route("/logout", name="app_logout") - */ -EOT - ); - } + $logoutMethodBuilder->addAttribute($manipulator->buildAttributeNode(Route::class, ['path' => '/logout', 'name' => 'app_logout'])); $manipulator->addUseStatementIfNecessary(Route::class); $manipulator->addMethodBody($logoutMethodBuilder, <<<'CODE' diff --git a/src/Util/PhpCompatUtil.php b/src/Util/PhpCompatUtil.php index e86a991ca..73083748a 100644 --- a/src/Util/PhpCompatUtil.php +++ b/src/Util/PhpCompatUtil.php @@ -25,27 +25,6 @@ public function __construct(private FileManager $fileManager) @trigger_deprecation('symfony/maker-bundle', '0.0.0', 'This utility is no longer being used. It may be removed in a future version.'); } - // @TODO - Remove before merge - public function canUseAttributes(): bool - { - @trigger_error('This method is no longer needed.'); - return true; - } - - // @TODO - Remove before merge - public function canUseTypedProperties(): bool - { - @trigger_error('This method is no longer needed.'); - return true; - } - - // @TODO - Remove before merge - public function canUseUnionTypes(): bool - { - @trigger_error('This method is no longer needed.'); - return true; - } - protected function getPhpVersion(): string { $rootDirectory = $this->fileManager->getRootDirectory(); diff --git a/src/Util/TemplateComponentGenerator.php b/src/Util/TemplateComponentGenerator.php index bbea3c004..0f4e444dd 100644 --- a/src/Util/TemplateComponentGenerator.php +++ b/src/Util/TemplateComponentGenerator.php @@ -51,10 +51,6 @@ public function generateRouteForControllerMethod(string $routePath, string $rout public function getPropertyType(ClassNameDetails $classNameDetails): ?string { - if (!$this->phpCompatUtil->canUseTypedProperties()) { - return null; - } - return sprintf('%s ', $classNameDetails->getShortName()); } diff --git a/tests/Security/SecurityControllerBuilderTest.php b/tests/Security/SecurityControllerBuilderTest.php index 92186eae9..39cb624e0 100644 --- a/tests/Security/SecurityControllerBuilderTest.php +++ b/tests/Security/SecurityControllerBuilderTest.php @@ -23,16 +23,15 @@ class SecurityControllerBuilderTest extends TestCase public function testLoginMethod(): void { /* @legacy Can be dropped when PHP 7.x support is dropped in MakerBundle */ - $this->runMethodTest( - 'addLoginMethod', - true, - sprintf('%s/legacy_add_login_method/%s', $this->expectedBasePath, 'SecurityController_login.php') - ); +// $this->runMethodTest( +// 'addLoginMethod', +// true, +// sprintf('%s/legacy_add_login_method/%s', $this->expectedBasePath, 'SecurityController_login.php') +// ); if ((\PHP_VERSION_ID >= 80000)) { $this->runMethodTest( 'addLoginMethod', - false, sprintf('%s/%s', $this->expectedBasePath, 'SecurityController_login.php') ); } @@ -41,16 +40,15 @@ public function testLoginMethod(): void public function testLogoutMethod(): void { /* @legacy Can be dropped when PHP 7.x support is dropped in MakerBundle */ - $this->runMethodTest( - 'addLogoutMethod', - true, - sprintf('%s/legacy_add_logout_method/%s', $this->expectedBasePath, 'SecurityController_logout.php') - ); +// $this->runMethodTest( +// 'addLogoutMethod', +// true, +// sprintf('%s/legacy_add_logout_method/%s', $this->expectedBasePath, 'SecurityController_logout.php') +// ); if ((\PHP_VERSION_ID >= 80000)) { $this->runMethodTest( 'addLogoutMethod', - false, sprintf('%s/%s', $this->expectedBasePath, 'SecurityController_logout.php') ); } @@ -59,19 +57,19 @@ public function testLogoutMethod(): void public function testLoginAndLogoutMethod(): void { /** @legacy Can be dropped when PHP 7.x support is dropped in MakerBundle */ - $builder = $this->getSecurityControllerBuilder(true); - $csm = $this->getClassSourceManipulator(); - - $builder->addLoginMethod($csm); - $builder->addLogoutMethod($csm); - - $this->assertStringEqualsFile( - sprintf('%s/legacy_add_login_logout_method/%s', $this->expectedBasePath, 'SecurityController_login_logout.php'), - $csm->getSourceCode() - ); +// $builder = $this->getSecurityControllerBuilder(true); +// $csm = $this->getClassSourceManipulator(); +// +// $builder->addLoginMethod($csm); +// $builder->addLogoutMethod($csm); +// +// $this->assertStringEqualsFile( +// sprintf('%s/legacy_add_login_logout_method/%s', $this->expectedBasePath, 'SecurityController_login_logout.php'), +// $csm->getSourceCode() +// ); if ((\PHP_VERSION_ID >= 80000)) { - $builder = $this->getSecurityControllerBuilder(false); + $builder = $this->getSecurityControllerBuilder(); $csm = $this->getClassSourceManipulator(); $builder->addLoginMethod($csm); @@ -84,9 +82,9 @@ public function testLoginAndLogoutMethod(): void } } - private function runMethodTest(string $builderMethod, bool $isLegacyTest, string $expectedFilePath): void + private function runMethodTest(string $builderMethod, string $expectedFilePath): void { - $builder = $this->getSecurityControllerBuilder($isLegacyTest); + $builder = $this->getSecurityControllerBuilder(); $csm = $this->getClassSourceManipulator(); $builder->$builderMethod($csm); @@ -98,13 +96,13 @@ private function getClassSourceManipulator(): ClassSourceManipulator return new ClassSourceManipulator(file_get_contents(__DIR__.'/fixtures/source/SecurityController.php')); } - private function getSecurityControllerBuilder(bool $isLegacyTest): SecurityControllerBuilder + private function getSecurityControllerBuilder(): SecurityControllerBuilder { $compatUtil = $this->createMock(PhpCompatUtil::class); - $compatUtil - ->method('canUseAttributes') - ->willReturn(!$isLegacyTest) - ; +// $compatUtil +// ->method('canUseAttributes') +// ->willReturn(!$isLegacyTest) +// ; return new SecurityControllerBuilder($compatUtil); } diff --git a/tests/Util/PhpVersionTest.php b/tests/Util/PhpVersionTest.php index 69f5aecd5..3816d592d 100644 --- a/tests/Util/PhpVersionTest.php +++ b/tests/Util/PhpVersionTest.php @@ -31,7 +31,7 @@ public function testUsesPhpPlatformFromComposerJsonFileForCanUseAttributes(strin $version = new PhpCompatUtil($mockFileManager); - $result = $version->canUseAttributes(); +// $result = $version->canUseAttributes(); /* * Symfony 5.2 is required to compare the result. Otherwise it will always @@ -110,7 +110,7 @@ public function testCanUseTypedProperties(string $version, bool $expectedResult) $version = new PhpCompatUtil($mockFileManager); - $result = $version->canUseTypedProperties(); +// $result = $version->canUseTypedProperties(); self::assertSame($expectedResult, $result); } @@ -138,7 +138,7 @@ public function testCanUseUnionTypes(string $version, bool $expectedResult): voi $version = new PhpCompatUtil($mockFileManager); - $result = $version->canUseUnionTypes(); +// $result = $version->canUseUnionTypes(); self::assertSame($expectedResult, $result); } From f868c371fc5d2dfa986cea2127827372be064d4d Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Wed, 18 May 2022 12:34:21 -0400 Subject: [PATCH 14/17] php-cs-fixer it up --- tests/Security/SecurityControllerBuilderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Security/SecurityControllerBuilderTest.php b/tests/Security/SecurityControllerBuilderTest.php index 39cb624e0..9bcc44b6b 100644 --- a/tests/Security/SecurityControllerBuilderTest.php +++ b/tests/Security/SecurityControllerBuilderTest.php @@ -56,7 +56,7 @@ public function testLogoutMethod(): void public function testLoginAndLogoutMethod(): void { - /** @legacy Can be dropped when PHP 7.x support is dropped in MakerBundle */ + /* @legacy Can be dropped when PHP 7.x support is dropped in MakerBundle */ // $builder = $this->getSecurityControllerBuilder(true); // $csm = $this->getClassSourceManipulator(); // From faa2ca80e9be8059203e8d02b9726b226056e9a4 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Wed, 18 May 2022 12:39:49 -0400 Subject: [PATCH 15/17] cant fully remove the util yet --- src/Util/PhpCompatUtil.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Util/PhpCompatUtil.php b/src/Util/PhpCompatUtil.php index 73083748a..56b662db3 100644 --- a/src/Util/PhpCompatUtil.php +++ b/src/Util/PhpCompatUtil.php @@ -22,7 +22,6 @@ class PhpCompatUtil { public function __construct(private FileManager $fileManager) { - @trigger_deprecation('symfony/maker-bundle', '0.0.0', 'This utility is no longer being used. It may be removed in a future version.'); } protected function getPhpVersion(): string From 76e9e1f47ca7bed5ce47453415509b5aee01ea76 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Wed, 18 May 2022 12:55:18 -0400 Subject: [PATCH 16/17] cleanup some tests --- .../SecurityControllerBuilderTest.php | 74 +++++-------------- .../SecurityController_login_logout.php | 36 --------- .../SecurityController_login.php | 28 ------- .../SecurityController_logout.php | 17 ----- tests/Util/PhpVersionTest.php | 58 +-------------- 5 files changed, 19 insertions(+), 194 deletions(-) delete mode 100644 tests/Security/fixtures/expected/legacy_add_login_logout_method/SecurityController_login_logout.php delete mode 100644 tests/Security/fixtures/expected/legacy_add_login_method/SecurityController_login.php delete mode 100644 tests/Security/fixtures/expected/legacy_add_logout_method/SecurityController_logout.php diff --git a/tests/Security/SecurityControllerBuilderTest.php b/tests/Security/SecurityControllerBuilderTest.php index 9bcc44b6b..b6743b254 100644 --- a/tests/Security/SecurityControllerBuilderTest.php +++ b/tests/Security/SecurityControllerBuilderTest.php @@ -18,68 +18,36 @@ class SecurityControllerBuilderTest extends TestCase { - private $expectedBasePath = __DIR__.'/fixtures/expected'; + private string $expectedBasePath = __DIR__.'/fixtures/expected'; public function testLoginMethod(): void { - /* @legacy Can be dropped when PHP 7.x support is dropped in MakerBundle */ -// $this->runMethodTest( -// 'addLoginMethod', -// true, -// sprintf('%s/legacy_add_login_method/%s', $this->expectedBasePath, 'SecurityController_login.php') -// ); - - if ((\PHP_VERSION_ID >= 80000)) { - $this->runMethodTest( - 'addLoginMethod', - sprintf('%s/%s', $this->expectedBasePath, 'SecurityController_login.php') - ); - } + $this->runMethodTest( + 'addLoginMethod', + sprintf('%s/%s', $this->expectedBasePath, 'SecurityController_login.php') + ); } public function testLogoutMethod(): void { - /* @legacy Can be dropped when PHP 7.x support is dropped in MakerBundle */ -// $this->runMethodTest( -// 'addLogoutMethod', -// true, -// sprintf('%s/legacy_add_logout_method/%s', $this->expectedBasePath, 'SecurityController_logout.php') -// ); - - if ((\PHP_VERSION_ID >= 80000)) { - $this->runMethodTest( - 'addLogoutMethod', - sprintf('%s/%s', $this->expectedBasePath, 'SecurityController_logout.php') - ); - } + $this->runMethodTest( + 'addLogoutMethod', + sprintf('%s/%s', $this->expectedBasePath, 'SecurityController_logout.php') + ); } public function testLoginAndLogoutMethod(): void { - /* @legacy Can be dropped when PHP 7.x support is dropped in MakerBundle */ -// $builder = $this->getSecurityControllerBuilder(true); -// $csm = $this->getClassSourceManipulator(); -// -// $builder->addLoginMethod($csm); -// $builder->addLogoutMethod($csm); -// -// $this->assertStringEqualsFile( -// sprintf('%s/legacy_add_login_logout_method/%s', $this->expectedBasePath, 'SecurityController_login_logout.php'), -// $csm->getSourceCode() -// ); - - if ((\PHP_VERSION_ID >= 80000)) { - $builder = $this->getSecurityControllerBuilder(); - $csm = $this->getClassSourceManipulator(); + $builder = $this->getSecurityControllerBuilder(); + $csm = $this->getClassSourceManipulator(); - $builder->addLoginMethod($csm); - $builder->addLogoutMethod($csm); + $builder->addLoginMethod($csm); + $builder->addLogoutMethod($csm); - $this->assertStringEqualsFile( - sprintf('%s/%s', $this->expectedBasePath, 'SecurityController_login_logout.php'), - $csm->getSourceCode() - ); - } + $this->assertStringEqualsFile( + sprintf('%s/%s', $this->expectedBasePath, 'SecurityController_login_logout.php'), + $csm->getSourceCode() + ); } private function runMethodTest(string $builderMethod, string $expectedFilePath): void @@ -98,12 +66,6 @@ private function getClassSourceManipulator(): ClassSourceManipulator private function getSecurityControllerBuilder(): SecurityControllerBuilder { - $compatUtil = $this->createMock(PhpCompatUtil::class); -// $compatUtil -// ->method('canUseAttributes') -// ->willReturn(!$isLegacyTest) -// ; - - return new SecurityControllerBuilder($compatUtil); + return new SecurityControllerBuilder($this->createMock(PhpCompatUtil::class)); } } diff --git a/tests/Security/fixtures/expected/legacy_add_login_logout_method/SecurityController_login_logout.php b/tests/Security/fixtures/expected/legacy_add_login_logout_method/SecurityController_login_logout.php deleted file mode 100644 index 65c096f8f..000000000 --- a/tests/Security/fixtures/expected/legacy_add_login_logout_method/SecurityController_login_logout.php +++ /dev/null @@ -1,36 +0,0 @@ -getUser()) { - // return $this->redirectToRoute('target_path'); - // } - - // get the login error if there is one - $error = $authenticationUtils->getLastAuthenticationError(); - // last username entered by the user - $lastUsername = $authenticationUtils->getLastUsername(); - - return $this->render('security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]); - } - - /** - * @Route("/logout", name="app_logout") - */ - public function logout(): void - { - throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.'); - } -} diff --git a/tests/Security/fixtures/expected/legacy_add_login_method/SecurityController_login.php b/tests/Security/fixtures/expected/legacy_add_login_method/SecurityController_login.php deleted file mode 100644 index 16608e401..000000000 --- a/tests/Security/fixtures/expected/legacy_add_login_method/SecurityController_login.php +++ /dev/null @@ -1,28 +0,0 @@ -getUser()) { - // return $this->redirectToRoute('target_path'); - // } - - // get the login error if there is one - $error = $authenticationUtils->getLastAuthenticationError(); - // last username entered by the user - $lastUsername = $authenticationUtils->getLastUsername(); - - return $this->render('security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]); - } -} diff --git a/tests/Security/fixtures/expected/legacy_add_logout_method/SecurityController_logout.php b/tests/Security/fixtures/expected/legacy_add_logout_method/SecurityController_logout.php deleted file mode 100644 index 037a1539b..000000000 --- a/tests/Security/fixtures/expected/legacy_add_logout_method/SecurityController_logout.php +++ /dev/null @@ -1,17 +0,0 @@ -markTestSkipped('No longer needed. Remove me before merge.'); + $this->markTestSkipped('This test needs to be refactored if we keep the util.'); $mockFileManager = $this->mockFileManager(sprintf('{"platform-overrides": {"php": "%s"}}', $version)); $version = new PhpCompatUtil($mockFileManager); @@ -99,62 +99,6 @@ public function testWithoutPlatformVersionSet(): void self::assertSame(\PHP_VERSION, $result); } - /** - * @dataProvider phpVersionForTypedPropertiesDataProvider - */ - public function testCanUseTypedProperties(string $version, bool $expectedResult): void - { - $this->markTestSkipped('No longer needed. Remove me before merge.'); - - $mockFileManager = $this->mockFileManager(sprintf('{"platform-overrides": {"php": "%s"}}', $version)); - - $version = new PhpCompatUtil($mockFileManager); - -// $result = $version->canUseTypedProperties(); - - self::assertSame($expectedResult, $result); - } - - public function phpVersionForTypedPropertiesDataProvider(): \Generator - { - yield ['8', true]; - yield ['8.0.1', true]; - yield ['8RC1', true]; - yield ['7.4', true]; - yield ['7.4.6', true]; - yield ['7', false]; - yield ['7.0', false]; - yield ['5.7', false]; - } - - /** - * @dataProvider phpVersionForUnionTypesDataProvider - */ - public function testCanUseUnionTypes(string $version, bool $expectedResult): void - { - $this->markTestSkipped('No longer needed. Remove me before merge.'); - - $mockFileManager = $this->mockFileManager(sprintf('{"platform-overrides": {"php": "%s"}}', $version)); - - $version = new PhpCompatUtil($mockFileManager); - -// $result = $version->canUseUnionTypes(); - - self::assertSame($expectedResult, $result); - } - - public function phpVersionForUnionTypesDataProvider(): \Generator - { - yield ['8', true]; - yield ['8.0.1', true]; - yield ['8RC1', true]; - yield ['7.4', false]; - yield ['7.4.6', false]; - yield ['7', false]; - yield ['7.0', false]; - yield ['5.7', false]; - } - /** * @return \PHPUnit\Framework\MockObject\MockObject|FileManager */ From 699c29db6e081490473a289dc357897f5da67a91 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Wed, 18 May 2022 14:07:09 -0400 Subject: [PATCH 17/17] bump appveyor php version --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 795cc5ea6..492d4a200 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -27,7 +27,7 @@ environment: TEST_DATABASE_DSN: mysql://root:Password12!@127.0.0.1:3306/test_maker matrix: - dependencies: highest - php_ver_target: 8.0.0 + php_ver_target: 8.0.19 install: - ps: Set-Service wuauserv -StartupType Manual