From ed95e276c7657199bbf86c228fe8d554171fcc69 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 12 Nov 2021 20:23:15 -0500 Subject: [PATCH] Refactoring Tests & Various Fixes for Symfony 6 --- .github/workflows/ci.yaml | 39 +- .php-cs-fixer.dist.php | 1 + composer.json | 30 +- src/Console/MigrationDiffFilteredOutput.php | 61 +- .../MigrationDiffFilteredOutput_php8.php | 39 + src/Maker/MakeAuthenticator.php | 27 +- src/Maker/MakeRegistrationForm.php | 16 +- src/Maker/MakeResetPassword.php | 2 + src/Maker/MakeTest.php | 12 +- src/Maker/MakeUser.php | 2 + .../Security52EmptyAuthenticator.tpl.php | 4 +- .../Security52LoginFormAuthenticator.tpl.php | 4 +- .../crud/controller/Controller.tpl.php | 15 +- .../RegistrationController.tpl.php | 11 +- .../ResetPasswordController.tpl.php | 8 +- .../skeleton/security/UserProvider.tpl.php | 9 +- .../skeleton/test/KernelTestCase.tpl.php | 4 +- src/Security/InteractiveSecurityHelper.php | 26 +- src/Security/SecurityConfigUpdater.php | 2 +- src/Test/MakerTestCase.php | 61 +- src/Test/MakerTestDetails.php | 265 +--- src/Test/MakerTestEnvironment.php | 263 ++-- src/Test/MakerTestRunner.php | 260 ++++ src/Util/ClassNameValue.php | 7 +- src/Util/ClassSourceManipulator.php | 6 +- src/Util/TemplateComponentGenerator.php | 8 +- tests/Command/MakerCommandTest.php | 11 +- tests/Docker/DatabaseServicesTest.php | 12 +- tests/Maker/MakeAuthenticatorTest.php | 508 +++---- tests/Maker/MakeCommandTest.php | 89 +- tests/Maker/MakeControllerTest.php | 138 +- tests/Maker/MakeCrudTest.php | 188 ++- tests/Maker/MakeDockerDatabaseTest.php | 170 +-- tests/Maker/MakeEntityLegacyTest.php | 558 -------- tests/Maker/MakeEntityTest.php | 1186 +++++++++-------- tests/Maker/MakeFixturesTest.php | 19 +- tests/Maker/MakeFormTest.php | 140 +- tests/Maker/MakeFunctionalTestTest.php | 42 +- tests/Maker/MakeMessageTest.php | 128 +- tests/Maker/MakeMessengerMiddlewareTest.php | 23 +- tests/Maker/MakeMigrationTest.php | 94 +- tests/Maker/MakeRegistrationFormTest.php | 272 ++-- tests/Maker/MakeResetPasswordTest.php | 302 +++-- tests/Maker/MakeSerializerEncoderTest.php | 26 +- tests/Maker/MakeSerializerNormalizerTest.php | 22 +- tests/Maker/MakeSubscriberTest.php | 45 +- tests/Maker/MakeTestTest.php | 115 +- tests/Maker/MakeTwigExtensionTest.php | 22 +- tests/Maker/MakeUnitTestTest.php | 24 +- tests/Maker/MakeUserTest.php | 135 +- tests/Maker/MakeValidatorTest.php | 22 +- tests/Maker/MakeVoterTest.php | 22 +- tests/Util/TemplateComponentGeneratorTest.php | 4 +- .../User_simple_self.php | 2 +- .../config/packages/security.yaml | 24 - .../config/packages/security.yaml | 27 - .../src/Security/Authenticator.php | 53 - .../config/packages/security.yaml | 29 - .../src/Security/User.php | 90 -- .../src/Security/UserProvider.php | 33 - .../tests/SecurityControllerTest.php | 46 - .../config/packages/security.yaml | 31 - .../src/Entity/User.php | 113 -- .../tests/SecurityControllerTest.php | 55 - .../config/packages/security.yaml | 31 - .../src/Entity/User.php | 113 -- .../config/packages/security.yaml | 31 - .../src/Entity/User.php | 113 -- .../tests/SecurityControllerTest.php | 84 -- .../config/packages/security.yaml | 28 - .../src/Entity/User.php | 113 -- .../tests/SecurityControllerTest.php | 48 - .../config/packages/security.yaml | 29 - .../src/Security/User.php | 90 -- .../src/Security/UserProvider.php | 33 - .../tests/SecurityControllerTest.php | 46 - .../config/packages/security.yaml | 26 - .../src/Security/User.php | 90 -- .../src/Security/UserProvider.php | 33 - .../tests/SecurityControllerTest.php | 35 - .../config/packages/security.yaml | 26 - .../config/packages/security.yaml | 29 - .../src/Security/Authenticator.php | 53 - .../config/packages/security.yaml | 25 - .../config/packages/security.yaml | 34 - .../src/Entity/User.php | 113 -- .../src/Repository/UserRepository.php | 38 - .../tests/SecurityControllerTest.php | 85 -- .../config/packages/dev/maker.yaml | 2 - .../src/Entity/SweetFood.php | 44 - .../config/packages/dev/maker.yaml | 2 - .../src/Entity/SweetFood.php | 45 - .../tests/GeneratedCrudControllerTest.php | 15 - .../src/Entity/Directory.php | 45 - .../tests/GeneratedEntityTest.php | 49 - .../MakeEntityManyToMany/src/Entity/User.php | 45 - .../config/packages/dev/maker.yaml | 2 - .../MakeEntityManyToOne/src/Entity/User.php | 45 - .../tests/GeneratedEntityTest.php | 49 - .../src/Entity/User.php | 19 - .../MakeEntityOneToOne/src/Entity/User.php | 45 - .../tests/GeneratedEntityTest.php | 17 - .../src/Entity/User.php | 14 - .../src/Entity/User.php | 19 - .../src/Entity/User.php | 45 - .../src/Entity/Product.php | 14 - .../tests/GeneratedEntityTest.php | 38 - .../src/Entity/User.php | 14 - .../config/services_test.yaml | 5 - .../config/packages/messenger.yaml | 5 - .../config/services_test.yaml | 5 - .../config/packages/security.yaml | 20 - .../src/Entity/User.php | 104 -- .../VerifyEmailDoesntModifyUserEntityTest.php | 15 - .../config/packages/security.yaml | 17 - .../src/Entity/User.php | 109 -- .../src/Security/AuthenticatorFirst.php | 7 - .../src/Security/AuthenticatorSecond.php | 7 - .../config/packages/security.yaml | 20 - .../src/Entity/User.php | 104 -- .../tests/UserEntityTest.php | 15 - .../config/packages/mailer.yaml | 3 - .../config/packages/security.yaml | 19 - .../src/Entity/User.php | 93 -- .../src/Repository/UserRepository.php | 21 - .../src/Security/LoginFormAuthenticator.php | 102 -- .../config/packages/mailer.yaml | 3 - .../config/packages/security.yaml | 20 - .../src/Controller/MyController.php | 18 - .../src/Entity/User.php | 93 -- .../src/Repository/UserRepository.php | 21 - .../tests/VerifyEmailTest.php | 41 - .../config/packages/security.yml | 3 - .../MakeResetPassword/src/Entity/User.php | 38 - .../packages/custom_reset_password.yaml | 2 - .../config/packages/security.yml | 3 - .../src/Entity/User.php | 38 - .../config/packages/security.yml | 3 - .../src/Entity/UserCustom.php | 38 - .../config/packages/mailer.yaml | 3 - .../config/packages/security.yml | 3 - .../src/Entity/User.php | 38 - .../config/packages/security.yml | 3 - .../src/Entity/User.php | 38 - .../src/Controller/TestingController.php | 16 - .../src/Security/AutomaticAuthenticator.php | 64 - .../tests/GeneratedEntityTest.php | 18 - .../config/routes.yaml | 7 - .../src/Security/AutomaticAuthenticator.php | 63 - .../MakeEntity/tests/GeneratedEntityTest.php | 35 - .../src/Entity/Directory.php | 53 - .../tests/GeneratedEntityTest.php | 49 - .../MakeEntityManyToMany/src/Entity/User.php | 53 - .../tests/GeneratedEntityTest.php | 61 - .../config/packages/dev/maker.yaml | 2 - .../tests/GeneratedEntityTest.php | 64 - .../MakeEntityManyToOne/src/Entity/User.php | 53 - .../tests/GeneratedEntityTest.php | 49 - .../src/Entity/User.php | 23 - .../tests/GeneratedEntityTest.php | 35 - .../tests/GeneratedEntityTest.php | 64 - .../MakeEntityOneToOne/src/Entity/User.php | 53 - .../tests/GeneratedEntityTest.php | 47 - .../tests/GeneratedEntityTest.php | 17 - .../tests/GeneratedEntityTest.php | 50 - .../tests/GeneratedEntityTest.php | 51 - .../tests/GeneratedEntityTest.php | 48 - .../tests/GeneratedEntityTest.php | 17 - .../src/Entity/User.php | 23 - .../vendor/some-vendor/src/Group.php | 8 - .../src/Entity/User.php | 53 - .../tests/GeneratedEntityTest.php | 49 - .../src/Entity/Product.php | 18 - .../tests/GeneratedEntityTest.php | 32 - .../tests/GeneratedEntityTest.php | 38 - .../fixtures/make-auth/BlankAuthenticator.php | 30 + .../LoginFlowTest.php.twig} | 53 +- .../SecurityController-empty.php} | 0 .../make-auth/UserProvider-no-entity.php | 40 + .../tests/it_makes_a_command.php} | 0 ...t_makes_a_command_in_custom_namespace.php} | 0 .../tests/it_generates_a_controller.php} | 0 .../it_generates_a_controller_with_twig.php} | 2 +- .../SweetFood-custom-namespace.php} | 0 .../src/Entity => make-crud}/SweetFood.php | 0 .../SweetFoodRepository.php | 0 .../tests/it_generates_basic_crud.php} | 0 ...generates_crud_with_custom_controller.php} | 0 ...rates_crud_with_custom_root_namespace.php} | 0 .../GeneratedEntityTest.php.twig} | 7 +- .../Group-vendor.php} | 0 .../entities/annotations/User-basic.php} | 2 +- .../annotations/User-custom-namespace.php} | 2 +- .../User-invalid-method-no-property.php} | 2 +- .../annotations/User-invalid-method.php} | 2 +- .../annotations/UserAvatarPhoto-basic.php} | 2 +- .../entities/attributes/User-basic.php} | 0 .../attributes/User-custom-namespace.php} | 0 .../User-invalid-method-no-property.php} | 0 .../attributes/User-invalid-method.php} | 0 .../attributes/UserAvatarPhoto-basic.php} | 0 .../annotations}/src/Entity/Food.php | 6 +- .../annotations}/src/Entity/Recipe.php | 2 +- .../attributes}/src/Entity/Food.php | 6 - .../attributes}/src/Entity/Recipe.php | 0 .../annotations}/src/Entity/Currency.php | 6 +- .../annotations}/src/Entity/Invoice.php | 8 +- .../annotations}/src/Entity/Money.php | 4 - .../attributes}/src/Entity/Currency.php | 0 .../attributes}/src/Entity/Invoice.php | 0 .../attributes}/src/Entity/Money.php | 0 .../config/doctrine/User.orm.xml | 0 .../config/doctrine/UserAvatar.orm.xml | 0 .../annotations}/src/Entity/User.php | 2 +- .../annotations}/src/Entity/UserAvatar.php | 2 +- .../attributes}/src/Entity/User.php | 0 .../attributes}/src/Entity/UserAvatar.php | 0 .../tests/it_adds_many_to_many_simple.php} | 0 ...ny_to_many_with_custom_root_namespace.php} | 0 .../it_adds_many_to_one_self_referencing.php} | 0 .../tests/it_adds_one_to_many_simple.php} | 0 .../tests/it_adds_one_to_one_simple.php} | 0 ...class_that_matches_existing_namespace.php} | 4 +- .../it_regenerates_embeddable_entity.php} | 0 .../it_regenerates_embedded_entities.php} | 0 .../tests/it_regenerates_entities.php} | 0 .../tests/it_regenerates_from_xml.php} | 0 .../tests/it_regenerates_with_overwrite.php} | 0 ...updates_entity_many_to_one_no_inverse.php} | 0 .../xml-mapping}/config/doctrine/User.orm.xml | 0 .../src/Entity => make-form}/Property.php | 0 .../src/Entity => make-form}/SourFood.php | 0 .../src/Form/Data => make-form}/TaskData.php | 0 .../Entity => make-form/embeddable}/Food.php | 18 +- .../embeddable/Receipt.php} | 2 +- .../Entity => make-form/inheritance}/Food.php | 0 .../inheritance}/SourFood.php | 0 .../tests/it_generates_basic_form.php} | 0 ...generates_form_with_embeddable_entity.php} | 0 .../tests/it_generates_form_with_entity.php} | 0 ...it_generates_form_with_non_entity_dto.php} | 0 ..._with_single_table_inheritance_entity.php} | 0 .../MainController.php | 0 .../config => make-functional}/routes.yaml | 0 .../tests/it_generates_basic_message.php} | 0 .../it_generates_message_with_transport.php} | 0 .../Entity => make-migration}/SpicyFood.php | 0 .../standard_setup}/config/routes.yaml | 0 .../src/Controller/TestingController.php | 0 .../LegacyGuardStubAuthenticator.php} | 2 +- .../src/Security/StubAuthenticator.php | 40 + ...s_registration_form_with_verification.php} | 2 +- ...tration_with_entity_and_authenticator.php} | 6 + .../tests/it_generates_with_normal_setup.php} | 0 .../make-test/basic_setup/config/routes.yaml | 3 + .../src/Controller/MainController.php | 14 + .../standard_setup}/config/routes.yaml | 0 .../src/Controller/TestingController.php | 2 +- .../src/Security/AutomaticAuthenticator.php | 54 + .../it_generates_entity_with_password.php} | 18 +- .../it_generates_non_entity_no_password.php} | 2 +- 261 files changed, 3030 insertions(+), 7521 deletions(-) create mode 100644 src/Console/MigrationDiffFilteredOutput_php8.php create mode 100644 src/Test/MakerTestRunner.php delete mode 100644 tests/Maker/MakeEntityLegacyTest.php delete mode 100644 tests/fixtures/MakeAuthenticator/config/packages/security.yaml delete mode 100644 tests/fixtures/MakeAuthenticatorExistingAuthenticator/config/packages/security.yaml delete mode 100644 tests/fixtures/MakeAuthenticatorExistingAuthenticator/src/Security/Authenticator.php delete mode 100644 tests/fixtures/MakeAuthenticatorLoginFormCustomUsernameField/config/packages/security.yaml delete mode 100644 tests/fixtures/MakeAuthenticatorLoginFormCustomUsernameField/src/Security/User.php delete mode 100644 tests/fixtures/MakeAuthenticatorLoginFormCustomUsernameField/src/Security/UserProvider.php delete mode 100644 tests/fixtures/MakeAuthenticatorLoginFormCustomUsernameField/tests/SecurityControllerTest.php delete mode 100644 tests/fixtures/MakeAuthenticatorLoginFormExistingController/config/packages/security.yaml delete mode 100644 tests/fixtures/MakeAuthenticatorLoginFormExistingController/src/Entity/User.php delete mode 100644 tests/fixtures/MakeAuthenticatorLoginFormExistingController/tests/SecurityControllerTest.php delete mode 100644 tests/fixtures/MakeAuthenticatorLoginFormUserEntity/config/packages/security.yaml delete mode 100644 tests/fixtures/MakeAuthenticatorLoginFormUserEntity/src/Entity/User.php delete mode 100644 tests/fixtures/MakeAuthenticatorLoginFormUserEntityLogout/config/packages/security.yaml delete mode 100644 tests/fixtures/MakeAuthenticatorLoginFormUserEntityLogout/src/Entity/User.php delete mode 100644 tests/fixtures/MakeAuthenticatorLoginFormUserEntityLogout/tests/SecurityControllerTest.php delete mode 100644 tests/fixtures/MakeAuthenticatorLoginFormUserEntityNoEncoder/config/packages/security.yaml delete mode 100644 tests/fixtures/MakeAuthenticatorLoginFormUserEntityNoEncoder/src/Entity/User.php delete mode 100644 tests/fixtures/MakeAuthenticatorLoginFormUserEntityNoEncoder/tests/SecurityControllerTest.php delete mode 100644 tests/fixtures/MakeAuthenticatorLoginFormUserNotEntity/config/packages/security.yaml delete mode 100644 tests/fixtures/MakeAuthenticatorLoginFormUserNotEntity/src/Security/User.php delete mode 100644 tests/fixtures/MakeAuthenticatorLoginFormUserNotEntity/src/Security/UserProvider.php delete mode 100644 tests/fixtures/MakeAuthenticatorLoginFormUserNotEntity/tests/SecurityControllerTest.php delete mode 100644 tests/fixtures/MakeAuthenticatorLoginFormUserNotEntityNoEncoder/config/packages/security.yaml delete mode 100644 tests/fixtures/MakeAuthenticatorLoginFormUserNotEntityNoEncoder/src/Security/User.php delete mode 100644 tests/fixtures/MakeAuthenticatorLoginFormUserNotEntityNoEncoder/src/Security/UserProvider.php delete mode 100644 tests/fixtures/MakeAuthenticatorLoginFormUserNotEntityNoEncoder/tests/SecurityControllerTest.php delete mode 100644 tests/fixtures/MakeAuthenticatorMultipleFirewalls/config/packages/security.yaml delete mode 100644 tests/fixtures/MakeAuthenticatorMultipleFirewallsExistingAuthenticator/config/packages/security.yaml delete mode 100644 tests/fixtures/MakeAuthenticatorMultipleFirewallsExistingAuthenticator/src/Security/Authenticator.php delete mode 100644 tests/fixtures/MakeAuthenticatorSecurity52Empty/config/packages/security.yaml delete mode 100644 tests/fixtures/MakeAuthenticatorSecurity52LoginForm/config/packages/security.yaml delete mode 100644 tests/fixtures/MakeAuthenticatorSecurity52LoginForm/src/Entity/User.php delete mode 100644 tests/fixtures/MakeAuthenticatorSecurity52LoginForm/src/Repository/UserRepository.php delete mode 100644 tests/fixtures/MakeAuthenticatorSecurity52LoginForm/tests/SecurityControllerTest.php delete mode 100644 tests/fixtures/MakeCommandInCustomRootNamespace/config/packages/dev/maker.yaml delete mode 100644 tests/fixtures/MakeCrudCustomController/src/Entity/SweetFood.php delete mode 100644 tests/fixtures/MakeCrudInCustomRootNamespace/config/packages/dev/maker.yaml delete mode 100644 tests/fixtures/MakeCrudRepository/src/Entity/SweetFood.php delete mode 100644 tests/fixtures/MakeCrudRepository/tests/GeneratedCrudControllerTest.php delete mode 100644 tests/fixtures/MakeEntityExistsInRoot/src/Entity/Directory.php delete mode 100644 tests/fixtures/MakeEntityExistsInRoot/tests/GeneratedEntityTest.php delete mode 100644 tests/fixtures/MakeEntityManyToMany/src/Entity/User.php delete mode 100644 tests/fixtures/MakeEntityManyToManyInCustomNamespace/config/packages/dev/maker.yaml delete mode 100644 tests/fixtures/MakeEntityManyToOne/src/Entity/User.php delete mode 100644 tests/fixtures/MakeEntityManyToOne/tests/GeneratedEntityTest.php delete mode 100644 tests/fixtures/MakeEntityManyToOneNoInverse/src/Entity/User.php delete mode 100644 tests/fixtures/MakeEntityOneToOne/src/Entity/User.php delete mode 100644 tests/fixtures/MakeEntityRegenerateOverwrite/tests/GeneratedEntityTest.php delete mode 100644 tests/fixtures/MakeEntityRegenerateXml/src/Entity/User.php delete mode 100644 tests/fixtures/MakeEntityRelationVendorTarget/src/Entity/User.php delete mode 100644 tests/fixtures/MakeEntitySelfReferencing/src/Entity/User.php delete mode 100644 tests/fixtures/MakeEntitySubNamespaceMatchingEntity/src/Entity/Product.php delete mode 100644 tests/fixtures/MakeEntityUpdate/tests/GeneratedEntityTest.php delete mode 100644 tests/fixtures/MakeEntityXmlMappingError/src/Entity/User.php delete mode 100644 tests/fixtures/MakeMessageBasic/config/services_test.yaml delete mode 100644 tests/fixtures/MakeMessageWithTransport/config/packages/messenger.yaml delete mode 100644 tests/fixtures/MakeMessageWithTransport/config/services_test.yaml delete mode 100644 tests/fixtures/MakeRegistrationFormEntity/config/packages/security.yaml delete mode 100644 tests/fixtures/MakeRegistrationFormEntity/src/Entity/User.php delete mode 100644 tests/fixtures/MakeRegistrationFormEntity/tests/VerifyEmailDoesntModifyUserEntityTest.php delete mode 100644 tests/fixtures/MakeRegistrationFormNoGuessing/config/packages/security.yaml delete mode 100644 tests/fixtures/MakeRegistrationFormNoGuessing/src/Entity/User.php delete mode 100644 tests/fixtures/MakeRegistrationFormNoGuessing/src/Security/AuthenticatorFirst.php delete mode 100644 tests/fixtures/MakeRegistrationFormNoGuessing/src/Security/AuthenticatorSecond.php delete mode 100644 tests/fixtures/MakeRegistrationFormVerifyEmail/config/packages/security.yaml delete mode 100644 tests/fixtures/MakeRegistrationFormVerifyEmail/src/Entity/User.php delete mode 100644 tests/fixtures/MakeRegistrationFormVerifyEmail/tests/UserEntityTest.php delete mode 100644 tests/fixtures/MakeRegistrationFormVerifyEmailFunctionalTest/config/packages/mailer.yaml delete mode 100644 tests/fixtures/MakeRegistrationFormVerifyEmailFunctionalTest/config/packages/security.yaml delete mode 100644 tests/fixtures/MakeRegistrationFormVerifyEmailFunctionalTest/src/Entity/User.php delete mode 100644 tests/fixtures/MakeRegistrationFormVerifyEmailFunctionalTest/src/Repository/UserRepository.php delete mode 100644 tests/fixtures/MakeRegistrationFormVerifyEmailFunctionalTest/src/Security/LoginFormAuthenticator.php delete mode 100644 tests/fixtures/MakeRegistrationFormVerifyEmailNoAuthFunctionalTest/config/packages/mailer.yaml delete mode 100644 tests/fixtures/MakeRegistrationFormVerifyEmailNoAuthFunctionalTest/config/packages/security.yaml delete mode 100644 tests/fixtures/MakeRegistrationFormVerifyEmailNoAuthFunctionalTest/src/Controller/MyController.php delete mode 100644 tests/fixtures/MakeRegistrationFormVerifyEmailNoAuthFunctionalTest/src/Entity/User.php delete mode 100644 tests/fixtures/MakeRegistrationFormVerifyEmailNoAuthFunctionalTest/src/Repository/UserRepository.php delete mode 100644 tests/fixtures/MakeRegistrationFormVerifyEmailNoAuthFunctionalTest/tests/VerifyEmailTest.php delete mode 100644 tests/fixtures/MakeResetPassword/config/packages/security.yml delete mode 100644 tests/fixtures/MakeResetPassword/src/Entity/User.php delete mode 100644 tests/fixtures/MakeResetPasswordCustomConfig/config/packages/custom_reset_password.yaml delete mode 100644 tests/fixtures/MakeResetPasswordCustomConfig/config/packages/security.yml delete mode 100644 tests/fixtures/MakeResetPasswordCustomConfig/src/Entity/User.php delete mode 100644 tests/fixtures/MakeResetPasswordCustomUserAttribute/config/packages/security.yml delete mode 100644 tests/fixtures/MakeResetPasswordCustomUserAttribute/src/Entity/UserCustom.php delete mode 100644 tests/fixtures/MakeResetPasswordFunctionalTest/config/packages/mailer.yaml delete mode 100644 tests/fixtures/MakeResetPasswordFunctionalTest/config/packages/security.yml delete mode 100644 tests/fixtures/MakeResetPasswordFunctionalTest/src/Entity/User.php delete mode 100644 tests/fixtures/MakeResetPasswordModifiedConfig/config/packages/security.yml delete mode 100644 tests/fixtures/MakeResetPasswordModifiedConfig/src/Entity/User.php delete mode 100644 tests/fixtures/MakeUserEntityPassword/src/Controller/TestingController.php delete mode 100644 tests/fixtures/MakeUserEntityPassword/src/Security/AutomaticAuthenticator.php delete mode 100644 tests/fixtures/MakeUserEntityPasswordAuthenticatedUserInterface/tests/GeneratedEntityTest.php delete mode 100644 tests/fixtures/MakeUserModelNoPassword/config/routes.yaml delete mode 100644 tests/fixtures/MakeUserModelNoPassword/src/Security/AutomaticAuthenticator.php delete mode 100644 tests/fixtures/legacy/MakeEntity/MakeEntity/tests/GeneratedEntityTest.php delete mode 100644 tests/fixtures/legacy/MakeEntity/MakeEntityExistsInRoot/src/Entity/Directory.php delete mode 100644 tests/fixtures/legacy/MakeEntity/MakeEntityExistsInRoot/tests/GeneratedEntityTest.php delete mode 100644 tests/fixtures/legacy/MakeEntity/MakeEntityManyToMany/src/Entity/User.php delete mode 100644 tests/fixtures/legacy/MakeEntity/MakeEntityManyToMany/tests/GeneratedEntityTest.php delete mode 100644 tests/fixtures/legacy/MakeEntity/MakeEntityManyToManyInCustomNamespace/config/packages/dev/maker.yaml delete mode 100644 tests/fixtures/legacy/MakeEntity/MakeEntityManyToManyInCustomNamespace/tests/GeneratedEntityTest.php delete mode 100644 tests/fixtures/legacy/MakeEntity/MakeEntityManyToOne/src/Entity/User.php delete mode 100644 tests/fixtures/legacy/MakeEntity/MakeEntityManyToOne/tests/GeneratedEntityTest.php delete mode 100644 tests/fixtures/legacy/MakeEntity/MakeEntityManyToOneNoInverse/src/Entity/User.php delete mode 100644 tests/fixtures/legacy/MakeEntity/MakeEntityManyToOneNoInverse/tests/GeneratedEntityTest.php delete mode 100644 tests/fixtures/legacy/MakeEntity/MakeEntityOneToMany/tests/GeneratedEntityTest.php delete mode 100644 tests/fixtures/legacy/MakeEntity/MakeEntityOneToOne/src/Entity/User.php delete mode 100644 tests/fixtures/legacy/MakeEntity/MakeEntityOneToOne/tests/GeneratedEntityTest.php delete mode 100644 tests/fixtures/legacy/MakeEntity/MakeEntityOverwrite/tests/GeneratedEntityTest.php delete mode 100644 tests/fixtures/legacy/MakeEntity/MakeEntityRegenerate/tests/GeneratedEntityTest.php delete mode 100644 tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateEmbedable/tests/GeneratedEntityTest.php delete mode 100644 tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateEmbeddableObject/tests/GeneratedEntityTest.php delete mode 100644 tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateOverwrite/tests/GeneratedEntityTest.php delete mode 100644 tests/fixtures/legacy/MakeEntity/MakeEntityRelationVendorTarget/src/Entity/User.php delete mode 100644 tests/fixtures/legacy/MakeEntity/MakeEntityRelationVendorTarget/vendor/some-vendor/src/Group.php delete mode 100644 tests/fixtures/legacy/MakeEntity/MakeEntitySelfReferencing/src/Entity/User.php delete mode 100644 tests/fixtures/legacy/MakeEntity/MakeEntitySelfReferencing/tests/GeneratedEntityTest.php delete mode 100644 tests/fixtures/legacy/MakeEntity/MakeEntitySubNamespaceMatchingEntity/src/Entity/Product.php delete mode 100644 tests/fixtures/legacy/MakeEntity/MakeEntitySubNamespaceMatchingEntity/tests/GeneratedEntityTest.php delete mode 100644 tests/fixtures/legacy/MakeEntity/MakeEntityUpdate/tests/GeneratedEntityTest.php create mode 100644 tests/fixtures/make-auth/BlankAuthenticator.php rename tests/fixtures/{MakeAuthenticatorLoginFormUserEntity/tests/SecurityControllerTest.php => make-auth/LoginFlowTest.php.twig} (60%) rename tests/fixtures/{MakeAuthenticatorLoginFormExistingController/src/Controller/SecurityController.php => make-auth/SecurityController-empty.php} (100%) create mode 100644 tests/fixtures/make-auth/UserProvider-no-entity.php rename tests/fixtures/{MakeCommand/tests/GeneratedCommandTest.php => make-command/tests/it_makes_a_command.php} (100%) rename tests/fixtures/{MakeCommandInCustomRootNamespace/tests/GeneratedCommandTest.php => make-command/tests/it_makes_a_command_in_custom_namespace.php} (100%) rename tests/fixtures/{MakeController/tests/GeneratedControllerTest.php => make-controller/tests/it_generates_a_controller.php} (100%) rename tests/fixtures/{MakeControllerTwig/tests/GeneratedControllerWithTwigTest.php => make-controller/tests/it_generates_a_controller_with_twig.php} (89%) rename tests/fixtures/{MakeCrudInCustomRootNamespace/src/Entity/SweetFood.php => make-crud/SweetFood-custom-namespace.php} (100%) rename tests/fixtures/{MakeCrud/src/Entity => make-crud}/SweetFood.php (100%) rename tests/fixtures/{MakeCrudRepository/src/Repository => make-crud}/SweetFoodRepository.php (100%) rename tests/fixtures/{MakeCrud/tests/GeneratedCrudControllerTest.php => make-crud/tests/it_generates_basic_crud.php} (100%) rename tests/fixtures/{MakeCrudCustomController/tests/GeneratedCrudControllerTest.php => make-crud/tests/it_generates_crud_with_custom_controller.php} (100%) rename tests/fixtures/{MakeCrudInCustomRootNamespace/tests/GeneratedCrudControllerTest.php => make-crud/tests/it_generates_crud_with_custom_root_namespace.php} (100%) rename tests/fixtures/{MakeEntity/tests/GeneratedEntityTest.php => make-entity/GeneratedEntityTest.php.twig} (86%) rename tests/fixtures/{MakeEntityRelationVendorTarget/vendor/some-vendor/src/Group.php => make-entity/Group-vendor.php} (100%) rename tests/fixtures/{legacy/MakeEntity/MakeEntityUpdate/src/Entity/User.php => make-entity/entities/annotations/User-basic.php} (97%) rename tests/fixtures/{legacy/MakeEntity/MakeEntityManyToManyInCustomNamespace/src/Entity/User.php => make-entity/entities/annotations/User-custom-namespace.php} (98%) rename tests/fixtures/{legacy/MakeEntity/MakeEntityOverwrite/src/Entity/User.php => make-entity/entities/annotations/User-invalid-method-no-property.php} (95%) rename tests/fixtures/{legacy/MakeEntity/MakeEntityRegenerateOverwrite/src/Entity/User.php => make-entity/entities/annotations/User-invalid-method.php} (96%) rename tests/fixtures/{legacy/MakeEntity/MakeEntityOneToMany/src/Entity/UserAvatarPhoto.php => make-entity/entities/annotations/UserAvatarPhoto-basic.php} (94%) rename tests/fixtures/{MakeEntityUpdate/src/Entity/User.php => make-entity/entities/attributes/User-basic.php} (100%) rename tests/fixtures/{MakeEntityManyToManyInCustomNamespace/src/Entity/User.php => make-entity/entities/attributes/User-custom-namespace.php} (100%) rename tests/fixtures/{MakeEntityOverwrite/src/Entity/User.php => make-entity/entities/attributes/User-invalid-method-no-property.php} (100%) rename tests/fixtures/{MakeEntityRegenerateOverwrite/src/Entity/User.php => make-entity/entities/attributes/User-invalid-method.php} (100%) rename tests/fixtures/{MakeEntityOneToMany/src/Entity/UserAvatarPhoto.php => make-entity/entities/attributes/UserAvatarPhoto-basic.php} (100%) rename tests/fixtures/{legacy/MakeEntity/MakeEntityRegenerateEmbedable => make-entity/regenerate-embeddable/annotations}/src/Entity/Food.php (64%) rename tests/fixtures/{legacy/MakeEntity/MakeEntityRegenerateEmbedable => make-entity/regenerate-embeddable/annotations}/src/Entity/Recipe.php (92%) rename tests/fixtures/{MakeEntityRegenerateEmbedable => make-entity/regenerate-embeddable/attributes}/src/Entity/Food.php (81%) rename tests/fixtures/{MakeEntityRegenerateEmbedable => make-entity/regenerate-embeddable/attributes}/src/Entity/Recipe.php (100%) rename tests/fixtures/{legacy/MakeEntity/MakeEntityRegenerateEmbeddableObject => make-entity/regenerate-embedded/annotations}/src/Entity/Currency.php (84%) rename tests/fixtures/{legacy/MakeEntity/MakeEntityRegenerateEmbeddableObject => make-entity/regenerate-embedded/annotations}/src/Entity/Invoice.php (60%) rename tests/fixtures/{legacy/MakeEntity/MakeEntityRegenerateEmbeddableObject => make-entity/regenerate-embedded/annotations}/src/Entity/Money.php (89%) rename tests/fixtures/{MakeEntityRegenerateEmbeddableObject => make-entity/regenerate-embedded/attributes}/src/Entity/Currency.php (100%) rename tests/fixtures/{MakeEntityRegenerateEmbeddableObject => make-entity/regenerate-embedded/attributes}/src/Entity/Invoice.php (100%) rename tests/fixtures/{MakeEntityRegenerateEmbeddableObject => make-entity/regenerate-embedded/attributes}/src/Entity/Money.php (100%) rename tests/fixtures/{MakeEntityRegenerateXml => make-entity/regenerate-xml}/config/doctrine/User.orm.xml (100%) rename tests/fixtures/{MakeEntityRegenerateXml => make-entity/regenerate-xml}/config/doctrine/UserAvatar.orm.xml (100%) rename tests/fixtures/{legacy/MakeEntity/MakeEntityRegenerate => make-entity/regenerate/annotations}/src/Entity/User.php (97%) rename tests/fixtures/{legacy/MakeEntity/MakeEntityRegenerate => make-entity/regenerate/annotations}/src/Entity/UserAvatar.php (96%) rename tests/fixtures/{MakeEntityRegenerate => make-entity/regenerate/attributes}/src/Entity/User.php (100%) rename tests/fixtures/{MakeEntityRegenerate => make-entity/regenerate/attributes}/src/Entity/UserAvatar.php (100%) rename tests/fixtures/{MakeEntityManyToMany/tests/GeneratedEntityTest.php => make-entity/tests/it_adds_many_to_many_simple.php} (100%) rename tests/fixtures/{MakeEntityManyToManyInCustomNamespace/tests/GeneratedEntityTest.php => make-entity/tests/it_adds_many_to_many_with_custom_root_namespace.php} (100%) rename tests/fixtures/{MakeEntitySelfReferencing/tests/GeneratedEntityTest.php => make-entity/tests/it_adds_many_to_one_self_referencing.php} (100%) rename tests/fixtures/{MakeEntityOneToMany/tests/GeneratedEntityTest.php => make-entity/tests/it_adds_one_to_many_simple.php} (100%) rename tests/fixtures/{MakeEntityOneToOne/tests/GeneratedEntityTest.php => make-entity/tests/it_adds_one_to_one_simple.php} (100%) rename tests/fixtures/{MakeEntitySubNamespaceMatchingEntity/tests/GeneratedEntityTest.php => make-entity/tests/it_creates_class_that_matches_existing_namespace.php} (86%) rename tests/fixtures/{MakeEntityRegenerateEmbedable/tests/GeneratedEntityTest.php => make-entity/tests/it_regenerates_embeddable_entity.php} (100%) rename tests/fixtures/{MakeEntityRegenerateEmbeddableObject/tests/GeneratedEntityTest.php => make-entity/tests/it_regenerates_embedded_entities.php} (100%) rename tests/fixtures/{MakeEntityRegenerate/tests/GeneratedEntityTest.php => make-entity/tests/it_regenerates_entities.php} (100%) rename tests/fixtures/{MakeEntityRegenerateXml/tests/GeneratedEntityTest.php => make-entity/tests/it_regenerates_from_xml.php} (100%) rename tests/fixtures/{MakeEntityOverwrite/tests/GeneratedEntityTest.php => make-entity/tests/it_regenerates_with_overwrite.php} (100%) rename tests/fixtures/{MakeEntityManyToOneNoInverse/tests/GeneratedEntityTest.php => make-entity/tests/it_updates_entity_many_to_one_no_inverse.php} (100%) rename tests/fixtures/{MakeEntityXmlMappingError => make-entity/xml-mapping}/config/doctrine/User.orm.xml (100%) rename tests/fixtures/{MakeFormForEntity/src/Entity => make-form}/Property.php (100%) rename tests/fixtures/{MakeFormForEntity/src/Entity => make-form}/SourFood.php (100%) rename tests/fixtures/{MakeFormForNonEntityDto/src/Form/Data => make-form}/TaskData.php (100%) rename tests/fixtures/{MakeFormEmbedableEntity/src/Entity => make-form/embeddable}/Food.php (72%) rename tests/fixtures/{MakeFormEmbedableEntity/src/Entity/Recept.php => make-form/embeddable/Receipt.php} (95%) rename tests/fixtures/{MakeFormSTIEntity/src/Entity => make-form/inheritance}/Food.php (100%) rename tests/fixtures/{MakeFormSTIEntity/src/Entity => make-form/inheritance}/SourFood.php (100%) rename tests/fixtures/{MakeForm/tests/GeneratedFormTest.php => make-form/tests/it_generates_basic_form.php} (100%) rename tests/fixtures/{MakeFormEmbedableEntity/tests/GeneratedFormTest.php => make-form/tests/it_generates_form_with_embeddable_entity.php} (100%) rename tests/fixtures/{MakeFormForEntity/tests/GeneratedFormTest.php => make-form/tests/it_generates_form_with_entity.php} (100%) rename tests/fixtures/{MakeFormForNonEntityDto/tests/GeneratedFormTest.php => make-form/tests/it_generates_form_with_non_entity_dto.php} (100%) rename tests/fixtures/{MakeFormSTIEntity/tests/GeneratedFormTest.php => make-form/tests/it_generates_form_with_single_table_inheritance_entity.php} (100%) rename tests/fixtures/{MakeFunctional/src/Controller => make-functional}/MainController.php (100%) rename tests/fixtures/{MakeFunctional/config => make-functional}/routes.yaml (100%) rename tests/fixtures/{MakeMessageBasic/tests/GeneratedMessageHandlerTest.php => make-message/tests/it_generates_basic_message.php} (100%) rename tests/fixtures/{MakeMessageWithTransport/tests/GeneratedMessageHandlerTest.php => make-message/tests/it_generates_message_with_transport.php} (100%) rename tests/fixtures/{MakeMigration/src/Entity => make-migration}/SpicyFood.php (100%) rename tests/fixtures/{MakeRegistrationFormEntity => make-registration-form/standard_setup}/config/routes.yaml (100%) rename tests/fixtures/{MakeRegistrationFormEntity => make-registration-form/standard_setup}/src/Controller/TestingController.php (100%) rename tests/fixtures/{MakeRegistrationFormEntity/src/Security/StubAuthenticator.php => make-registration-form/standard_setup/src/Security/LegacyGuardStubAuthenticator.php} (95%) create mode 100644 tests/fixtures/make-registration-form/standard_setup/src/Security/StubAuthenticator.php rename tests/fixtures/{MakeRegistrationFormVerifyEmailFunctionalTest/tests/VerifyEmailTest.php => make-registration-form/tests/it_generates_registration_form_with_verification.php} (96%) rename tests/fixtures/{MakeRegistrationFormEntity/tests/RegistrationFormTest.php => make-registration-form/tests/it_generates_registration_with_entity_and_authenticator.php} (91%) rename tests/fixtures/{MakeResetPasswordFunctionalTest/tests/ResetPasswordFunctionalTest.php => make-reset-password/tests/it_generates_with_normal_setup.php} (100%) create mode 100644 tests/fixtures/make-test/basic_setup/config/routes.yaml create mode 100644 tests/fixtures/make-test/basic_setup/src/Controller/MainController.php rename tests/fixtures/{MakeUserEntityPassword => make-user/standard_setup}/config/routes.yaml (100%) rename tests/fixtures/{MakeUserModelNoPassword => make-user/standard_setup}/src/Controller/TestingController.php (91%) create mode 100644 tests/fixtures/make-user/standard_setup/src/Security/AutomaticAuthenticator.php rename tests/fixtures/{MakeUserEntityPassword/tests/GeneratedEntityTest.php => make-user/tests/it_generates_entity_with_password.php} (55%) rename tests/fixtures/{MakeUserModelNoPassword/tests/GeneratedEntityTest.php => make-user/tests/it_generates_non_entity_no_password.php} (92%) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 73519caa0..1788aa4fe 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -57,7 +57,7 @@ jobs: run: "tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run --diff" test: - name: "PHP ${{ matrix.php-version }} + symfony/skeleton@${{ matrix.symfony-skeleton-stability }}" + name: "PHP ${{ matrix.php-version }} + @${{ matrix.symfony-version }} ${{ matrix.dependency-versions }} deps" runs-on: ubuntu-18.04 @@ -82,28 +82,30 @@ jobs: ports: - 1337:1337 - continue-on-error: ${{ matrix.allow-failures }} - env: - SYMFONY_SKELETON_STABILITY: ${{ matrix.symfony-skeleton-stability }} + SYMFONY_VERSION: ${{ matrix.symfony-version }} strategy: fail-fast: false matrix: php-version: - - '7.1.3' - - '7.2' - - '7.3' - - '7.4' - '8.0' - symfony-skeleton-stability: - - 'stable' - composer-options: ['--no-suggest'] - allow-failures: [false] + symfony-version: + - '4.4.*' + - '5.3.*' + - '5.4.x-dev' + - '6.0.x-dev' + dependency-versions: ['highest'] include: - - php-version: '8.0' - symfony-skeleton-stability: 'dev' - allow-failures: true + # testing lowest PHP version with LTS + - php-version: '7.1.3' + symfony-version: '4.4.*' + # not important - does not affect each app's dependencies + dependency-versions: 'highest' + # testing lowest php version with highest 5.x stable + - php-version: '7.2.5' + symfony-version: '5.3.*' + dependency-versions: 'lowest' steps: - name: "Checkout code" @@ -132,17 +134,12 @@ jobs: run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: "Require symfony/flex" - if: contains('stable', env.SYMFONY_SKELETON_STABILITY) run: composer global require --no-progress --no-scripts --no-plugins symfony/flex - - name: "Require symfony/flex dev-main" - if: contains('dev', env.SYMFONY_SKELETON_STABILITY) - run: composer global require --no-progress --no-scripts --no-plugins symfony/flex dev-main - - name: "Composer install" uses: "ramsey/composer-install@v1" with: - composer-options: "${{ matrix.composer-options }}" + dependency-versions: "${{ matrix.dependency-versions }}" - name: "Composer install php-cs-fixer" uses: "ramsey/composer-install@v1" diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index ee09e0477..b637e7f7a 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -11,6 +11,7 @@ ->exclude('fixtures') // the PHP template files are a bit special ->notName('*.tpl.php') + ->notPath('src/Console/MigrationDiffFilteredOutput_php8.php') ; return (new PhpCsFixer\Config()) diff --git a/composer.json b/composer.json index 329bcaf50..5c1f092e2 100644 --- a/composer.json +++ b/composer.json @@ -16,24 +16,26 @@ "php": ">=7.1.3", "doctrine/inflector": "^1.2|^2.0", "nikic/php-parser": "^4.11", - "symfony/config": "^4.0|^5.0|^6.0", - "symfony/console": "^4.0|^5.0|^6.0", - "symfony/dependency-injection": "^4.0|^5.0|^6.0", + "symfony/config": "^4.4|^5.0|^6.0", + "symfony/console": "^4.4|^5.0|^6.0", + "symfony/dependency-injection": "^4.4|^5.0|^6.0", "symfony/deprecation-contracts": "^2.2", - "symfony/filesystem": "^4.0|^5.0|^6.0", - "symfony/finder": "^4.0|^5.0|^6.0", - "symfony/framework-bundle": "^4.0|^5.0|^6.0", - "symfony/http-kernel": "^4.0|^5.0|^6.0" + "symfony/filesystem": "^4.4|^5.0|^6.0", + "symfony/finder": "^4.4|^5.0|^6.0", + "symfony/framework-bundle": "^4.4|^5.0|^6.0", + "symfony/http-kernel": "^4.4|^5.0|^6.0" }, "require-dev": { - "composer/semver": "^3.0@dev", - "doctrine/doctrine-bundle": "^1.8|^2.0", + "composer/semver": "^3.0", + "doctrine/doctrine-bundle": "^1.12.3|^2.0", "doctrine/orm": "^2.3", - "symfony/http-client": "^4.3|^5.0|^6.0", - "symfony/phpunit-bridge": "^4.3|^5.0|^6.0", - "symfony/process": "^4.0|^5.0|^6.0", - "symfony/security-core": "^4.0|^5.0|^6.0", - "symfony/yaml": "^4.0|^5.0|^6.0" + "symfony/http-client": "^4.4|^5.0|^6.0", + "symfony/phpunit-bridge": "^4.4|^5.0|^6.0", + "symfony/polyfill-php80": "^1.16.0", + "symfony/process": "^4.4|^5.0|^6.0", + "symfony/security-core": "^4.4|^5.0|^6.0", + "symfony/yaml": "^4.4|^5.0|^6.0", + "twig/twig": "^2.0|^3.0" }, "config": { "preferred-install": "dist", diff --git a/src/Console/MigrationDiffFilteredOutput.php b/src/Console/MigrationDiffFilteredOutput.php index 43a322301..34c712a40 100644 --- a/src/Console/MigrationDiffFilteredOutput.php +++ b/src/Console/MigrationDiffFilteredOutput.php @@ -14,7 +14,38 @@ use Symfony\Component\Console\Formatter\OutputFormatterInterface; use Symfony\Component\Console\Output\OutputInterface; -class MigrationDiffFilteredOutput implements OutputInterface +if (\PHP_VERSION_ID < 80000 + // look for the "string|iterable" type on OutputInterface::write() + || !(new \ReflectionMethod(OutputInterface::class, 'write'))->getParameters()[0]->getType()) { + class MigrationDiffFilteredOutput implements OutputInterface + { + use BaseMakerMigrationDiffFilteredOuputTrait; + + public function write($messages, $newline = false, $options = 0) + { + $this->_write($messages, $newline, $options); + } + + public function writeln($messages, $options = 0) + { + $this->_writeln($messages, $options); + } + + public function setVerbosity($level) + { + $this->output->setVerbosity($level); + } + + public function setDecorated($decorated) + { + $this->output->setDecorated($decorated); + } + } +} else { + require __DIR__.'/MigrationDiffFilteredOutput_php8.php'; +} + +trait BaseMakerMigrationDiffFilteredOuputTrait { private $output; private $buffer = ''; @@ -25,56 +56,46 @@ public function __construct(OutputInterface $output) $this->output = $output; } - public function write($messages, $newline = false, $options = 0) + public function _write($messages, bool $newline = false, $options = 0) { $messages = $this->filterMessages($messages, $newline); $this->output->write($messages, $newline, $options); } - public function writeln($messages, $options = 0) + public function _writeln($messages, int $options = 0) { $messages = $this->filterMessages($messages, true); $this->output->writeln($messages, $options); } - public function setVerbosity($level) - { - $this->output->setVerbosity($level); - } - - public function getVerbosity() + public function getVerbosity(): int { return $this->output->getVerbosity(); } - public function isQuiet() + public function isQuiet(): bool { return $this->output->isQuiet(); } - public function isVerbose() + public function isVerbose(): bool { return $this->output->isVerbose(); } - public function isVeryVerbose() + public function isVeryVerbose(): bool { return $this->output->isVeryVerbose(); } - public function isDebug() + public function isDebug(): bool { return $this->output->isDebug(); } - public function setDecorated($decorated) - { - $this->output->setDecorated($decorated); - } - - public function isDecorated() + public function isDecorated(): bool { return $this->output->isDecorated(); } @@ -84,7 +105,7 @@ public function setFormatter(OutputFormatterInterface $formatter) $this->output->setFormatter($formatter); } - public function getFormatter() + public function getFormatter(): OutputFormatterInterface { return $this->output->getFormatter(); } diff --git a/src/Console/MigrationDiffFilteredOutput_php8.php b/src/Console/MigrationDiffFilteredOutput_php8.php new file mode 100644 index 000000000..d7c2a0e6a --- /dev/null +++ b/src/Console/MigrationDiffFilteredOutput_php8.php @@ -0,0 +1,39 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\MakerBundle\Console; + +use Symfony\Component\Console\Output\OutputInterface; + +class MigrationDiffFilteredOutput implements OutputInterface +{ + use BaseMakerMigrationDiffFilteredOuputTrait; + + public function write($messages, bool $newline = false, $options = 0) + { + $this->_write($messages, $newline, $options); + } + + public function writeln($messages, int $options = 0) + { + $this->_writeln($messages, $options); + } + + public function setVerbosity(int $level) + { + $this->output->setVerbosity($level); + } + + public function setDecorated(bool $decorated) + { + $this->output->setDecorated($decorated); + } +} diff --git a/src/Maker/MakeAuthenticator.php b/src/Maker/MakeAuthenticator.php index c8a51eb67..cb3aaa678 100644 --- a/src/Maker/MakeAuthenticator.php +++ b/src/Maker/MakeAuthenticator.php @@ -36,7 +36,9 @@ use Symfony\Component\Form\Form; use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Security\Guard\Authenticator\AbstractFormLoginAuthenticator; +use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface; use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge; +use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface; use Symfony\Component\Yaml\Yaml; /** @@ -264,7 +266,10 @@ private function generateAuthenticatorClass(array $securityData, string $authent $this->generator->generateClass( $authenticatorClass, sprintf('authenticator/%sEmptyAuthenticator.tpl.php', $this->useSecurity52 ? 'Security52' : ''), - ['provider_key_type_hint' => $this->providerKeyTypeHint()] + [ + 'provider_key_type_hint' => $this->providerKeyTypeHint(), + 'use_legacy_passport_interface' => $this->shouldUseLegacyPassportInterface(), + ] ); return; @@ -287,6 +292,7 @@ private function generateAuthenticatorClass(array $securityData, string $authent 'user_needs_encoder' => $this->userClassHasEncoder($securityData, $userClass), 'user_is_entity' => $this->doctrineHelper->isClassAMappedEntity($userClass), 'provider_key_type_hint' => $this->providerKeyTypeHint(), + 'use_legacy_passport_interface' => $this->shouldUseLegacyPassportInterface(), ] ); } @@ -411,4 +417,23 @@ private function providerKeyTypeHint(): string return sprintf('%s ', $type->getName()); } + + private function shouldUseLegacyPassportInterface(): bool + { + // only applies to new authenticator security + if (!$this->useSecurity52) { + return false; + } + + // legacy: checking for Symfony 5.2 & 5.3 before PassportInterface deprecation + $class = new \ReflectionClass(AuthenticatorInterface::class); + $method = $class->getMethod('authenticate'); + + // 5.4 where return type is temporarily removed + if (!$method->getReturnType()) { + return false; + } + + return PassportInterface::class === $method->getReturnType()->getName(); + } } diff --git a/src/Maker/MakeRegistrationForm.php b/src/Maker/MakeRegistrationForm.php index cf72a7dfa..d623f461b 100644 --- a/src/Maker/MakeRegistrationForm.php +++ b/src/Maker/MakeRegistrationForm.php @@ -13,6 +13,7 @@ use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; use Doctrine\Common\Annotations\Annotation; +use Doctrine\ORM\EntityManagerInterface; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Bridge\Twig\Mime\TemplatedEmail; use Symfony\Bundle\MakerBundle\ConsoleStyle; @@ -47,6 +48,7 @@ use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; use Symfony\Component\Security\Guard\GuardAuthenticatorHandler; +use Symfony\Component\Security\Http\Authentication\UserAuthenticatorInterface; use Symfony\Component\Validator\Validation; use SymfonyCasts\Bundle\VerifyEmail\Exception\VerifyEmailExceptionInterface; use SymfonyCasts\Bundle\VerifyEmail\Model\VerifyEmailSignatureComponents; @@ -78,6 +80,7 @@ final class MakeRegistrationForm extends AbstractMaker private $firewallName; private $redirectRouteName; private $addUniqueEntityConstraint; + private $useNewAuthenticatorSystem = false; public function __construct(FileManager $fileManager, FormTypeRenderer $formTypeRenderer, RouterInterface $router, DoctrineHelper $doctrineHelper) { @@ -116,6 +119,11 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma $securityData = $manipulator->getData(); $providersData = $securityData['security']['providers'] ?? []; + // Determine if we should use new security features introduced in Symfony 5.2 + if ($securityData['security']['enable_authenticator_manager'] ?? false) { + $this->useNewAuthenticatorSystem = true; + } + $this->userClass = $interactiveSecurityHelper->guessUserClass( $io, $providersData, @@ -292,6 +300,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen Response::class, Route::class, $passwordHasher, + EntityManagerInterface::class, ]; if ($this->willVerifyEmail) { @@ -307,7 +316,11 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen if ($this->autoLoginAuthenticator) { $useStatements[] = $this->autoLoginAuthenticator; - $useStatements[] = GuardAuthenticatorHandler::class; + if ($this->useNewAuthenticatorSystem) { + $useStatements[] = UserAuthenticatorInterface::class; + } else { + $useStatements[] = GuardAuthenticatorHandler::class; + } } $generator->generateController( @@ -328,6 +341,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen 'email_getter' => $this->emailGetter, 'authenticator_class_name' => $this->autoLoginAuthenticator ? Str::getShortClassName($this->autoLoginAuthenticator) : null, 'authenticator_full_class_name' => $this->autoLoginAuthenticator, + 'use_new_authenticator_system' => $this->useNewAuthenticatorSystem, 'firewall_name' => $this->firewallName, 'redirect_route_name' => $this->redirectRouteName, 'password_hasher_class_details' => ($passwordClassDetails = $generator->createClassNameDetails($passwordHasher, '\\')), diff --git a/src/Maker/MakeResetPassword.php b/src/Maker/MakeResetPassword.php index 4d7ceb7e7..d73ace9f3 100644 --- a/src/Maker/MakeResetPassword.php +++ b/src/Maker/MakeResetPassword.php @@ -12,6 +12,7 @@ namespace Symfony\Bundle\MakerBundle\Maker; use Doctrine\Common\Annotations\Annotation; +use Doctrine\ORM\EntityManagerInterface; use PhpParser\Builder\Param; use Symfony\Bridge\Twig\AppVariable; use Symfony\Bridge\Twig\Mime\TemplatedEmail; @@ -232,6 +233,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen ResetPasswordExceptionInterface::class, ResetPasswordHelperInterface::class, $passwordHasher, + EntityManagerInterface::class, ]; $generator->generateController( diff --git a/src/Maker/MakeTest.php b/src/Maker/MakeTest.php index 841c0dd53..845dfe1dc 100644 --- a/src/Maker/MakeTest.php +++ b/src/Maker/MakeTest.php @@ -12,6 +12,7 @@ namespace Symfony\Bundle\MakerBundle\Maker; use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase; +use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestAssertionsTrait; use Symfony\Bundle\MakerBundle\ConsoleStyle; use Symfony\Bundle\MakerBundle\DependencyBuilder; @@ -144,7 +145,10 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen $generator->generateClass( $testClassNameDetails->getFullName(), "test/$type.tpl.php", - ['web_assertions_are_available' => trait_exists(WebTestAssertionsTrait::class)] + [ + 'web_assertions_are_available' => trait_exists(WebTestAssertionsTrait::class), + 'use_legacy_container_property' => $this->useLegacyContainerProperty(), + ] ); $generator->writeChanges(); @@ -220,4 +224,10 @@ private function handleDeprecatedMakerCommands(InputInterface $input, ConsoleSty break; } } + + private function useLegacyContainerProperty(): bool + { + // for 5.2 and lower + return !method_exists(KernelTestCase::class, 'getContainer'); + } } diff --git a/src/Maker/MakeUser.php b/src/Maker/MakeUser.php index c2ea82512..d2a8a92d1 100644 --- a/src/Maker/MakeUser.php +++ b/src/Maker/MakeUser.php @@ -36,6 +36,7 @@ use Symfony\Component\Security\Core\Encoder\Argon2iPasswordEncoder; use Symfony\Component\Security\Core\Encoder\NativePasswordEncoder; use Symfony\Component\Security\Core\Exception\UserNotFoundException; +use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Symfony\Component\Security\Core\User\PasswordUpgraderInterface; use Symfony\Component\Yaml\Yaml; @@ -189,6 +190,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen [ 'uses_user_identifier' => class_exists(UserNotFoundException::class), 'user_short_name' => $userClassNameDetails->getShortName(), + 'use_legacy_password_upgrader_type' => !interface_exists(PasswordAuthenticatedUserInterface::class), ] ); } diff --git a/src/Resources/skeleton/authenticator/Security52EmptyAuthenticator.tpl.php b/src/Resources/skeleton/authenticator/Security52EmptyAuthenticator.tpl.php index 94e49865b..5890d0eaa 100644 --- a/src/Resources/skeleton/authenticator/Security52EmptyAuthenticator.tpl.php +++ b/src/Resources/skeleton/authenticator/Security52EmptyAuthenticator.tpl.php @@ -7,7 +7,7 @@ use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Http\Authenticator\AbstractAuthenticator; -use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface; + class extends AbstractAuthenticator { @@ -16,7 +16,7 @@ public function supports(Request $request): ?bool // TODO: Implement supports() method. } - public function authenticate(Request $request): PassportInterface + public function authenticate(Request $request): { // TODO: Implement authenticate() method. } diff --git a/src/Resources/skeleton/authenticator/Security52LoginFormAuthenticator.tpl.php b/src/Resources/skeleton/authenticator/Security52LoginFormAuthenticator.tpl.php index 20a192181..011a2a59c 100644 --- a/src/Resources/skeleton/authenticator/Security52LoginFormAuthenticator.tpl.php +++ b/src/Resources/skeleton/authenticator/Security52LoginFormAuthenticator.tpl.php @@ -13,7 +13,7 @@ use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge; use Symfony\Component\Security\Http\Authenticator\Passport\Credentials\PasswordCredentials; use Symfony\Component\Security\Http\Authenticator\Passport\Passport; -use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface; + use Symfony\Component\Security\Http\Util\TargetPathTrait; class extends AbstractLoginFormAuthenticator @@ -29,7 +29,7 @@ public function __construct(UrlGeneratorInterface $urlGenerator) $this->urlGenerator = $urlGenerator; } - public function authenticate(Request $request): PassportInterface + public function authenticate(Request $request): { $ = $request->request->get('', ''); diff --git a/src/Resources/skeleton/crud/controller/Controller.tpl.php b/src/Resources/skeleton/crud/controller/Controller.tpl.php index 515cddce7..3cf422598 100644 --- a/src/Resources/skeleton/crud/controller/Controller.tpl.php +++ b/src/Resources/skeleton/crud/controller/Controller.tpl.php @@ -7,6 +7,7 @@ use ; +use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -30,9 +31,9 @@ public function index( $): Re ]); } - public function index(): Response + public function index(EntityManagerInterface $entityManager): Response { - $ = $this->getDoctrine() + $ = $entityManager ->getRepository(::class) ->findAll(); @@ -43,14 +44,13 @@ public function index(): Response generateRouteForControllerMethod('/new', sprintf('%s_new', $route_name), ['GET', 'POST']) ?> - public function new(Request $request): Response + public function new(Request $request, EntityManagerInterface $entityManager): Response { $ = new (); $form = $this->createForm(::class, $); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $entityManager = $this->getDoctrine()->getManager(); $entityManager->persist($); $entityManager->flush(); @@ -79,13 +79,13 @@ public function show( $): Re } generateRouteForControllerMethod(sprintf('/{%s}/edit', $entity_identifier), sprintf('%s_edit', $route_name), ['GET', 'POST']) ?> - public function edit(Request $request, $): Response + public function edit(Request $request, $, EntityManagerInterface $entityManager): Response { $form = $this->createForm(::class, $); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $this->getDoctrine()->getManager()->flush(); + $entityManager->flush(); return $this->redirectToRoute('_index', [], Response::HTTP_SEE_OTHER); } @@ -104,10 +104,9 @@ public function edit(Request $request, $generateRouteForControllerMethod(sprintf('/{%s}', $entity_identifier), sprintf('%s_delete', $route_name), ['POST']) ?> - public function delete(Request $request, $): Response + public function delete(Request $request, $, EntityManagerInterface $entityManager): Response { if ($this->isCsrfTokenValid('delete'.$->get(), $request->request->get('_token'))) { - $entityManager = $this->getDoctrine()->getManager(); $entityManager->remove($); $entityManager->flush(); } diff --git a/src/Resources/skeleton/registration/RegistrationController.tpl.php b/src/Resources/skeleton/registration/RegistrationController.tpl.php index 57527aa18..187f92acf 100644 --- a/src/Resources/skeleton/registration/RegistrationController.tpl.php +++ b/src/Resources/skeleton/registration/RegistrationController.tpl.php @@ -16,7 +16,7 @@ public function __construct(getShortName() ?> generateRouteForControllerMethod($route_path, $route_name) ?> - public function register(Request $request, getShortName() ?> ): Response + public function register(Request $request, getShortName() ?> , EntityManagerInterface $entityManager): Response { $user = new (); $form = $this->createForm(::class, $user); @@ -31,7 +31,6 @@ public function register(Request $request, g ) ); - $entityManager = $this->getDoctrine()->getManager(); $entityManager->persist($user); $entityManager->flush(); @@ -48,12 +47,20 @@ public function register(Request $request, g // do anything else you need here, like send an email + + return $userAuthenticator->authenticateUser( + $user, + $authenticator, + $request + ); + return $guardHandler->authenticateUserAndHandleSuccess( $user, $request, $authenticator, '' // firewall name in security.yaml ); + return $this->redirectToRoute(''); diff --git a/src/Resources/skeleton/resetPassword/ResetPasswordController.tpl.php b/src/Resources/skeleton/resetPassword/ResetPasswordController.tpl.php index 1bec8aa2e..8d61cf325 100644 --- a/src/Resources/skeleton/resetPassword/ResetPasswordController.tpl.php +++ b/src/Resources/skeleton/resetPassword/ResetPasswordController.tpl.php @@ -82,7 +82,7 @@ public function checkEmail(): Response * @Route("/reset/{token}", name="app_reset_password") */ - public function reset(Request $request, getShortName() ?> , string $token = null): Response + public function reset(Request $request, getShortName() ?> , EntityManagerInterface $entityManager, string $token = null): Response { if ($token) { // We store the token in session and remove it from the URL, to avoid the URL being @@ -123,7 +123,7 @@ public function reset(Request $request, getS ); $user->($encodedPassword); - $this->getDoctrine()->getManager()->flush(); + $entityManager->flush(); // The session is cleaned up after the password has been changed. $this->cleanSessionAfterReset(); @@ -136,9 +136,9 @@ public function reset(Request $request, getS ]); } - private function processSendingPasswordResetEmail(string $emailFormData, MailerInterface $mailer): RedirectResponse + private function processSendingPasswordResetEmail(string $emailFormData, MailerInterface $mailer, EntityManagerInterface $entityManager): RedirectResponse { - $user = $this->getDoctrine()->getRepository(::class)->findOneBy([ + $user = $entityManager->getRepository(::class)->findOneBy([ '' => $emailFormData, ]); diff --git a/src/Resources/skeleton/security/UserProvider.tpl.php b/src/Resources/skeleton/security/UserProvider.tpl.php index 6b8161eac..c7ee1ef38 100644 --- a/src/Resources/skeleton/security/UserProvider.tpl.php +++ b/src/Resources/skeleton/security/UserProvider.tpl.php @@ -4,6 +4,7 @@ use Symfony\Component\Security\Core\Exception\UnsupportedUserException; use Symfony\Component\Security\Core\Exception\; + use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserProviderInterface; @@ -48,10 +49,8 @@ public function loadUserByUsername($username): UserInterface * * If your firewall is "stateless: true" (for a pure API), this * method is not called. - * - * @return UserInterface */ - public function refreshUser(UserInterface $user) + public function refreshUser(UserInterface $user): UserInterface { if (!$user instanceof ) { throw new UnsupportedUserException(sprintf('Invalid user class "%s".', get_class($user))); @@ -65,7 +64,7 @@ public function refreshUser(UserInterface $user) /** * Tells Symfony to use this provider for this User class. */ - public function supportsClass($class) + public function supportsClass($class): bool { return ::class === $class || is_subclass_of($class, ::class); } @@ -74,7 +73,7 @@ public function supportsClass($class) /** * Upgrades the hashed password of a user, typically for using a better hash algorithm. */ - public function upgradePassword(UserInterface $user, string $newHashedPassword): void + public function upgradePassword( $user, string $newHashedPassword): void { // TODO: when hashed passwords are in use, this method should: // 1. persist the new password in the user storage diff --git a/src/Resources/skeleton/test/KernelTestCase.tpl.php b/src/Resources/skeleton/test/KernelTestCase.tpl.php index 9e4aee502..75d6e118b 100644 --- a/src/Resources/skeleton/test/KernelTestCase.tpl.php +++ b/src/Resources/skeleton/test/KernelTestCase.tpl.php @@ -11,7 +11,7 @@ public function testSomething(): void $kernel = self::bootKernel(); $this->assertSame('test', $kernel->getEnvironment()); - //$routerService = self::$container->get('router'); - //$myCustomService = self::$container->get(CustomService::class); + //$routerService = ->get('router'); + //$myCustomService = ->get(CustomService::class); } } diff --git a/src/Security/InteractiveSecurityHelper.php b/src/Security/InteractiveSecurityHelper.php index 0839cb4d5..19770edaa 100644 --- a/src/Security/InteractiveSecurityHelper.php +++ b/src/Security/InteractiveSecurityHelper.php @@ -184,24 +184,24 @@ public function guessPasswordField(SymfonyStyle $io, string $userClass): string public function getAuthenticatorClasses(array $firewallData): array { - $authenticatorClasses = []; - - if (!isset($firewallData['guard'])) { - return []; - } - - if (!isset($firewallData['guard']['authenticators'])) { - return []; + if (isset($firewallData['guard'])) { + return array_filter($firewallData['guard']['authenticators'] ?? [], function ($authenticator) { + return class_exists($authenticator); + }); } - foreach ($firewallData['guard']['authenticators'] as $authenticator) { - // skip service id's - as they won't work for autowiring - if (class_exists($authenticator)) { - $authenticatorClasses[] = $authenticator; + if (isset($firewallData['custom_authenticator'])) { + $authenticators = $firewallData['custom_authenticator']; + if (\is_string($authenticators)) { + $authenticators = [$authenticators]; } + + return array_filter($authenticators, function ($authenticator) { + return class_exists($authenticator); + }); } - return $authenticatorClasses; + return []; } public function guessPasswordSetter(SymfonyStyle $io, string $userClass): string diff --git a/src/Security/SecurityConfigUpdater.php b/src/Security/SecurityConfigUpdater.php index 15954c8f7..12a2e3a1c 100644 --- a/src/Security/SecurityConfigUpdater.php +++ b/src/Security/SecurityConfigUpdater.php @@ -190,7 +190,7 @@ private function updatePasswordHashers(UserClassConfiguration $userConfig, strin $newData = $this->manipulator->getData(); if ('password_hashers' === $keyName && isset($newData['security']['encoders'])) { // fallback to "encoders" if the user already defined encoder config - $this->updatePasswordHashers($userClass, $userClass, 'encoders'); + $this->updatePasswordHashers($userConfig, $userClass, 'encoders'); return; } diff --git a/src/Test/MakerTestCase.php b/src/Test/MakerTestCase.php index dd91916e0..b7e9dfebb 100644 --- a/src/Test/MakerTestCase.php +++ b/src/Test/MakerTestCase.php @@ -35,16 +35,19 @@ public function testExecute(MakerTestDetails $makerTestDetails) abstract public function getTestDetails(); + abstract protected function getMakerClass(): string; + + protected function createMakerTest(): MakerTestDetails + { + return new MakerTestDetails($this->getMakerInstance($this->getMakerClass())); + } + protected function executeMakerCommand(MakerTestDetails $testDetails) { if (!class_exists(Process::class)) { throw new \LogicException('The MakerTestCase cannot be run as the Process component is not installed. Try running "compose require --dev symfony/process".'); } - if ($testDetails->shouldSkip()) { - $this->markTestSkipped($testDetails->getSkipMessage()); - } - if (!$testDetails->isSupportedByCurrentPhpVersion()) { $this->markTestSkipped(); } @@ -52,23 +55,26 @@ protected function executeMakerCommand(MakerTestDetails $testDetails) $testEnv = MakerTestEnvironment::create($testDetails); // prepare environment to test - $testEnv->prepare(); + $testEnv->prepareDirectory(); if (!$this->hasRequiredDependencyVersions($testDetails, $testEnv)) { $this->markTestSkipped('Some dependencies versions are too low'); } + $makerRunner = new MakerTestRunner($testEnv); + foreach ($testDetails->getPreRunCallbacks() as $preRunCallback) { + $preRunCallback($makerRunner); + } + + $callback = $testDetails->getRunCallback(); + $callback($makerRunner); + // run tests - $makerTestProcess = $testEnv->runMaker(); $files = $testEnv->getGeneratedFilesFromOutputText(); foreach ($files as $file) { $this->assertTrue($testEnv->fileExists($file), sprintf('The file "%s" does not exist after generation', $file)); - if (\PHP_VERSION_ID >= 80000) { - continue; - } - if ('.php' === substr($file, -4)) { $csProcess = $testEnv->runPhpCSFixer($file); @@ -85,19 +91,6 @@ protected function executeMakerCommand(MakerTestDetails $testDetails) $this->assertTrue($csProcess->isSuccessful(), sprintf('File "%s" has a twig-cs problem: %s', $file, $csProcess->getErrorOutput()."\n".$csProcess->getOutput())); } } - - // run internal tests - $internalTestProcess = $testEnv->runInternalTests(); - if (null !== $internalTestProcess) { - $this->assertTrue($internalTestProcess->isSuccessful(), sprintf("Error while running the PHPUnit tests *in* the project: \n\n %s \n\n Command Output: %s", $internalTestProcess->getErrorOutput()."\n".$internalTestProcess->getOutput(), $makerTestProcess->getErrorOutput()."\n".$makerTestProcess->getOutput())); - } - - // checkout user asserts - if (null === $testDetails->getAssert()) { - $this->assertStringContainsString('Success', $makerTestProcess->getOutput(), $makerTestProcess->getErrorOutput()); - } else { - ($testDetails->getAssert())($makerTestProcess->getOutput(), $testEnv->getPath()); - } } protected function assertContainsCount(string $needle, string $haystack, int $count) @@ -105,7 +98,7 @@ protected function assertContainsCount(string $needle, string $haystack, int $co $this->assertEquals(1, substr_count($haystack, $needle), sprintf('Found more than %d occurrences of "%s" in "%s"', $count, $needle, $haystack)); } - protected function getMakerInstance(string $makerClass): MakerInterface + private function getMakerInstance(string $makerClass): MakerInterface { if (null === $this->kernel) { $this->kernel = $this->createKernel(); @@ -150,4 +143,24 @@ private function hasRequiredDependencyVersions(MakerTestDetails $testDetails, Ma return true; } + + public static function assertStringContainsString(string $needle, string $haystack, string $message = ''): void + { + if (method_exists(TestCase::class, 'assertStringContainsString')) { + parent::assertStringContainsString($needle, $haystack, $message); + } else { + // legacy for older phpunit versions (e.g. older php version on CI) + self::assertContains($needle, $haystack, $message); + } + } + + public static function assertStringNotContainsString(string $needle, string $haystack, string $message = ''): void + { + if (method_exists(TestCase::class, 'assertStringNotContainsString')) { + parent::assertStringNotContainsString($needle, $haystack, $message); + } else { + // legacy for older phpunit versions (e.g. older php version on CI) + self::assertNotContains($needle, $haystack, $message); + } + } } diff --git a/src/Test/MakerTestDetails.php b/src/Test/MakerTestDetails.php index 0ad05c315..b7d1618fa 100644 --- a/src/Test/MakerTestDetails.php +++ b/src/Test/MakerTestDetails.php @@ -18,56 +18,33 @@ final class MakerTestDetails { private $maker; - private $inputs; + private $runCallback; - private $fixtureFilesPath; - - private $deletedFiles = []; - - private $replacements = []; - - private $postMakeReplacements = []; - - private $preMakeCommands = []; - - private $postMakeCommands = []; - - private $assert; + private $preRunCallbacks = []; private $extraDependencies = []; - private $argumentsString = ''; - - private $commandAllowedToFail = false; - private $rootNamespace = 'App'; private $requiredPhpVersion; private $requiredPackageVersions = []; - private $guardAuthenticators = []; - - private $shouldSkip = false; - private $skipMessage; - - /** - * @return static - */ - public static function createTest(MakerInterface $maker, array $inputs) + public function __construct(MakerInterface $maker) { - return new static($maker, $inputs); + $this->maker = $maker; } - private function __construct(MakerInterface $maker, array $inputs) + public function run(\Closure $callback): self { - $this->inputs = $inputs; - $this->maker = $maker; + $this->runCallback = $callback; + + return $this; } - public function setFixtureFilesPath(string $fixtureFilesPath): self + public function preRun(\Closure $callback): self { - $this->fixtureFilesPath = $fixtureFilesPath; + $this->preRunCallbacks[] = $callback; return $this; } @@ -84,133 +61,9 @@ public function changeRootNamespace(string $rootNamespace): self return $this; } - public function addPreMakeCommand(string $preMakeCommand): self - { - $this->preMakeCommands[] = $preMakeCommand; - - return $this; - } - - public function addPostMakeCommand(string $postMakeCommand): self - { - $this->postMakeCommands[] = $postMakeCommand; - - return $this; - } - - public function deleteFile(string $filename): self - { - $this->deletedFiles[] = $filename; - - return $this; - } - - public function getFilesToDelete(): array - { - return $this->deletedFiles; - } - - public function addReplacement(string $filename, string $find, string $replace): self - { - $this->replacements[] = [ - 'filename' => $filename, - 'find' => $find, - 'replace' => $replace, - ]; - - return $this; - } - - public function addPostMakeReplacement(string $filename, string $find, string $replace): self - { - $this->postMakeReplacements[] = [ - 'filename' => $filename, - 'find' => $find, - 'replace' => $replace, - ]; - - return $this; - } - - public function configureDatabase(bool $createSchema = true): self - { - // currently, we need to replace this in *both* files so we can also - // run bin/console commands - $this - ->addReplacement( - '.env', - 'postgresql://symfony:ChangeMe@127.0.0.1:5432/app?serverVersion=13&charset=utf8', - getenv('TEST_DATABASE_DSN') - ) - ; - - // Flex includes a recipe to suffix the dbname w/ "_test" - lets keep - // things simple for these tests and not do that. - $this->addReplacement( - 'config/packages/test/doctrine.yaml', - "dbname_suffix: '_test%env(default::TEST_TOKEN)%'", - '') - ; - - // this looks silly, but it's the only way to drop the database *for sure*, - // as doctrine:database:drop will error if there is no database - // also, skip for SQLITE, as it does not support --if-not-exists - if (0 !== strpos(getenv('TEST_DATABASE_DSN'), 'sqlite://')) { - $this->addPreMakeCommand('php bin/console doctrine:database:create --env=test --if-not-exists'); - } - $this->addPreMakeCommand('php bin/console doctrine:database:drop --env=test --force'); - - $this->addPreMakeCommand('php bin/console doctrine:database:create --env=test'); - if ($createSchema) { - $this->addPreMakeCommand('php bin/console doctrine:schema:create --env=test'); - } - - return $this; - } - - public function updateSchemaAfterCommand(): self - { - $this->addPostMakeCommand('php bin/console doctrine:schema:update --env=test --force'); - - return $this; - } - - /** - * Pass a callable that will be called after the maker command has been run. - * - * $test->assert(function(string $output, string $directory) { - * // $output is the command output text - * // $directory is the directory where the project lives - * }) - * - * @param callable $assert - * - * @return MakerTestDetails - */ - public function assert($assert): self - { - $this->assert = $assert; - - return $this; - } - - public function addExtraDependencies(string $packageName): self - { - $this->extraDependencies[] = $packageName; - - return $this; - } - - public function setArgumentsString(string $argumentsString): self + public function addExtraDependencies(string ...$packages): self { - $this->argumentsString = $argumentsString; - - return $this; - } - - public function setCommandAllowedToFail(bool $commandAllowedToFail): self - { - $this->commandAllowedToFail = $commandAllowedToFail; + $this->extraDependencies += $packages; return $this; } @@ -229,23 +82,6 @@ public function addRequiredPackageVersion(string $packageName, string $versionCo return $this; } - public function setGuardAuthenticator(string $firewallName, string $id): self - { - $this->guardAuthenticators[$firewallName] = $id; - - return $this; - } - - public function getInputs(): array - { - return $this->inputs; - } - - public function getFixtureFilesPath() - { - return $this->fixtureFilesPath; - } - public function getUniqueCacheDirectoryName(): string { // for cache purposes, only the dependencies are important! @@ -253,40 +89,12 @@ public function getUniqueCacheDirectoryName(): string return 'maker_'.strtolower($this->getRootNamespace()).'_'.md5(serialize($this->getDependencies())); } - public function getPreMakeCommands(): array - { - return $this->preMakeCommands; - } - - public function getPostMakeCommands(): array - { - return $this->postMakeCommands; - } - - public function getReplacements(): array - { - return $this->replacements; - } - - public function getPostMakeReplacements(): array - { - return $this->postMakeReplacements; - } - public function getMaker(): MakerInterface { return $this->maker; } - /** - * @return callable - */ - public function getAssert() - { - return $this->assert; - } - - public function getDependencies() + public function getDependencies(): array { $depBuilder = $this->getDependencyBuilder(); @@ -297,7 +105,7 @@ public function getDependencies() ); } - public function getExtraDependencies() + public function getExtraDependencies(): array { return $this->extraDependencies; } @@ -310,55 +118,30 @@ public function getDependencyBuilder(): DependencyBuilder return $depBuilder; } - public function getArgumentsString(): string - { - return $this->argumentsString; - } - - public function isCommandAllowedToFail(): bool - { - return $this->commandAllowedToFail; - } - public function isSupportedByCurrentPhpVersion(): bool { return null === $this->requiredPhpVersion || \PHP_VERSION_ID >= $this->requiredPhpVersion; } - public function getGuardAuthenticators(): array - { - return $this->guardAuthenticators; - } - public function getRequiredPackageVersions(): array { return $this->requiredPackageVersions; } - public function skip(string $message) + public function getRunCallback(): \Closure { - $this->shouldSkip = true; - $this->skipMessage = $message; - - return $this; - } - - public function shouldSkip(): bool - { - return $this->shouldSkip; - } + if (!$this->runCallback) { + throw new \Exception('Don\'t forget to call ->run()'); + } - public function getSkipMessage(): ?string - { - return $this->skipMessage; + return $this->runCallback; } - public function useDoctrineAttributeMapping(): self + /** + * @return \Closure[] + */ + public function getPreRunCallbacks(): array { - return $this->addReplacement( - 'config/packages/doctrine.yaml', - 'type: annotation', - 'type: attribute' - ); + return $this->preRunCallbacks; } } diff --git a/src/Test/MakerTestEnvironment.php b/src/Test/MakerTestEnvironment.php index ddb8f5f60..710c4ce82 100644 --- a/src/Test/MakerTestEnvironment.php +++ b/src/Test/MakerTestEnvironment.php @@ -11,11 +11,7 @@ namespace Symfony\Bundle\MakerBundle\Test; -use Symfony\Bundle\MakerBundle\Util\YamlSourceManipulator; use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\Finder\Finder; -use Symfony\Component\HttpClient\HttpClient; -use Symfony\Component\Process\Exception\ProcessFailedException; use Symfony\Component\Process\InputStream; /** @@ -32,7 +28,6 @@ final class MakerTestEnvironment private $cachePath; private $flexPath; private $path; - private $targetSkeletonVersion; /** * @var MakerTestProcess @@ -56,7 +51,12 @@ private function __construct(MakerTestDetails $testDetails) $targetVersion = $this->getTargetSkeletonVersion(); $this->flexPath = $this->cachePath.'/flex_project'.$targetVersion; - $this->path = $this->cachePath.\DIRECTORY_SEPARATOR.$testDetails->getUniqueCacheDirectoryName().$targetVersion; + $directoryName = $targetVersion ?: 'current'; + if (str_ends_with($directoryName, '.*')) { + $directoryName = substr($directoryName, 0, -2); + } + + $this->path = $this->cachePath.\DIRECTORY_SEPARATOR.$testDetails->getUniqueCacheDirectoryName().'_'.$directoryName; } public static function create(MakerTestDetails $testDetails): self @@ -126,9 +126,10 @@ private function changeRootNamespaceIfNeeded(): void } $this->processReplacements($replacements, $this->path); + $this->runCommand('composer dump-autoload'); } - public function prepare(): void + public function prepareDirectory(): void { if (!$this->fs->exists($this->flexPath)) { $this->buildFlexSkeleton(); @@ -161,7 +162,7 @@ public function prepare(): void MakerTestProcess::create('git diff --quiet || ( git config user.name "symfony" && git config user.email "test@symfony.com" && git add . && git commit -a -m "second commit" )', $this->path )->run(); - } catch (ProcessFailedException $e) { + } catch (\Exception $e) { $this->fs->remove($this->path); throw $e; @@ -169,81 +170,25 @@ public function prepare(): void } else { MakerTestProcess::create('git reset --hard && git clean -fd', $this->path)->run(); } - - if (null !== $this->testDetails->getFixtureFilesPath()) { - // move fixture files into directory - $finder = new Finder(); - $finder->in($this->testDetails->getFixtureFilesPath())->files(); - - foreach ($finder as $file) { - if ($file->getPath() === $this->testDetails->getFixtureFilesPath()) { - continue; - } - - $this->fs->copy($file->getPathname(), $this->path.'/'.$file->getRelativePathname(), true); - } - } - - $this->processReplacements($this->testDetails->getReplacements(), $this->path); - - if ($ignoredFiles = $this->testDetails->getFilesToDelete()) { - foreach ($ignoredFiles as $file) { - if (file_exists($this->path.'/'.$file)) { - $this->fs->remove($this->path.'/'.$file); - } - } - } - - MakerTestProcess::create('composer dump-autoload', $this->path) - ->run(); } - private function preMake(): void + public function runCommand(string $command): MakerTestProcess { - foreach ($this->testDetails->getPreMakeCommands() as $preCommand) { - MakerTestProcess::create($preCommand, $this->path) - ->run(); - } + return MakerTestProcess::create($command, $this->path)->run(); } - public function runMaker(): MakerTestProcess + public function runMaker(array $inputs, string $argumentsString = '', bool $allowedToFail = false): MakerTestProcess { - // Lets remove cache + // Let's remove cache $this->fs->remove($this->path.'/var/cache'); - $this->preMake(); - - // We don't need ansi coloring in tests! - $testProcess = MakerTestProcess::create( - sprintf('php bin/console %s %s --no-ansi', $this->testDetails->getMaker()::getCommandName(), $this->testDetails->getArgumentsString()), - $this->path, - [ - 'SHELL_INTERACTIVE' => '1', - ], - 10 + $testProcess = $this->createInteractiveCommandProcess( + $this->testDetails->getMaker()::getCommandName(), + $inputs, + $argumentsString ); - if ($userInputs = $this->testDetails->getInputs()) { - $inputStream = new InputStream(); - - // start the command with some input - $inputStream->write(current($userInputs)."\n"); - - $inputStream->onEmpty(function () use ($inputStream, &$userInputs) { - $nextInput = next($userInputs); - if (false === $nextInput) { - $inputStream->close(); - } else { - $inputStream->write($nextInput."\n"); - } - }); - - $testProcess->setInput($inputStream); - } - - $this->runnedMakerProcess = $testProcess->run($this->testDetails->isCommandAllowedToFail()); - - $this->postMake(); + $this->runnedMakerProcess = $testProcess->run($allowedToFail); return $this->runnedMakerProcess; } @@ -284,48 +229,6 @@ public function runTwigCSLint(string $file): MakerTestProcess ->run(true); } - public function runInternalTests(): ?MakerTestProcess - { - $finder = new Finder(); - $finder->in($this->path.'/tests')->files(); - if ($finder->count() > 0) { - // execute the tests that were moved into the project! - return MakerTestProcess::create(sprintf('php %s', $this->path.'/bin/phpunit'), $this->path) - ->run(true); - } - - return null; - } - - private function postMake(): void - { - $this->processReplacements($this->testDetails->getPostMakeReplacements(), $this->path); - - $guardAuthenticators = $this->testDetails->getGuardAuthenticators(); - if (!empty($guardAuthenticators)) { - $yaml = file_get_contents($this->path.'/config/packages/security.yaml'); - $manipulator = new YamlSourceManipulator($yaml); - $data = $manipulator->getData(); - - foreach ($guardAuthenticators as $firewallName => $id) { - if (!isset($data['security']['firewalls'][$firewallName])) { - throw new \Exception(sprintf('Could not find firewall "%s"', $firewallName)); - } - - $data['security']['firewalls'][$firewallName]['guard'] = [ - 'authenticators' => [$id], - ]; - } - $manipulator->setData($data); - file_put_contents($this->path.'/config/packages/security.yaml', $manipulator->getContents()); - } - - foreach ($this->testDetails->getPostMakeCommands() as $postCommand) { - MakerTestProcess::create($postCommand, $this->path) - ->run(); - } - } - private function buildFlexSkeleton(): void { $targetVersion = $this->getTargetSkeletonVersion(); @@ -336,18 +239,6 @@ private function buildFlexSkeleton(): void $this->cachePath )->run(); - if (false !== strpos($targetVersion, 'dev')) { - // make sure that dev versions allow dev deps - // for the current stable minor of Symfony, by default, - // minimum-stability is NOT dev, even when getting the -dev version - // of symfony/skeleton - MakerTestProcess::create('composer config minimum-stability dev', $this->flexPath) - ->run(); - - MakerTestProcess::create(['composer', 'update'], $this->flexPath) - ->run(); - } - $rootPath = str_replace('\\', '\\\\', realpath(__DIR__.'/../..')); // processes any changes needed to the Flex project @@ -405,22 +296,83 @@ private function buildFlexSkeleton(): void )->run(); } - private function processReplacements(array $replacements, $rootDir): void + private function processReplacements(array $replacements, string $rootDir): void { foreach ($replacements as $replacement) { - $path = realpath($rootDir.'/'.$replacement['filename']); + $this->processReplacement($rootDir, $replacement['filename'], $replacement['find'], $replacement['replace']); + } + } + + public function processReplacement(string $rootDir, string $filename, string $find, string $replace, bool $allowNotFound = false): void + { + $path = realpath($rootDir.'/'.$filename); - if (!$this->fs->exists($path)) { - throw new \Exception(sprintf('Could not find file "%s" to process replacements inside "%s"', $replacement['filename'], $rootDir)); + if (!$this->fs->exists($path)) { + if ($allowNotFound) { + return; } - $contents = file_get_contents($path); - if (false === strpos($contents, $replacement['find'])) { - throw new \Exception(sprintf('Could not find "%s" inside "%s"', $replacement['find'], $replacement['filename'])); + throw new \Exception(sprintf('Could not find file "%s" to process replacements inside "%s"', $filename, $rootDir)); + } + + $contents = file_get_contents($path); + if (false === strpos($contents, $find)) { + if ($allowNotFound) { + return; } - file_put_contents($path, str_replace($replacement['find'], $replacement['replace'], $contents)); + throw new \Exception(sprintf('Could not find "%s" inside "%s"', $find, $filename)); + } + + file_put_contents($path, str_replace($find, $replace, $contents)); + } + + public function createInteractiveCommandProcess(string $commandName, array $userInputs, string $argumentsString = ''): MakerTestProcess + { + // We don't need ansi coloring in tests! + $process = MakerTestProcess::create( + sprintf('php bin/console %s %s --no-ansi', $commandName, $argumentsString), + $this->path, + [ + 'SHELL_INTERACTIVE' => '1', + ], + 10 + ); + + if ($userInputs) { + $inputStream = new InputStream(); + + // start the command with some input + $inputStream->write(current($userInputs)."\n"); + + $inputStream->onEmpty(function () use ($inputStream, &$userInputs) { + $nextInput = next($userInputs); + if (false === $nextInput) { + $inputStream->close(); + } else { + $inputStream->write($nextInput."\n"); + } + }); + + $process->setInput($inputStream); } + + return $process; + } + + public function getSymfonyVersionInApp(): int + { + $contents = file_get_contents($this->getPath().'/vendor/symfony/http-kernel/Kernel.php'); + $position = strpos($contents, 'VERSION_ID = '); + + return (int) substr($contents, $position + 13, 5); + } + + public function doesClassExistInApp(string $class): bool + { + $classMap = require $this->getPath().'/vendor/composer/autoload_classmap.php'; + + return isset($classMap[$class]); } /** @@ -455,45 +407,8 @@ private function determineMissingDependencies(): array return array_merge($data, $this->testDetails->getExtraDependencies()); } - private function getTargetSkeletonVersion(): string + private function getTargetSkeletonVersion(): ?string { - if (null === $this->targetSkeletonVersion) { - $stability = $_SERVER['SYMFONY_SKELETON_STABILITY'] ?? 'stable'; - - if ('stable' === $stability) { - $this->targetSkeletonVersion = ''; - - return $this->targetSkeletonVersion; - } - - switch ($stability) { - case 'stable-dev': - $version = ($this->getSymfonyVersions())['latest']; - $parts = explode('.', $version); - - $this->targetSkeletonVersion = sprintf('%s.%s.x-dev', $parts[0], $parts[1]); - - break; - case 'dev': - $version = ($this->getSymfonyVersions())['dev']; - $parts = explode('.', $version); - - $this->targetSkeletonVersion = sprintf('%s.%s.x-dev', $parts[0], $parts[1]); - - break; - default: - throw new \InvalidArgumentException('Invalid stability'); - } - } - - return $this->targetSkeletonVersion; - } - - private function getSymfonyVersions(): array - { - $httpClient = HttpClient::create(); - $response = $httpClient->request('GET', 'https://symfony.com/versions.json'); - - return $response->toArray(); + return $_SERVER['SYMFONY_VERSION'] ?? ''; } } diff --git a/src/Test/MakerTestRunner.php b/src/Test/MakerTestRunner.php new file mode 100644 index 000000000..fb0665220 --- /dev/null +++ b/src/Test/MakerTestRunner.php @@ -0,0 +1,260 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\MakerBundle\Test; + +use PHPUnit\Framework\ExpectationFailedException; +use Symfony\Bundle\MakerBundle\Util\ClassSourceManipulator; +use Symfony\Bundle\MakerBundle\Util\YamlSourceManipulator; +use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\Finder\Finder; +use Symfony\Component\Yaml\Yaml; +use Twig\Environment; +use Twig\Loader\FilesystemLoader; + +class MakerTestRunner +{ + private $environment; + private $filesystem; + private $executedMakerProcess; + + public function __construct(MakerTestEnvironment $environment) + { + $this->environment = $environment; + $this->filesystem = new Filesystem(); + } + + public function runMaker(array $inputs, string $argumentsString = '', bool $allowedToFail = false): string + { + $this->executedMakerProcess = $this->environment->runMaker($inputs, $argumentsString, $allowedToFail); + + return $this->executedMakerProcess->getOutput(); + } + + public function copy(string $source, string $destination) + { + $path = __DIR__.'/../../tests/fixtures/'.$source; + + if (!file_exists($path)) { + throw new \Exception(sprintf('Cannot find file "%s"', $path)); + } + + if (is_file($path)) { + $this->filesystem->copy($path, $this->getPath($destination), true); + + return; + } + + // handle a directory copy + $finder = new Finder(); + $finder->in($path)->files(); + + foreach ($finder as $file) { + $this->filesystem->copy($file->getPathname(), $this->getPath($file->getRelativePathname()), true); + } + } + + /** + * When using an authenticator "fixtures" file, this adjusts it to support Symfony 5.2/5.3. + */ + public function adjustAuthenticatorForLegacyPassportInterface(string $filename): void + { + // no adjustment needed on 5.4 and higher + if ($this->getSymfonyVersion() >= 50400) { + return; + } + + $this->replaceInFile( + $filename, + '\\Passport;', + "\\Passport;\nuse Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;" + ); + + $this->replaceInFile( + $filename, + ': Passport', + ': PassportInterface' + ); + } + + public function renderTemplateFile(string $source, string $destination, array $variables): void + { + $twig = new Environment( + new FilesystemLoader(__DIR__.'/../../tests/fixtures') + ); + + $rendered = $twig->render($source, $variables); + + $this->filesystem->mkdir(\dirname($this->getPath($destination))); + file_put_contents($this->getPath($destination), $rendered); + } + + public function getPath(string $filename): string + { + return $this->environment->getPath().'/'.$filename; + } + + public function readYaml(string $filename): array + { + return Yaml::parse(file_get_contents($this->getPath($filename))); + } + + public function getExecutedMakerProcess(): MakerTestProcess + { + if (!$this->executedMakerProcess) { + throw new \Exception('Maker process has not been executed yet.'); + } + + return $this->executedMakerProcess; + } + + public function modifyYamlFile(string $filename, \Closure $callback) + { + $path = $this->getPath($filename); + $manipulator = new YamlSourceManipulator(file_get_contents($path)); + + $newData = $callback($manipulator->getData()); + if (!\is_array($newData)) { + throw new \Exception('The modifyYamlFile() callback must return the final array of data'); + } + $manipulator->setData($newData); + + file_put_contents($path, $manipulator->getContents()); + } + + public function runConsole(string $command, array $inputs, string $arguments = '') + { + $process = $this->environment->createInteractiveCommandProcess( + $command, + $inputs, + $arguments + ); + + $process->run(); + } + + public function runProcess(string $command): void + { + MakerTestProcess::create($command, $this->environment->getPath())->run(); + } + + public function replaceInFile(string $filename, string $find, string $replace, bool $allowNotFound = false): void + { + $this->environment->processReplacement( + $this->environment->getPath(), + $filename, + $find, + $replace, + $allowNotFound + ); + } + + public function removeFromFile(string $filename, string $find, bool $allowNotFound = false): void + { + $this->environment->processReplacement( + $this->environment->getPath(), + $filename, + $find, + '', + $allowNotFound + ); + } + + public function configureDatabase(bool $createSchema = true): void + { + $this->replaceInFile( + '.env', + 'postgresql://symfony:ChangeMe@127.0.0.1:5432/app?serverVersion=13&charset=utf8', + getenv('TEST_DATABASE_DSN') + ); + + // Flex includes a recipe to suffix the dbname w/ "_test" - lets keep + // things simple for these tests and not do that. + $this->removeFromFile( + 'config/packages/test/doctrine.yaml', + "dbname_suffix: '_test%env(default::TEST_TOKEN)%'" + ); + + // this looks silly, but it's the only way to drop the database *for sure*, + // as doctrine:database:drop will error if there is no database + // also, skip for SQLITE, as it does not support --if-not-exists + if (0 !== strpos(getenv('TEST_DATABASE_DSN'), 'sqlite://')) { + $this->runConsole('doctrine:database:create', [], '--env=test --if-not-exists'); + } + $this->runConsole('doctrine:database:drop', [], '--env=test --force'); + + $this->runConsole('doctrine:database:create', [], '--env=test'); + if ($createSchema) { + $this->runConsole('doctrine:schema:create', [], '--env=test'); + } + } + + public function updateSchema(): void + { + $this->runConsole('doctrine:schema:update', [], '--env=test --force'); + } + + public function runTests(): void + { + $internalTestProcess = MakerTestProcess::create( + sprintf('php %s', $this->getPath('/bin/phpunit')), + $this->environment->getPath()) + ->run(true) + ; + + if ($internalTestProcess->isSuccessful()) { + return; + } + + throw new ExpectationFailedException(sprintf("Error while running the PHPUnit tests *in* the project: \n\n %s \n\n Command Output: %s", $internalTestProcess->getErrorOutput()."\n".$internalTestProcess->getOutput(), $this->getExecutedMakerProcess()->getErrorOutput()."\n".$this->getExecutedMakerProcess()->getOutput())); + } + + public function writeFile(string $filename, string $contents): void + { + $this->filesystem->mkdir(\dirname($this->getPath($filename))); + file_put_contents($this->getPath($filename), $contents); + } + + public function addToAutoloader(string $namespace, string $path) + { + $this->replaceInFile( + 'composer.json', + '"App\\\Tests\\\": "tests/",', + sprintf('"App\\\Tests\\\": "tests/",'."\n".' "%s": "%s",', $namespace, $path) + ); + + $this->environment->runCommand('composer dump-autoload'); + } + + public function deleteFile(string $filename): void + { + $this->filesystem->remove($this->getPath($filename)); + } + + public function manipulateClass(string $filename, \Closure $callback): void + { + $contents = file_get_contents($this->getPath($filename)); + $manipulator = new ClassSourceManipulator($contents, true, false, true, true); + $callback($manipulator); + + file_put_contents($this->getPath($filename), $manipulator->getSourceCode()); + } + + public function getSymfonyVersion(): int + { + return $this->environment->getSymfonyVersionInApp(); + } + + public function doesClassExist(string $class): bool + { + return $this->environment->doesClassExistInApp($class); + } +} diff --git a/src/Util/ClassNameValue.php b/src/Util/ClassNameValue.php index 57b155f46..d8c4a8db0 100644 --- a/src/Util/ClassNameValue.php +++ b/src/Util/ClassNameValue.php @@ -29,13 +29,18 @@ public function __construct(string $typeHint, string $fullClassName) public function getShortName(): string { - if ('self' === $this->typeHint) { + if ($this->isSelf()) { return Str::getShortClassName($this->fullClassName); } return $this->typeHint; } + public function isSelf(): bool + { + return 'self' === $this->typeHint; + } + public function __toString() { return $this->getShortName(); diff --git a/src/Util/ClassSourceManipulator.php b/src/Util/ClassSourceManipulator.php index 08bf95dcb..c74dc0641 100644 --- a/src/Util/ClassSourceManipulator.php +++ b/src/Util/ClassSourceManipulator.php @@ -1408,7 +1408,11 @@ private function buildNodeExprByValue($value): Node\Expr if (null === $nodeValue) { if ($value instanceof ClassNameValue) { - $nodeValue = new Node\Expr\ConstFetch(new Node\Name(sprintf('%s::class', $value->getShortName()))); + $nodeValue = new Node\Expr\ConstFetch( + new Node\Name( + sprintf('%s::class', $value->isSelf() ? 'self' : $value->getShortName()) + ) + ); } else { throw new \Exception(sprintf('Cannot build a node expr for value of type "%s"', \gettype($value))); } diff --git a/src/Util/TemplateComponentGenerator.php b/src/Util/TemplateComponentGenerator.php index 2fe12eb11..b55f744ee 100644 --- a/src/Util/TemplateComponentGenerator.php +++ b/src/Util/TemplateComponentGenerator.php @@ -54,10 +54,10 @@ public function generateRouteForControllerMethod(string $routePath, string $rout $attribute .= ', methods: ['; foreach ($methods as $method) { - $attribute .= sprintf('\'%s\',', $method); + $attribute .= sprintf('\'%s\', ', $method); } - $attribute = rtrim($attribute, ','); + $attribute = rtrim($attribute, ', '); $attribute .= ']'; } @@ -74,10 +74,10 @@ public function generateRouteForControllerMethod(string $routePath, string $rout $annotation .= ', methods={'; foreach ($methods as $method) { - $annotation .= sprintf('"%s",', $method); + $annotation .= sprintf('"%s", ', $method); } - $annotation = rtrim($annotation, ','); + $annotation = rtrim($annotation, ', '); $annotation .= '}'; } diff --git a/tests/Command/MakerCommandTest.php b/tests/Command/MakerCommandTest.php index ea49c0cad..14429cb72 100644 --- a/tests/Command/MakerCommandTest.php +++ b/tests/Command/MakerCommandTest.php @@ -26,7 +26,9 @@ class MakerCommandTest extends TestCase public function testExceptionOnMissingDependencies(): void { $this->expectException(RuntimeCommandException::class); - $this->expectExceptionMessageMatches('/composer require foo-package/'); + if (method_exists($this, 'expectExceptionMessageMatches')) { + $this->expectExceptionMessageMatches('/composer require foo-package/'); + } $maker = $this->createMock(MakerInterface::class); $maker @@ -61,6 +63,11 @@ public function testExceptionOnUnknownRootNamespace(): void $tester = new CommandTester($command); $tester->execute([]); - self::assertStringContainsString('using a namespace other than "Unknown"', $tester->getDisplay()); + if (method_exists(self::class, 'assertStringContainsString')) { + self::assertStringContainsString('using a namespace other than "Unknown"', $tester->getDisplay()); + } else { + // legacy for older phpunit versions (e.g. older php version on CI) + self::assertContains('using a namespace other than "Unknown"', $tester->getDisplay()); + } } } diff --git a/tests/Docker/DatabaseServicesTest.php b/tests/Docker/DatabaseServicesTest.php index 1888cef9e..38e35f9cf 100644 --- a/tests/Docker/DatabaseServicesTest.php +++ b/tests/Docker/DatabaseServicesTest.php @@ -43,7 +43,7 @@ public function testSkeletonReturnArrayForDesiredDatabase(string $databaseName): $result = DockerDatabaseServices::getDatabaseSkeleton($databaseName, 'latest'); self::assertArrayHasKey('image', $result); - self::assertStringContainsStringIgnoringCase($databaseName, $result['image']); + $this->assertStringContainsIgnoringCase($databaseName, $result['image']); } /** @@ -65,4 +65,14 @@ public function testSuggestedVersion(string $databaseName): void ('postgres' === strtolower($databaseName)) ? self::assertSame('alpine', $result) : self::assertSame('latest', $result); } + + private function assertStringContainsIgnoringCase(string $needle, string $haystack): void + { + if (method_exists(self::class, 'assertStringContainsString')) { + self::assertStringContainsStringIgnoringCase($needle, $haystack); + } else { + // legacy for older phpunit versions (e.g. older php version on CI) + self::assertContains(strtolower($needle), strtolower($haystack)); + } + } } diff --git a/tests/Maker/MakeAuthenticatorTest.php b/tests/Maker/MakeAuthenticatorTest.php index 345c009a4..d9422b491 100644 --- a/tests/Maker/MakeAuthenticatorTest.php +++ b/tests/Maker/MakeAuthenticatorTest.php @@ -13,97 +13,116 @@ use Symfony\Bundle\MakerBundle\Maker\MakeAuthenticator; use Symfony\Bundle\MakerBundle\Test\MakerTestCase; -use Symfony\Bundle\MakerBundle\Test\MakerTestDetails; -use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\Yaml\Yaml; +use Symfony\Bundle\MakerBundle\Test\MakerTestRunner; +use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; +use Symfony\Component\Security\Core\User\UserInterface; class MakeAuthenticatorTest extends MakerTestCase { + protected function getMakerClass(): string + { + return MakeAuthenticator::class; + } + public function getTestDetails() { - yield 'auth_empty_one_firewall' => [ - MakerTestDetails::createTest( - $this->getMakerInstance(MakeAuthenticator::class), - [ + yield 'auth_empty_one_firewall' => [$this->createMakerTest() + ->addRequiredPackageVersion('symfony/security-bundle', '>=5.2') + ->run(function (MakerTestRunner $runner) { + $output = $runner->runMaker([ // authenticator type => empty-auth 0, // authenticator class name 'AppCustomAuthenticator', - ] - ) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeAuthenticator') - ->assert( - function (string $output, string $directory) { - $this->assertStringContainsString('Success', $output); - - $fs = new Filesystem(); - $this->assertTrue($fs->exists(sprintf('%s/src/Security/AppCustomAuthenticator.php', $directory))); - - $securityConfig = Yaml::parse(file_get_contents(sprintf('%s/config/packages/security.yaml', $directory))); - $this->assertEquals( - 'App\\Security\\AppCustomAuthenticator', - $securityConfig['security']['firewalls']['main']['guard']['authenticators'][0] - ); - } - ), + ]); + + $this->assertStringContainsString('Success', $output); + $this->assertFileExists($runner->getPath('src/Security/AppCustomAuthenticator.php')); + $securityConfig = $runner->readYaml('config/packages/security.yaml'); + $this->assertEquals( + 'App\\Security\\AppCustomAuthenticator', + $securityConfig['security']['firewalls']['main']['custom_authenticator'] + ); + }), ]; - yield 'auth_empty_multiple_firewalls' => [ - MakerTestDetails::createTest( - $this->getMakerInstance(MakeAuthenticator::class), - [ + yield 'auth_empty_multiple_firewalls' => [$this->createMakerTest() + ->addRequiredPackageVersion('symfony/security-bundle', '>=5.2') + ->run(function (MakerTestRunner $runner) { + $runner->modifyYamlFile('config/packages/security.yaml', function (array $config) { + $config['security']['firewalls']['second']['lazy'] = true; + + return $config; + }); + + $output = $runner->runMaker([ // authenticator type => empty-auth 0, // class name 'AppCustomAuthenticator', - // firewall name + // firewall name (1 will be the "second" firewall) 1, - ] - ) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeAuthenticatorMultipleFirewalls') - ->assert( - function (string $output, string $directory) { - $this->assertStringContainsString('Success', $output); - - $securityConfig = Yaml::parse(file_get_contents(sprintf('%s/config/packages/security.yaml', $directory))); - $this->assertEquals( - 'App\\Security\\AppCustomAuthenticator', - $securityConfig['security']['firewalls']['second']['guard']['authenticators'][0] - ); - } - ), + ]); + + $this->assertStringContainsString('Success', $output); + $securityConfig = $runner->readYaml('config/packages/security.yaml'); + $this->assertEquals( + 'App\\Security\\AppCustomAuthenticator', + $securityConfig['security']['firewalls']['second']['custom_authenticator'] + ); + }), ]; - yield 'auth_empty_existing_authenticator' => [ - MakerTestDetails::createTest( - $this->getMakerInstance(MakeAuthenticator::class), - [ + yield 'auth_empty_existing_authenticator' => [$this->createMakerTest() + ->addRequiredPackageVersion('symfony/security-bundle', '>=5.2') + ->run(function (MakerTestRunner $runner) { + $runner->copy( + 'make-auth/BlankAuthenticator.php', + 'src/Security/BlankAuthenticator.php' + ); + $runner->adjustAuthenticatorForLegacyPassportInterface('src/Security/BlankAuthenticator.php'); + + $runner->modifyYamlFile('config/packages/security.yaml', function (array $config) { + $config['security']['firewalls']['main']['custom_authenticator'] = 'App\Security\BlankAuthenticator'; + + return $config; + }); + + $output = $runner->runMaker([ // authenticator type => empty-auth 0, // class name 'AppCustomAuthenticator', // firewall name 1, - ] - ) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeAuthenticatorExistingAuthenticator') - ->assert( - function (string $output, string $directory) { - $this->assertStringContainsString('Success', $output); - - $securityConfig = Yaml::parse(file_get_contents(sprintf('%s/config/packages/security.yaml', $directory))); - $this->assertEquals( - 'App\\Security\\AppCustomAuthenticator', - $securityConfig['security']['firewalls']['main']['guard']['entry_point'] - ); - } - ), + ]); + + $this->assertStringContainsString('Success', $output); + + $securityConfig = $runner->readYaml('config/packages/security.yaml'); + $this->assertEquals( + 'App\\Security\\AppCustomAuthenticator', + $securityConfig['security']['firewalls']['main']['custom_authenticator'][1] + ); + }), ]; - yield 'auth_empty_multiple_firewalls_existing_authenticator' => [ - MakerTestDetails::createTest( - $this->getMakerInstance(MakeAuthenticator::class), - [ + yield 'auth_empty_multiple_firewalls_existing_authenticator' => [$this->createMakerTest() + ->addRequiredPackageVersion('symfony/security-bundle', '>=5.2') + ->run(function (MakerTestRunner $runner) { + $runner->copy( + 'make-auth/BlankAuthenticator.php', + 'src/Security/BlankAuthenticator.php' + ); + $runner->adjustAuthenticatorForLegacyPassportInterface('src/Security/BlankAuthenticator.php'); + + $runner->modifyYamlFile('config/packages/security.yaml', function (array $config) { + $config['security']['firewalls']['second'] = ['lazy' => true, 'custom_authenticator' => 'App\Security\BlankAuthenticator']; + + return $config; + }); + + $output = $runner->runMaker([ // authenticator type => empty-auth 0, // class name @@ -112,26 +131,26 @@ function (string $output, string $directory) { 1, // entry point 1, - ] - ) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeAuthenticatorMultipleFirewallsExistingAuthenticator') - ->assert( - function (string $output, string $directory) { - $this->assertStringContainsString('Success', $output); - - $securityConfig = Yaml::parse(file_get_contents(sprintf('%s/config/packages/security.yaml', $directory))); - $this->assertEquals( - 'App\\Security\\AppCustomAuthenticator', - $securityConfig['security']['firewalls']['second']['guard']['entry_point'] - ); - } - ), + ]); + + $this->assertStringContainsString('Success', $output); + + $securityConfig = $runner->readYaml('config/packages/security.yaml'); + $this->assertEquals( + 'App\\Security\\AppCustomAuthenticator', + $securityConfig['security']['firewalls']['second']['custom_authenticator'][1] + ); + }), ]; - yield 'auth_login_form_user_entity_with_encoder' => [ - MakerTestDetails::createTest( - $this->getMakerInstance(MakeAuthenticator::class), - [ + yield 'auth_login_form_user_entity_with_hasher' => [$this->createMakerTest() + // we use new security + depend on hasher + ->addRequiredPackageVersion('symfony/security-bundle', '>=5.3') + ->addExtraDependencies('doctrine', 'twig', 'symfony/form') + ->run(function (MakerTestRunner $runner) { + $this->makeUser($runner, 'userEmail'); + + $output = $runner->runMaker([ // authenticator type => login-form 1, // class name @@ -141,30 +160,25 @@ function (string $output, string $directory) { // field name 'userEmail', 'no', - ] - ) - ->addExtraDependencies('doctrine') - ->addExtraDependencies('twig') - ->addExtraDependencies('symfony/form') - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeAuthenticatorLoginFormUserEntity') - ->configureDatabase() - ->updateSchemaAfterCommand() - ->assert( - function (string $output, string $directory) { - $this->assertStringContainsString('Success', $output); - - $fs = new Filesystem(); - $this->assertTrue($fs->exists(sprintf('%s/src/Controller/SecurityController.php', $directory))); - $this->assertTrue($fs->exists(sprintf('%s/templates/security/login.html.twig', $directory))); - $this->assertTrue($fs->exists(sprintf('%s/src/Security/AppCustomAuthenticator.php', $directory))); - } - ), + ]); + + $this->runLoginTest($runner, 'userEmail'); + + $this->assertStringContainsString('Success', $output); + + $this->assertFileExists($runner->getPath('src/Controller/SecurityController.php')); + $this->assertFileExists($runner->getPath('templates/security/login.html.twig')); + $this->assertFileExists($runner->getPath('src/Security/AppCustomAuthenticator.php')); + }), ]; - yield 'auth_login_form_custom_username_field' => [ - MakerTestDetails::createTest( - $this->getMakerInstance(MakeAuthenticator::class), - [ + yield 'auth_login_form_no_entity_custom_username_field' => [$this->createMakerTest() + ->addRequiredPackageVersion('symfony/security-bundle', '>=5.2') + ->addExtraDependencies('doctrine/annotations', 'twig', 'symfony/form') + ->run(function (MakerTestRunner $runner) { + $this->makeUser($runner, 'userEmail', false); + + $runner->runMaker([ // authenticator type => login-form 1, // class name @@ -176,60 +190,25 @@ function (string $output, string $directory) { // username field => userEmail 0, 'no', - ] - ) - ->addExtraDependencies('doctrine/annotations') - ->addExtraDependencies('twig') - ->addExtraDependencies('symfony/form') - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeAuthenticatorLoginFormCustomUsernameField'), - ]; + ]); - yield 'auth_login_form_user_entity_no_encoder' => [ - MakerTestDetails::createTest( - $this->getMakerInstance(MakeAuthenticator::class), - [ - // authenticator type => login-form - 1, - // class name - 'AppCustomAuthenticator', - // controller name - 'SecurityController', - 'no', - ] - ) - ->addExtraDependencies('doctrine') - ->addExtraDependencies('twig') - ->addExtraDependencies('symfony/form') - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeAuthenticatorLoginFormUserEntityNoEncoder') - ->configureDatabase() - ->updateSchemaAfterCommand(), + $runner->runTests(); + $this->runLoginTest( + $runner, + 'userEmail', + false, + 'App\\Security\\User' + ); + }), ]; - yield 'auth_login_form_user_not_entity_with_encoder' => [ - MakerTestDetails::createTest( - $this->getMakerInstance(MakeAuthenticator::class), - [ - // authenticator type => login-form - 1, - // class name - 'AppCustomAuthenticator', - // controller name - 'SecurityController', - // user class - 'App\Security\User', - 'no', - ] - ) - ->addExtraDependencies('twig') - ->addExtraDependencies('doctrine/annotations') - ->addExtraDependencies('symfony/form') - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeAuthenticatorLoginFormUserNotEntity'), - ]; + yield 'auth_login_form_user_not_entity_with_hasher' => [$this->createMakerTest() + ->addRequiredPackageVersion('symfony/security-bundle', '>=5.2') + ->addExtraDependencies('doctrine/annotations', 'twig', 'symfony/form') + ->run(function (MakerTestRunner $runner) { + $this->makeUser($runner, 'email', false); - yield 'auth_login_form_user_not_entity_no_encoder' => [ - MakerTestDetails::createTest( - $this->getMakerInstance(MakeAuthenticator::class), - [ + $runner->runMaker([ // authenticator type => login-form 1, // class name @@ -239,18 +218,22 @@ function (string $output, string $directory) { // user class 'App\Security\User', 'no', - ] - ) - ->addExtraDependencies('twig') - ->addExtraDependencies('doctrine/annotations') - ->addExtraDependencies('symfony/form') - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeAuthenticatorLoginFormUserNotEntityNoEncoder'), + ]); + }), ]; - yield 'auth_login_form_existing_controller' => [ - MakerTestDetails::createTest( - $this->getMakerInstance(MakeAuthenticator::class), - [ + yield 'auth_login_form_existing_controller' => [$this->createMakerTest() + ->addRequiredPackageVersion('symfony/security-bundle', '>=5.2') + ->addExtraDependencies('doctrine', 'twig', 'symfony/form') + ->run(function (MakerTestRunner $runner) { + $this->makeUser($runner, 'email'); + + $runner->copy( + 'make-auth/SecurityController-empty.php', + 'src/Controller/SecurityController.php' + ); + + $runner->runMaker([ // authenticator type => login-form 1, // class name @@ -258,20 +241,19 @@ function (string $output, string $directory) { // controller name 'SecurityController', 'no', - ] - ) - ->addExtraDependencies('doctrine') - ->addExtraDependencies('twig') - ->addExtraDependencies('symfony/form') - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeAuthenticatorLoginFormExistingController') - ->configureDatabase() - ->updateSchemaAfterCommand(), + ]); + + $this->runLoginTest($runner, 'email'); + }), ]; - yield 'auth_login_form_user_entity_with_encoder_logout' => [ - MakerTestDetails::createTest( - $this->getMakerInstance(MakeAuthenticator::class), - [ + yield 'auth_login_form_user_entity_with_logout' => [$this->createMakerTest() + ->addRequiredPackageVersion('symfony/security-bundle', '>=5.2') + ->addExtraDependencies('doctrine', 'twig', 'symfony/form') + ->run(function (MakerTestRunner $runner) { + $this->makeUser($runner, 'userEmail'); + + $output = $runner->runMaker([ // authenticator type => login-form 1, // class name @@ -280,96 +262,116 @@ function (string $output, string $directory) { 'SecurityController', // logout support 'yes', - ] - ) - ->addExtraDependencies('doctrine') - ->addExtraDependencies('twig') - ->addExtraDependencies('symfony/form') - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeAuthenticatorLoginFormUserEntityLogout') - ->configureDatabase() - ->updateSchemaAfterCommand() - ->assert( - function (string $output, string $directory) { - $this->assertStringContainsString('Success', $output); - - $fs = new Filesystem(); - $this->assertTrue($fs->exists(sprintf('%s/src/Controller/SecurityController.php', $directory))); - $this->assertTrue($fs->exists(sprintf('%s/templates/security/login.html.twig', $directory))); - $this->assertTrue($fs->exists(sprintf('%s/src/Security/AppCustomAuthenticator.php', $directory))); - - $securityConfig = Yaml::parse(file_get_contents(sprintf('%s/config/packages/security.yaml', $directory))); - $this->assertEquals( - 'app_logout', - $securityConfig['security']['firewalls']['main']['logout']['path'] - ); - } - ), + ]); + + $this->runLoginTest($runner, 'userEmail', true, 'App\\Entity\\User', true); + + $this->assertStringContainsString('Success', $output); + + $this->assertFileExists($runner->getPath('src/Controller/SecurityController.php')); + $this->assertFileExists($runner->getPath('templates/security/login.html.twig')); + $this->assertFileExists($runner->getPath('src/Security/AppCustomAuthenticator.php')); + + $securityConfig = $runner->readYaml('config/packages/security.yaml'); + $this->assertEquals( + 'app_logout', + $securityConfig['security']['firewalls']['main']['logout']['path'] + ); + }), ]; - yield 'security_52_empty_authenticator' => [ - MakerTestDetails::createTest( - $this->getMakerInstance(MakeAuthenticator::class), - [ + yield 'auth_legacy_guard_empty_one_firewall' => [$this->createMakerTest() + ->addRequiredPackageVersion('symfony/security-bundle', '<5.2') + ->run(function (MakerTestRunner $runner) { + $output = $runner->runMaker([ // authenticator type => empty-auth 0, // authenticator class name 'AppCustomAuthenticator', - ] - ) - ->setRequiredPhpVersion(70200) - ->addRequiredPackageVersion('symfony/security-bundle', '>=5.2') - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeAuthenticatorSecurity52Empty') - ->assert( - function (string $output, string $directory) { - $this->assertStringContainsString('Success', $output); - - $fs = new Filesystem(); - $this->assertTrue($fs->exists(sprintf('%s/src/Security/AppCustomAuthenticator.php', $directory))); - - $securityConfig = Yaml::parse(file_get_contents(sprintf('%s/config/packages/security.yaml', $directory))); - - $this->assertEquals( - 'App\\Security\\AppCustomAuthenticator', - $securityConfig['security']['firewalls']['main']['custom_authenticator'] - ); - } - ), + ]); + + $this->assertStringContainsString('Success', $output); + + $this->assertFileExists($runner->getPath('src/Security/AppCustomAuthenticator.php')); + + $securityConfig = $runner->readYaml('config/packages/security.yaml'); + $this->assertEquals( + 'App\\Security\\AppCustomAuthenticator', + $securityConfig['security']['firewalls']['main']['guard']['authenticators'][0] + ); + }), ]; - yield 'security_52_login_form_authenticator' => [ - MakerTestDetails::createTest( - $this->getMakerInstance(MakeAuthenticator::class), - [ + yield 'auth_legacy_guard_login_form_user_entity_with_encoder' => [$this->createMakerTest() + ->addRequiredPackageVersion('symfony/security-bundle', '<5.2') + ->addExtraDependencies('doctrine', 'twig', 'symfony/form') + ->run(function (MakerTestRunner $runner) { + $this->makeUser($runner, 'userEmail'); + + $output = $runner->runMaker([ // authenticator type => login-form 1, // class name - 'AppTestSecurity52LoginFormAuthenticator', + 'AppCustomAuthenticator', // controller name 'SecurityController', - // User selector field + // field name 'userEmail', - // Logout Url - 'no', - ] - ) - ->setRequiredPhpVersion(70200) - ->addRequiredPackageVersion('symfony/security-bundle', '>=5.2') - ->addExtraDependencies('doctrine') - ->addExtraDependencies('twig') - ->addExtraDependencies('symfony/form') - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeAuthenticatorSecurity52LoginForm') - ->configureDatabase() - ->updateSchemaAfterCommand() - ->assert( - function (string $output, string $directory) { - $this->assertStringContainsString('Success', $output); - - $fs = new Filesystem(); - $this->assertTrue($fs->exists(sprintf('%s/src/Controller/SecurityController.php', $directory))); - $this->assertTrue($fs->exists(sprintf('%s/templates/security/login.html.twig', $directory))); - $this->assertTrue($fs->exists(sprintf('%s/src/Security/AppTestSecurity52LoginFormAuthenticator.php', $directory))); - } - ), + 'no', // log out + ]); + + $this->assertStringContainsString('Success', $output); + $this->runLoginTest($runner, 'userEmail'); + }), ]; } + + private function runLoginTest(MakerTestRunner $runner, string $userIdentifier, bool $isEntity = true, string $userClass = 'App\\Entity\\User', bool $testLogin = false) + { + $runner->renderTemplateFile( + 'make-auth/LoginFlowTest.php.twig', + 'tests/LoginFlowTest.php', + [ + 'userIdentifier' => $userIdentifier, + 'isEntity' => $isEntity, + 'userClass' => $userClass, + 'testLogin' => $testLogin, + 'useLegacyContainerProperty' => $runner->getSymfonyVersion() <= 50200, + ] + ); + + // plaintext password: needed for entities, simplifies overall + $runner->modifyYamlFile('config/packages/security.yaml', function (array $config) { + // legacy check for 5.2 and lower "encoders" + if (isset($config['security']['password_hashers'])) { + $config['security']['password_hashers'] = [PasswordAuthenticatedUserInterface::class => 'plaintext']; + } else { + $config['security']['encoders'] = [UserInterface::class => 'plaintext']; + } + + return $config; + }); + + if ($isEntity) { + $runner->configureDatabase(); + } + $runner->runTests(); + } + + private function makeUser(MakerTestRunner $runner, string $userIdentifier, bool $isEntity = true, bool $checkPassword = true) + { + $runner->runConsole('make:user', [ + 'User', // class name + $isEntity ? 'y' : 'n', // entity + $userIdentifier, // identifier + $checkPassword ? 'y' : 'n', // password + ]); + + if (!$isEntity) { + $runner->copy( + 'make-auth/UserProvider-no-entity.php', + 'src/Security/UserProvider.php' + ); + } + } } diff --git a/tests/Maker/MakeCommandTest.php b/tests/Maker/MakeCommandTest.php index 99967e72f..1f49335b0 100644 --- a/tests/Maker/MakeCommandTest.php +++ b/tests/Maker/MakeCommandTest.php @@ -13,48 +13,73 @@ use Symfony\Bundle\MakerBundle\Maker\MakeCommand; use Symfony\Bundle\MakerBundle\Test\MakerTestCase; -use Symfony\Bundle\MakerBundle\Test\MakerTestDetails; +use Symfony\Bundle\MakerBundle\Test\MakerTestRunner; +use Symfony\Component\Yaml\Yaml; class MakeCommandTest extends MakerTestCase { + protected function getMakerClass(): string + { + return MakeCommand::class; + } + public function getTestDetails(): \Generator { - yield 'command' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeCommand::class), - [ - // command name - 'app:foo', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeCommand'), - ]; + yield 'it_makes_a_command_no_attributes' => [$this->createMakerTest() + ->addRequiredPackageVersion('symfony/console', '<5.3') + ->run(function (MakerTestRunner $runner) { + $runner->runMaker([ + // command name + 'app:foo', + ]); - yield 'command_in_custom_root_namespace' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeCommand::class), - [ - // command name - 'app:foo', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeCommandInCustomRootNamespace') - ->changeRootNamespace('Custom'), + $this->runCommandTest($runner, 'it_makes_a_command.php'); + }), ]; - yield 'command_with_attributes' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeCommand::class), - [ - // command name - 'app:foo', - ]) + yield 'it_makes_a_command_with_attributes' => [$this->createMakerTest() ->setRequiredPhpVersion(80000) ->addRequiredPackageVersion('symfony/console', '>=5.3') - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeCommand') - ->assert( - static function (string $output, string $directory) { - $commandFileContents = file_get_contents(sprintf('%s/src/Command/FooCommand.php', $directory)); - - self::assertStringContainsString('use Symfony\Component\Console\Attribute\AsCommand;', $commandFileContents); - self::assertStringContainsString('#[AsCommand(', $commandFileContents); - } - ), + ->run(function (MakerTestRunner $runner) { + $runner->runMaker([ + // command name + 'app:foo', + ]); + + $this->runCommandTest($runner, 'it_makes_a_command.php'); + + $commandFileContents = file_get_contents($runner->getPath('src/Command/FooCommand.php')); + + self::assertStringContainsString('use Symfony\Component\Console\Attribute\AsCommand;', $commandFileContents); + self::assertStringContainsString('#[AsCommand(', $commandFileContents); + }), ]; + + yield 'it_makes_a_command_in_custom_namespace' => [$this->createMakerTest() + ->changeRootNamespace('Custom') + ->run(function (MakerTestRunner $runner) { + $runner->writeFile( + 'config/packages/dev/maker.yaml', + Yaml::dump(['maker' => ['root_namespace' => 'Custom']]) + ); + + $runner->runMaker([ + // command name + 'app:foo', + ]); + + $this->runCommandTest($runner, 'it_makes_a_command_in_custom_namespace.php'); + }), + ]; + } + + private function runCommandTest(MakerTestRunner $runner, string $filename) + { + $runner->copy( + 'make-command/tests/'.$filename, + 'tests/GeneratedCommandTest.php' + ); + + $runner->runTests(); } } diff --git a/tests/Maker/MakeControllerTest.php b/tests/Maker/MakeControllerTest.php index 8cb573f7f..49cd40da4 100644 --- a/tests/Maker/MakeControllerTest.php +++ b/tests/Maker/MakeControllerTest.php @@ -13,55 +13,66 @@ use Symfony\Bundle\MakerBundle\Maker\MakeController; use Symfony\Bundle\MakerBundle\Test\MakerTestCase; -use Symfony\Bundle\MakerBundle\Test\MakerTestDetails; +use Symfony\Bundle\MakerBundle\Test\MakerTestRunner; class MakeControllerTest extends MakerTestCase { + protected function getMakerClass(): string + { + return MakeController::class; + } + public function getTestDetails() { - yield 'controller_basic' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeController::class), - [ - // controller class name - 'FooBar', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeController') - ->assert(function (string $output, string $directory) { - // make sure the template was not configured + yield 'it_generates_a_controller' => [$this->createMakerTest() + ->run(function (MakerTestRunner $runner) { + $output = $runner->runMaker([ + // controller class name + 'FooBar', + ]); + $this->assertContainsCount('created: ', $output, 1); + + $this->runControllerTest($runner, 'it_generates_a_controller.php'); }), ]; - yield 'controller_with_template_and_base' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeController::class), - [ - // controller class name - 'FooTwig', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeControllerTwig') - ->addExtraDependencies('twig'), + yield 'it_generates_a_controller_with_twig' => [$this->createMakerTest() + ->addExtraDependencies('twig') + ->run(function (MakerTestRunner $runner) { + $output = $runner->runMaker([ + // controller class name + 'FooTwig', + ]); + + $this->runControllerTest($runner, 'it_generates_a_controller_with_twig.php'); + }), ]; - yield 'controller_with_template_no_base' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeController::class), - [ - // controller class name - 'FooTwig', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeControllerTwig') + yield 'it_generates_a_controller_with_twig_no_base_template' => [$this->createMakerTest() ->addExtraDependencies('twig') - ->deleteFile('templates/base.html.twig'), + ->run(function (MakerTestRunner $runner) { + $runner->deleteFile('templates/base.html.twig'); + + $runner->runMaker([ + // controller class name + 'FooTwig', + ]); + + $this->runControllerTest($runner, 'it_generates_a_controller_with_twig.php'); + }), ]; - yield 'controller_without_template' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeController::class), - [ - // controller class name - 'FooNoTemplate', - ]) - ->setArgumentsString('--no-template') + yield 'it_generates_a_controller_with_without_template' => [$this->createMakerTest() ->addExtraDependencies('twig') - ->assert(function (string $output, string $directory) { + ->run(function (MakerTestRunner $runner) { + $runner->deleteFile('templates/base.html.twig'); + + $output = $runner->runMaker([ + // controller class name + 'FooNoTemplate', + ], '--no-template'); + // make sure the template was not configured $this->assertContainsCount('created: ', $output, 1); $this->assertStringContainsString('created: src/Controller/FooNoTemplateController.php', $output); @@ -69,42 +80,51 @@ public function getTestDetails() }), ]; - yield 'controller_sub_namespace' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeController::class), - [ - // controller class name - 'Admin\\FooBar', - ]) - ->assert(function (string $output, string $directory) { - $this->assertFileExists($directory.'/src/Controller/Admin/FooBarController.php'); + yield 'it_generates_a_controller_in_sub_namespace' => [$this->createMakerTest() + ->run(function (MakerTestRunner $runner) { + $output = $runner->runMaker([ + // controller class name + 'Admin\\FooBar', + ]); + $this->assertFileExists($runner->getPath('src/Controller/Admin/FooBarController.php')); $this->assertStringContainsString('created: src/Controller/Admin/FooBarController.php', $output); }), ]; - yield 'controller_sub_namespace_template' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeController::class), - [ - // controller class name - 'Admin\\FooBar', - ]) + yield 'it_generates_a_controller_in_sub_namespace_with_template' => [$this->createMakerTest() ->addExtraDependencies('twig') - ->assert(function (string $output, string $directory) { - $this->assertFileExists($directory.'/templates/admin/foo_bar/index.html.twig'); - }), - ]; + ->run(function (MakerTestRunner $runner) { + $output = $runner->runMaker([ + // controller class name + 'Admin\\FooBar', + ]); + + $this->assertFileExists($runner->getPath('templates/admin/foo_bar/index.html.twig')); + }), + ]; - yield 'controller_full_custom_namespace' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeController::class), - [ - // controller class name - '\App\Foo\Bar\CoolController', - ]) + yield 'it_generates_a_controller_with_full_custom_namespace' => [$this->createMakerTest() ->addExtraDependencies('twig') - ->assert(function (string $output, string $directory) { + ->run(function (MakerTestRunner $runner) { + $output = $runner->runMaker([ + // controller class name + '\App\Foo\Bar\CoolController', + ]); + $this->assertStringContainsString('created: src/Foo/Bar/CoolController.php', $output); $this->assertStringContainsString('created: templates/foo/bar/cool/index.html.twig', $output); }), ]; } + + private function runControllerTest(MakerTestRunner $runner, string $filename) + { + $runner->copy( + 'make-controller/tests/'.$filename, + 'tests/GeneratedControllerTest.php' + ); + + $runner->runTests(); + } } diff --git a/tests/Maker/MakeCrudTest.php b/tests/Maker/MakeCrudTest.php index c746f2044..06356d9f1 100644 --- a/tests/Maker/MakeCrudTest.php +++ b/tests/Maker/MakeCrudTest.php @@ -14,102 +14,146 @@ use Symfony\Bundle\MakerBundle\Maker\MakeCrud; use Symfony\Bundle\MakerBundle\Test\MakerTestCase; use Symfony\Bundle\MakerBundle\Test\MakerTestDetails; +use Symfony\Bundle\MakerBundle\Test\MakerTestRunner; +use Symfony\Component\Yaml\Yaml; class MakeCrudTest extends MakerTestCase { + protected function getMakerClass(): string + { + return MakeCrud::class; + } + + private function createMakeCrudTest(): MakerTestDetails + { + return $this->createMakerTest() + // workaround for segfault in PHP 7.1 CI :/ + ->setRequiredPhpVersion(70200); + } + public function getTestDetails() { - yield 'crud_basic' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeCrud::class), - [ - // entity class name - 'SweetFood', - '', // default controller - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeCrud') - // need for crud web tests - ->configureDatabase() - ->assert(function (string $output, string $directory) { + yield 'it_generates_basic_crud' => [$this->createMakeCrudTest() + ->run(function (MakerTestRunner $runner) { + $runner->copy( + 'make-crud/SweetFood.php', + 'src/Entity/SweetFood.php' + ); + + $output = $runner->runMaker([ + // entity class name + 'SweetFood', + '', // default controller + ]); + $this->assertStringContainsString('created: src/Controller/SweetFoodController.php', $output); $this->assertStringContainsString('created: src/Form/SweetFoodType.php', $output); - }) - // workaround for segfault in PHP 7.1 CI :/ - ->setRequiredPhpVersion(70200), + + $this->runCrudTest($runner, 'it_generates_basic_crud.php'); + }), ]; - yield 'crud_basic_custom_controller' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeCrud::class), - [ - // entity class name - 'SweetFood', - 'SweetFoodAdminController', // default controller - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeCrudCustomController') - // need for crud web tests - ->configureDatabase() - ->assert(function (string $output, string $directory) { + yield 'it_generates_crud_with_custom_controller' => [$this->createMakeCrudTest() + ->run(function (MakerTestRunner $runner) { + $runner->copy( + 'make-crud/SweetFood.php', + 'src/Entity/SweetFood.php' + ); + + $output = $runner->runMaker([ + // entity class name + 'SweetFood', + 'SweetFoodAdminController', // default controller + ]); + $this->assertStringContainsString('created: src/Controller/SweetFoodAdminController.php', $output); $this->assertStringContainsString('created: src/Form/SweetFoodType.php', $output); - }) - // workaround for segfault in PHP 7.1 CI :/ - ->setRequiredPhpVersion(70200), + + $this->runCrudTest($runner, 'it_generates_crud_with_custom_controller.php'); + }), ]; - yield 'crud_basic_in_custom_root_namespace' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeCrud::class), - [ - // entity class name - 'SweetFood', - '', // default controller - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeCrudInCustomRootNamespace') + yield 'it_generates_crud_with_custom_root_namespace' => [$this->createMakeCrudTest() ->changeRootNamespace('Custom') - // need for crud web tests - ->configureDatabase() - ->assert(function (string $output, string $directory) { + ->run(function (MakerTestRunner $runner) { + $runner->writeFile( + 'config/packages/dev/maker.yaml', + Yaml::dump(['maker' => ['root_namespace' => 'Custom']]) + ); + + $runner->copy( + 'make-crud/SweetFood-custom-namespace.php', + 'src/Entity/SweetFood.php' + ); + + $output = $runner->runMaker([ + // entity class name + 'SweetFood', + '', // default controller + ]); + $this->assertStringContainsString('created: src/Controller/SweetFoodController.php', $output); $this->assertStringContainsString('created: src/Form/SweetFoodType.php', $output); - }) - // workaround for segfault in PHP 7.1 CI :/ - ->setRequiredPhpVersion(70200), + + $this->runCrudTest($runner, 'it_generates_crud_with_custom_root_namespace.php'); + }), ]; - yield 'crud_repository' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeCrud::class), - [ - // entity class name - 'SweetFood', - '', // default controller - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeCrudRepository') - // need for crud web tests - ->configureDatabase() - ->assert(function (string $output, string $directory) { + yield 'it_generates_crud_using_custom_repository' => [$this->createMakeCrudTest() + ->run(function (MakerTestRunner $runner) { + $runner->copy( + 'make-crud/SweetFood.php', + 'src/Entity/SweetFood.php' + ); + $runner->copy( + 'make-crud/SweetFoodRepository.php', + 'src/Repository/SweetFoodRepository.php' + ); + + $output = $runner->runMaker([ + // entity class name + 'SweetFood', + '', // default controller + ]); + $this->assertStringContainsString('created: src/Controller/SweetFoodController.php', $output); $this->assertStringContainsString('created: src/Form/SweetFoodType.php', $output); - }) - // workaround for segfault in PHP 7.1 CI :/ - ->setRequiredPhpVersion(70200), + + $this->runCrudTest($runner, 'it_generates_basic_crud.php'); + }), ]; - yield 'crud_with_no_base' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeCrud::class), - [ - // entity class name - 'SweetFood', - '', // default controller - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeCrud') - // need for crud web tests - ->addExtraDependencies('symfony/css-selector') - ->configureDatabase() - ->deleteFile('templates/base.html.twig') - ->assert(function (string $output, string $directory) { + yield 'it_generates_crud_with_no_base_template' => [$this->createMakeCrudTest() + ->run(function (MakerTestRunner $runner) { + $runner->copy( + 'make-crud/SweetFood.php', + 'src/Entity/SweetFood.php' + ); + + $runner->deleteFile('templates/base.html.twig'); + + $output = $runner->runMaker([ + // entity class name + 'SweetFood', + '', // default controller + ]); + $this->assertStringContainsString('created: src/Controller/SweetFoodController.php', $output); $this->assertStringContainsString('created: src/Form/SweetFoodType.php', $output); - }) - // workaround for segfault in PHP 7.1 CI :/ - ->setRequiredPhpVersion(70200), + + $this->runCrudTest($runner, 'it_generates_basic_crud.php'); + }), ]; } + + private function runCrudTest(MakerTestRunner $runner, string $filename) + { + $runner->copy( + 'make-crud/tests/'.$filename, + 'tests/GeneratedCrudControllerTest.php' + ); + + $runner->configureDatabase(); + $runner->runTests(); + } } diff --git a/tests/Maker/MakeDockerDatabaseTest.php b/tests/Maker/MakeDockerDatabaseTest.php index 7ee35f925..494862738 100644 --- a/tests/Maker/MakeDockerDatabaseTest.php +++ b/tests/Maker/MakeDockerDatabaseTest.php @@ -13,120 +13,98 @@ use Symfony\Bundle\MakerBundle\Maker\MakeDockerDatabase; use Symfony\Bundle\MakerBundle\Test\MakerTestCase; -use Symfony\Bundle\MakerBundle\Test\MakerTestDetails; +use Symfony\Bundle\MakerBundle\Test\MakerTestRunner; use Symfony\Bundle\MakerBundle\Util\ComposeFileManipulator; -use Symfony\Component\Filesystem\Filesystem; /** * @author Jesse Rushlow */ final class MakeDockerDatabaseTest extends MakerTestCase { + protected function getMakerClass(): string + { + return MakeDockerDatabase::class; + } + public function getTestDetails(): \Generator { - yield 'uses_3_7_compose_file_version' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeDockerDatabase::class), - [ - '0', // Select MySQL as the database - '', // use the default "latest" service version - ] - ) - ->assert( - function (string $output, string $directory) { - $fs = new Filesystem(); + yield 'it_uses_3_7_compose_file_version_generates_mysql_database' => [$this->createMakerTest() + ->run(function (MakerTestRunner $runner) { + $runner->runMaker([ + '0', // Select MySQL as the database + '', // use the default "latest" service version + ]); - $composeFile = sprintf('%s/%s', $directory, 'docker-compose.yaml'); + $this->assertFileExists($runner->getPath('docker-compose.yaml')); - self::assertTrue($fs->exists($composeFile)); + $manipulator = $this->getComposeManipulator($runner); + $data = $manipulator->getComposeData(); - $manipulator = new ComposeFileManipulator(file_get_contents($composeFile)); + self::assertSame('3.7', $data['version']); - $data = $manipulator->getComposeData(); + self::assertTrue($manipulator->serviceExists('database')); - self::assertSame('3.7', $data['version']); - } - ), - ]; - yield 'creates_mysql_service' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeDockerDatabase::class), - [ - '0', // Select MySQL as the database - '', // use the default "latest" service version - ] - ) - ->assert( - function (string $output, string $directory) { - $this->assertStringContainsString('Success', $output); - - $composeFile = sprintf('%s/%s', $directory, 'docker-compose.yaml'); - $manipulator = new ComposeFileManipulator(file_get_contents($composeFile)); - - self::assertTrue($manipulator->serviceExists('database')); - - $data = $manipulator->getComposeData(); - $mysql = $data['services']['database']; - - self::assertSame('mysql:latest', $mysql['image']); - self::assertSame('password', $mysql['environment']['MYSQL_ROOT_PASSWORD']); - self::assertSame('main', $mysql['environment']['MYSQL_DATABASE']); - self::assertSame(['3306'], $mysql['ports']); - } - ), + $mysql = $data['services']['database']; + + self::assertSame('mysql:latest', $mysql['image']); + self::assertSame('password', $mysql['environment']['MYSQL_ROOT_PASSWORD']); + self::assertSame('main', $mysql['environment']['MYSQL_DATABASE']); + self::assertSame(['3306'], $mysql['ports']); + }), ]; - yield 'creates_mariadb_service' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeDockerDatabase::class), - [ - '1', // Select MariaDB as the database - '', // use the default "latest" service version - ] - ) - ->assert( - function (string $output, string $directory) { - $this->assertStringContainsString('Success', $output); - - $composeFile = sprintf('%s/%s', $directory, 'docker-compose.yaml'); - $manipulator = new ComposeFileManipulator(file_get_contents($composeFile)); - - self::assertTrue($manipulator->serviceExists('database')); - - $data = $manipulator->getComposeData(); - $mariadb = $data['services']['database']; - - self::assertSame('mariadb:latest', $mariadb['image']); - self::assertSame('password', $mariadb['environment']['MYSQL_ROOT_PASSWORD']); - self::assertSame('main', $mariadb['environment']['MYSQL_DATABASE']); - self::assertSame(['3306'], $mariadb['ports']); - } - ), + yield 'it_creates_mariadb' => [$this->createMakerTest() + ->run(function (MakerTestRunner $runner) { + $output = $runner->runMaker([ + '1', // Select MariaDB as the database + '', // use the default "latest" service version + ]); + + $this->assertStringContainsString('Success', $output); + + $manipulator = $this->getComposeManipulator($runner); + + self::assertTrue($manipulator->serviceExists('database')); + + $data = $manipulator->getComposeData(); + $mariadb = $data['services']['database']; + + self::assertSame('mariadb:latest', $mariadb['image']); + self::assertSame('password', $mariadb['environment']['MYSQL_ROOT_PASSWORD']); + self::assertSame('main', $mariadb['environment']['MYSQL_DATABASE']); + self::assertSame(['3306'], $mariadb['ports']); + }), ]; - yield 'create_postgres_service' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeDockerDatabase::class), - [ - '2', // Select Postgres as the database - '', // use the default "alpine" service version - ] - ) - ->assert( - function (string $output, string $directory) { - $this->assertStringContainsString('Success', $output); - - $composeFile = sprintf('%s/%s', $directory, 'docker-compose.yaml'); - $manipulator = new ComposeFileManipulator(file_get_contents($composeFile)); - - self::assertTrue($manipulator->serviceExists('database')); - - $data = $manipulator->getComposeData(); - $postgres = $data['services']['database']; - - self::assertSame('postgres:alpine', $postgres['image']); - self::assertSame('main', $postgres['environment']['POSTGRES_USER']); - self::assertSame('main', $postgres['environment']['POSTGRES_PASSWORD']); - self::assertSame('main', $postgres['environment']['POSTGRES_DB']); - self::assertSame(['5432'], $postgres['ports']); - } - ), + yield 'it_creates_postgresql' => [$this->createMakerTest() + ->run(function (MakerTestRunner $runner) { + $output = $runner->runMaker([ + '2', // Select Postgres as the database + '', // use the default "alpine" service version + ]); + + $this->assertStringContainsString('Success', $output); + + $manipulator = $this->getComposeManipulator($runner); + + self::assertTrue($manipulator->serviceExists('database')); + + $data = $manipulator->getComposeData(); + $postgres = $data['services']['database']; + + self::assertSame('postgres:alpine', $postgres['image']); + self::assertSame('main', $postgres['environment']['POSTGRES_USER']); + self::assertSame('main', $postgres['environment']['POSTGRES_PASSWORD']); + self::assertSame('main', $postgres['environment']['POSTGRES_DB']); + self::assertSame(['5432'], $postgres['ports']); + }), ]; } + + private function getComposeManipulator(MakerTestRunner $runner): ComposeFileManipulator + { + $composeFile = $runner->getPath('docker-compose.yaml'); + + return new ComposeFileManipulator(file_get_contents($composeFile)); + } } diff --git a/tests/Maker/MakeEntityLegacyTest.php b/tests/Maker/MakeEntityLegacyTest.php deleted file mode 100644 index 79d2a1e84..000000000 --- a/tests/Maker/MakeEntityLegacyTest.php +++ /dev/null @@ -1,558 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\MakerBundle\Tests\Maker; - -use Symfony\Bundle\MakerBundle\Maker\MakeEntity; -use Symfony\Bundle\MakerBundle\Test\MakerTestCase; -use Symfony\Bundle\MakerBundle\Test\MakerTestDetails; -use Symfony\Component\Finder\Finder; - -class MakeEntityLegacyTest extends MakerTestCase -{ - public function getTestDetails() - { - yield 'entity_new' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'User', - // add not additional fields - '', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/legacy/MakeEntity/MakeEntity') - ->configureDatabase() - ->updateSchemaAfterCommand(), - ]; - - yield 'entity_new_api_resource' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'User', - // Mark the entity as an API Platform resource - 'y', - // add not additional fields - '', - ]) - ->addExtraDependencies('api') - ->setFixtureFilesPath(__DIR__.'/../fixtures/legacy/MakeEntity/MakeEntity') - ->configureDatabase() - ->updateSchemaAfterCommand() - ->assert(function (string $output, string $directory) { - $this->assertFileExists($directory.'/src/Entity/User.php'); - - $content = file_get_contents($directory.'/src/Entity/User.php'); - $this->assertStringContainsString('use ApiPlatform\Core\Annotation\ApiResource;', $content); - $this->assertStringContainsString(\PHP_VERSION_ID >= 80000 ? '#[ApiResource]' : '@ApiResource', $content); - }), - ]; - - yield 'entity_with_fields' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'User', - // add not additional fields - 'name', - 'string', - '255', // length - // nullable - 'y', - 'createdAt', - // use default datetime - '', - // nullable - 'y', - // finish adding fields - '', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/legacy/MakeEntity/MakeEntity') - ->configureDatabase() - ->updateSchemaAfterCommand(), - ]; - - yield 'entity_updating_main' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'User', - // add additional fields - 'lastName', - 'string', - '', // length (default 255) - // nullable - 'y', - // finish adding fields - '', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/legacy/MakeEntity/MakeEntityUpdate') - ->configureDatabase() - ->updateSchemaAfterCommand(), - ]; - - yield 'entity_many_to_one_simple_with_inverse' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'UserAvatarPhoto', - // field name - 'user', - // add a relationship field - 'relation', - // the target entity - 'User', - // relation type - 'ManyToOne', - // nullable - 'n', - // do you want to generate an inverse relation? (default to yes) - '', - // field name on opposite side - use default 'userAvatarPhotos' - '', - // orphanRemoval (default to no) - '', - // finish adding fields - '', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/legacy/MakeEntity/MakeEntityManyToOne') - ->configureDatabase() - ->updateSchemaAfterCommand(), - ]; - - yield 'entity_many_to_one_simple_no_inverse' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'UserAvatarPhoto', - // field name - 'user', - // add a relationship field - 'relation', - // the target entity - 'User', - // relation type - 'ManyToOne', - // nullable - 'n', - // do you want to generate an inverse relation? (default to yes) - 'n', - // finish adding fields - '', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/legacy/MakeEntity/MakeEntityManyToOneNoInverse') - ->configureDatabase() - ->updateSchemaAfterCommand(), - ]; - - yield 'entity_many_to_one_self_referencing' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'User', - // field name - 'guardian', - // add a relationship field - 'relation', - // the target entity - 'User', - // relation type - 'ManyToOne', - // nullable - 'y', - // do you want to generate an inverse relation? (default to yes) - '', - // field name on opposite side - 'dependants', - // orphanRemoval (default to no) - '', - // finish adding fields - '', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/legacy/MakeEntity/MakeEntitySelfReferencing') - ->configureDatabase() - ->updateSchemaAfterCommand(), - ]; - - yield 'entity_exists_in_root' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'Directory', - // field name - 'parentDirectory', - // add a relationship field - 'relation', - // the target entity - 'Directory', - // relation type - 'ManyToOne', - // nullable - 'y', - // do you want to generate an inverse relation? (default to yes) - '', - // field name on opposite side - 'childDirectories', - // orphanRemoval (default to no) - '', - // finish adding fields - '', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/legacy/MakeEntity/MakeEntityExistsInRoot') - ->configureDatabase() - ->updateSchemaAfterCommand(), - ]; - - yield 'entity_one_to_many_simple' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'User', - // field name - 'photos', - // add a relationship field - 'relation', - // the target entity - 'UserAvatarPhoto', - // relation type - 'OneToMany', - // field name on opposite side - use default 'user' - '', - // nullable - 'n', - // orphanRemoval - 'y', - // finish adding fields - '', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/legacy/MakeEntity/MakeEntityOneToMany') - ->configureDatabase() - ->updateSchemaAfterCommand(), - ]; - - yield 'entity_many_to_many_simple' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'Course', - // field name - 'students', - // add a relationship field - 'relation', - // the target entity - 'User', - // relation type - 'ManyToMany', - // inverse side? - 'y', - // field name on opposite side - use default 'courses' - '', - // finish adding fields - '', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/legacy/MakeEntity/MakeEntityManyToMany') - ->configureDatabase() - ->updateSchemaAfterCommand(), - ]; - - yield 'entity_many_to_many_simple_in_custom_root_namespace' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'Course', - // field name - 'students', - // add a relationship field - 'relation', - // the target entity - 'User', - // relation type - 'ManyToMany', - // inverse side? - 'y', - // field name on opposite side - use default 'courses' - '', - // finish adding fields - '', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/legacy/MakeEntity/MakeEntityManyToManyInCustomNamespace') - ->changeRootNamespace('Custom') - ->configureDatabase() - ->updateSchemaAfterCommand(), - ]; - - yield 'entity_one_to_one_simple' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'UserProfile', - // field name - 'user', - // add a relationship field - 'relation', - // the target entity - 'User', - // relation type - 'OneToOne', - // nullable - 'n', - // inverse side? - 'y', - // field name on opposite side - use default 'userProfile' - '', - // finish adding fields - '', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/legacy/MakeEntity/MakeEntityOneToOne') - ->configureDatabase() - ->updateSchemaAfterCommand(), - ]; - - yield 'entity_many_to_one_vendor_target' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'User', - // field name - 'userGroup', - // add a relationship field - 'ManyToOne', - // the target entity - 'Some\\Vendor\\Group', - // nullable - '', - /* - * normally, we ask for the field on the *other* side, but we - * do not here, since the other side won't be mapped. - */ - // finish adding fields - '', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/legacy/MakeEntity/MakeEntityRelationVendorTarget') - ->configureDatabase() - ->addReplacement( - 'composer.json', - '"App\\\Tests\\\": "tests/",', - '"App\\\Tests\\\": "tests/",'."\n".' "Some\\\Vendor\\\": "vendor/some-vendor/src",' - ) - ->assert(function (string $output, string $directory) { - $this->assertStringContainsString('updated: src/Entity/User.php', $output); - $this->assertStringNotContainsString('updated: vendor/', $output); - - // sanity checks on the generated code - $finder = new Finder(); - $finder->in($directory.'/src/Entity')->files()->name('*.php'); - $this->assertCount(1, $finder); - - $this->assertStringNotContainsString('inversedBy', file_get_contents($directory.'/src/Entity/User.php')); - }), - ]; - - yield 'entity_many_to_many_vendor_target' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'User', - // field name - 'userGroups', - // add a relationship field - 'ManyToMany', - // the target entity - 'Some\Vendor\Group', - /* - * normally, we ask for the field on the *other* side, but we - * do not here, since the other side won't be mapped. - */ - // finish adding fields - '', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/legacy/MakeEntity/MakeEntityRelationVendorTarget') - ->configureDatabase() - ->addReplacement( - 'composer.json', - '"App\\\Tests\\\": "tests/",', - '"App\\\Tests\\\": "tests/",'."\n".' "Some\\\Vendor\\\": "vendor/some-vendor/src",' - ) - ->assert(function (string $output, string $directory) { - $this->assertStringNotContainsString('updated: vendor/', $output); - - $this->assertStringNotContainsString('inversedBy', file_get_contents($directory.'/src/Entity/User.php')); - }), - ]; - - yield 'entity_one_to_one_vendor_target' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'User', - // field name - 'userGroup', - // add a relationship field - 'OneToOne', - // the target entity - 'Some\Vendor\Group', - // nullable, - '', - /* - * normally, we ask for the field on the *other* side, but we - * do not here, since the other side won't be mapped. - */ - // finish adding fields - '', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/legacy/MakeEntity/MakeEntityRelationVendorTarget') - ->configureDatabase() - ->addReplacement( - 'composer.json', - '"App\\\Tests\\\": "tests/",', - '"App\\\Tests\\\": "tests/",'."\n".' "Some\\\Vendor\\\": "vendor/some-vendor/src",' - ) - ->assert(function (string $output, string $directory) { - $this->assertStringNotContainsString('updated: vendor/', $output); - - $this->assertStringNotContainsString('inversedBy', file_get_contents($directory.'/src/Entity/User.php')); - }), - ]; - - yield 'entity_regenerate' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // namespace: use default App\Entity - '', - ]) - ->setArgumentsString('--regenerate') - ->setFixtureFilesPath(__DIR__.'/../fixtures/legacy/MakeEntity/MakeEntityRegenerate') - ->configureDatabase(true), - ]; - - yield 'entity_regenerate_embeddable_object' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // namespace: use default App\Entity - '', - ]) - ->setArgumentsString('--regenerate') - ->setFixtureFilesPath(__DIR__.'/../fixtures/legacy/MakeEntity/MakeEntityRegenerateEmbeddableObject') - ->configureDatabase(), - ]; - - yield 'entity_regenerate_embeddable' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // namespace: use default App\Entity - '', - ]) - ->setArgumentsString('--regenerate --overwrite') - ->setFixtureFilesPath(__DIR__.'/../fixtures/legacy/MakeEntity/MakeEntityRegenerateEmbedable') - ->configureDatabase(), - ]; - - yield 'entity_regenerate_overwrite' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // namespace: use default App\Entity - '', - ]) - ->setArgumentsString('--regenerate --overwrite') - ->setFixtureFilesPath(__DIR__.'/../fixtures/legacy/MakeEntity/MakeEntityRegenerateOverwrite') - ->configureDatabase(false), - ]; - - yield 'entity_updating_overwrite' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'User', - // field name - 'firstName', - 'string', - '', // length (default 255) - // nullable - '', - // finish adding fields - '', - ]) - ->setArgumentsString('--overwrite') - ->setFixtureFilesPath(__DIR__.'/../fixtures/legacy/MakeEntity/MakeEntityOverwrite'), - ]; - - // see #192 - yield 'entity_into_sub_namespace_matching_entity' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'Product\\Category', - // add not additional fields - '', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/legacy/MakeEntity/MakeEntitySubNamespaceMatchingEntity') - ->configureDatabase() - ->updateSchemaAfterCommand(), - ]; - - $broadCastTest = MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'User', - // Mark the entity as broadcasted - 'y', - // add not additional fields - '', - ]) - ->setRequiredPhpVersion(70200) - ->addExtraDependencies('symfony/ux-turbo-mercure') - ->configureDatabase() - ->addReplacement( - '.env', - 'https://example.com/.well-known/mercure', - 'http://127.0.0.1:1337/.well-known/mercure' - ) - ->updateSchemaAfterCommand() - ->assert(function (string $output, string $directory) { - $this->assertFileExists($directory.'/src/Entity/User.php'); - - $content = file_get_contents($directory.'/src/Entity/User.php'); - $this->assertStringContainsString('use Symfony\UX\Turbo\Attribute\Broadcast;', $content); - $this->assertStringContainsString(\PHP_VERSION_ID >= 80000 ? '#[Broadcast]' : '@Broadcast', $content); - }) - ; - // use the fixtures - which contains a test for Mercure - unless specified to skip those - $skipMercureTest = $_SERVER['MAKER_SKIP_MERCURE_TEST'] ?? false; - if (!$skipMercureTest) { - $broadCastTest->setFixtureFilesPath(__DIR__.'/../fixtures/legacy/MakeEntity/MakeEntity'); - } - yield 'entity_new_broadcast' => [$broadCastTest]; - - yield 'entity_new_with_api_and_broadcast_dependencies' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'User', - // Mark the entity as not an API Platform resource - 'n', - // Mark the entity as not broadcasted - 'n', - // add not additional fields - '', - ]) - ->setRequiredPhpVersion(70200) - ->addExtraDependencies('api') - ->addExtraDependencies('symfony/ux-turbo-mercure') - ->setFixtureFilesPath(__DIR__.'/../fixtures/legacy/MakeEntity/MakeEntity') - ->configureDatabase() - ->updateSchemaAfterCommand() - ->assert(function (string $output, string $directory) { - $this->assertFileExists($directory.'/src/Entity/User.php'); - }), - ]; - } -} diff --git a/tests/Maker/MakeEntityTest.php b/tests/Maker/MakeEntityTest.php index 13900a2de..bfe9f52d0 100644 --- a/tests/Maker/MakeEntityTest.php +++ b/tests/Maker/MakeEntityTest.php @@ -11,659 +11,699 @@ namespace Symfony\Bundle\MakerBundle\Tests\Maker; +use Doctrine\ORM\Mapping\Driver\AttributeReader; use Symfony\Bundle\MakerBundle\Maker\MakeEntity; use Symfony\Bundle\MakerBundle\Test\MakerTestCase; use Symfony\Bundle\MakerBundle\Test\MakerTestDetails; +use Symfony\Bundle\MakerBundle\Test\MakerTestRunner; use Symfony\Component\Finder\Finder; +use Symfony\Component\Yaml\Yaml; class MakeEntityTest extends MakerTestCase { - public function getTestDetails() + protected function getMakerClass(): string { - yield 'entity_new' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'User', - // add not additional fields - '', - ]) - ->setRequiredPhpVersion(80000) - ->useDoctrineAttributeMapping() - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntity') - ->configureDatabase() - ->updateSchemaAfterCommand(), - ]; + return MakeEntity::class; + } - yield 'entity_new_api_resource' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'User', - // Mark the entity as an API Platform resource - 'y', - // add not additional fields - '', - ]) - ->setRequiredPhpVersion(80000) - ->useDoctrineAttributeMapping() - ->addExtraDependencies('api') - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntity') - ->configureDatabase() - ->updateSchemaAfterCommand() - ->assert(function (string $output, string $directory) { - $this->assertFileExists($directory.'/src/Entity/User.php'); + private function createMakeEntityTest(bool $withDatabase = true): MakerTestDetails + { + return $this->createMakerTest() + ->preRun(function (MakerTestRunner $runner) use ($withDatabase) { + if ($this->useAttributes($runner)) { + // use attributes + $runner->replaceInFile( + 'config/packages/doctrine.yaml', + 'type: annotation', + 'type: attribute' + ); + } + + if ($withDatabase) { + $runner->configureDatabase(); + } + }); + } - $content = file_get_contents($directory.'/src/Entity/User.php'); - $this->assertStringContainsString('use ApiPlatform\Core\Annotation\ApiResource;', $content); - $this->assertStringContainsString(\PHP_VERSION_ID >= 80000 ? '#[ApiResource]' : '@ApiResource', $content); + private function createMakeEntityTestForMercure(): MakerTestDetails + { + return $this->createMakeEntityTest() + ->setRequiredPhpVersion(70250) + // technically we need twig-bundle >= 5.2, but this is a good proxy + // using twig-bundle doesn't work because it's only installed via ux-turbo-mercure + ->addRequiredPackageVersion('symfony/framework-bundle', '>=5.2.0') + ->preRun(function (MakerTestRunner $runner) { + // installed manually later so that the compatibility check can run fist + $runner->runProcess('composer require symfony/ux-turbo-mercure'); + }); + } + + public function getTestDetails() + { + yield 'it_creates_a_new_class_basic' => [$this->createMakeEntityTest() + ->run(function (MakerTestRunner $runner) { + $runner->runMaker([ + // entity class name + 'User', + // add not additional fields + '', + ]); + + $this->runEntityTest($runner); }), ]; - yield 'entity_with_fields' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'User', - // add not additional fields - 'name', - 'string', - '255', // length - // nullable - 'y', - 'createdAt', - // use default datetime - '', - // nullable - 'y', - // finish adding fields - '', - ]) - ->setRequiredPhpVersion(80000) - ->useDoctrineAttributeMapping() - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntity') - ->configureDatabase() - ->updateSchemaAfterCommand(), - ]; + yield 'it_creates_a_new_class_and_api_resource' => [$this->createMakeEntityTest() + ->addExtraDependencies('api') + ->run(function (MakerTestRunner $runner) { + $runner->runMaker([ + // entity class name + 'User', + // Mark the entity as an API Platform resource + 'y', + // add not additional fields + '', + ]); + + $this->assertFileExists($runner->getPath('src/Entity/User.php')); + + $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); - yield 'entity_updating_main' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'User', - // add additional fields - 'lastName', - 'string', - '', // length (default 255) - // nullable - 'y', - // finish adding fields - '', - ]) - ->setRequiredPhpVersion(80000) - ->useDoctrineAttributeMapping() - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntityUpdate') - ->configureDatabase() - ->updateSchemaAfterCommand(), + $this->runEntityTest($runner); + }), ]; - yield 'entity_many_to_one_simple_with_inverse' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'UserAvatarPhoto', - // field name - 'user', - // add a relationship field - 'relation', - // the target entity - 'User', - // relation type - 'ManyToOne', - // nullable - 'n', - // do you want to generate an inverse relation? (default to yes) - '', - // field name on opposite side - use default 'userAvatarPhotos' - '', - // orphanRemoval (default to no) - '', - // finish adding fields - '', - ]) - ->setRequiredPhpVersion(80000) - ->useDoctrineAttributeMapping() - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntityManyToOne') - ->configureDatabase() - ->updateSchemaAfterCommand(), + yield 'it_creates_a_new_class_with_fields' => [$this->createMakeEntityTest() + ->run(function (MakerTestRunner $runner) { + $runner->runMaker([ + // entity class name + 'User', + // add not additional fields + 'name', + 'string', + '255', // length + // nullable + 'y', + 'createdAt', + // use default datetime + '', + // nullable + 'y', + // finish adding fields + '', + ]); + + $this->runEntityTest($runner); + }), ]; - yield 'entity_many_to_one_simple_no_inverse' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'UserAvatarPhoto', - // field name - 'user', - // add a relationship field - 'relation', - // the target entity - 'User', - // relation type - 'ManyToOne', - // nullable - 'n', - // do you want to generate an inverse relation? (default to yes) - 'n', - // finish adding fields - '', - ]) - ->setRequiredPhpVersion(80000) - ->useDoctrineAttributeMapping() - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntityManyToOneNoInverse') - ->configureDatabase() - ->updateSchemaAfterCommand(), + yield 'it_updates_existing_entity' => [$this->createMakeEntityTest() + ->run(function (MakerTestRunner $runner) { + $this->copyEntity($runner, 'User-basic.php'); + + $runner->runMaker([ + // entity class name + 'User', + // add additional fields + 'lastName', + 'string', + '', // length (default 255) + // nullable + 'y', + // finish adding fields + '', + ]); + + $this->runEntityTest($runner, [ + // existing field + 'firstName' => 'Mr. Chocolate', + // new field + 'lastName' => 'Cake', + ]); + }), ]; - yield 'entity_many_to_one_self_referencing' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'User', - // field name - 'guardian', - // add a relationship field - 'relation', - // the target entity - 'User', - // relation type - 'ManyToOne', - // nullable - 'y', - // do you want to generate an inverse relation? (default to yes) - '', - // field name on opposite side - 'dependants', - // orphanRemoval (default to no) - '', - // finish adding fields - '', - ]) - ->setRequiredPhpVersion(80000) - ->useDoctrineAttributeMapping() - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntitySelfReferencing') - ->configureDatabase() - ->updateSchemaAfterCommand(), + yield 'it_updates_entity_many_to_one_no_inverse' => [$this->createMakeEntityTest() + ->run(function (MakerTestRunner $runner) { + $this->copyEntity($runner, 'User-basic.php'); + + $runner->runMaker([ + // entity class name + 'UserAvatarPhoto', + // field name + 'user', + // add a relationship field + 'relation', + // the target entity + 'User', + // relation type + 'ManyToOne', + // nullable + 'n', + // do you want to generate an inverse relation? (default to yes) + 'n', + // finish adding fields + '', + ]); + + $this->runCustomTest($runner, 'it_updates_entity_many_to_one_no_inverse.php'); + }), ]; - yield 'entity_exists_in_root' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'Directory', - // field name - 'parentDirectory', - // add a relationship field - 'relation', - // the target entity - 'Directory', - // relation type - 'ManyToOne', - // nullable - 'y', - // do you want to generate an inverse relation? (default to yes) - '', - // field name on opposite side - 'childDirectories', - // orphanRemoval (default to no) - '', - // finish adding fields - '', - ]) - ->setRequiredPhpVersion(80000) - ->useDoctrineAttributeMapping() - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntityExistsInRoot') - ->configureDatabase() - ->updateSchemaAfterCommand(), + yield 'it_adds_many_to_one_self_referencing' => [$this->createMakeEntityTest() + ->run(function (MakerTestRunner $runner) { + $this->copyEntity($runner, 'User-basic.php'); + + $runner->runMaker([ + // entity class name + 'User', + // field name + 'guardian', + // add a relationship field + 'relation', + // the target entity + 'User', + // relation type + 'ManyToOne', + // nullable + 'y', + // do you want to generate an inverse relation? (default to yes) + '', + // field name on opposite side + 'dependants', + // orphanRemoval (default to no) + '', + // finish adding fields + '', + ]); + + $this->runCustomTest($runner, 'it_adds_many_to_one_self_referencing.php'); + }), ]; - yield 'entity_one_to_many_simple' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'User', - // field name - 'photos', - // add a relationship field - 'relation', - // the target entity - 'UserAvatarPhoto', - // relation type - 'OneToMany', - // field name on opposite side - use default 'user' - '', - // nullable - 'n', - // orphanRemoval - 'y', - // finish adding fields - '', - ]) - ->setRequiredPhpVersion(80000) - ->useDoctrineAttributeMapping() - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntityOneToMany') - ->configureDatabase() - ->updateSchemaAfterCommand(), + yield 'it_adds_one_to_many_simple' => [$this->createMakeEntityTest() + ->run(function (MakerTestRunner $runner) { + $this->copyEntity($runner, 'UserAvatarPhoto-basic.php'); + + $runner->runMaker([ + // entity class name + 'User', + // field name + 'photos', + // add a relationship field + 'relation', + // the target entity + 'UserAvatarPhoto', + // relation type + 'OneToMany', + // field name on opposite side - use default 'user' + '', + // nullable + 'n', + // orphanRemoval + 'y', + // finish adding fields + '', + ]); + + $this->runCustomTest($runner, 'it_adds_one_to_many_simple.php'); + }), ]; - yield 'entity_many_to_many_simple' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'Course', - // field name - 'students', - // add a relationship field - 'relation', - // the target entity - 'User', - // relation type - 'ManyToMany', - // inverse side? - 'y', - // field name on opposite side - use default 'courses' - '', - // finish adding fields - '', - ]) - ->setRequiredPhpVersion(80000) - ->useDoctrineAttributeMapping() - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntityManyToMany') - ->configureDatabase() - ->updateSchemaAfterCommand(), + yield 'it_adds_many_to_many_simple' => [$this->createMakeEntityTest() + ->run(function (MakerTestRunner $runner) { + $this->copyEntity($runner, 'User-basic.php'); + + $runner->runMaker([ + // entity class name + 'Course', + // field name + 'students', + // add a relationship field + 'relation', + // the target entity + 'User', + // relation type + 'ManyToMany', + // inverse side? + 'y', + // field name on opposite side - use default 'courses' + '', + // finish adding fields + '', + ]); + + $this->runCustomTest($runner, 'it_adds_many_to_many_simple.php'); + }), ]; - yield 'entity_many_to_many_simple_in_custom_root_namespace' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'Course', - // field name - 'students', - // add a relationship field - 'relation', - // the target entity - 'User', - // relation type - 'ManyToMany', - // inverse side? - 'y', - // field name on opposite side - use default 'courses' - '', - // finish adding fields - '', - ]) - ->setRequiredPhpVersion(80000) - ->useDoctrineAttributeMapping() - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntityManyToManyInCustomNamespace') + yield 'it_adds_many_to_many_with_custom_root_namespace' => [$this->createMakeEntityTest() ->changeRootNamespace('Custom') - ->configureDatabase() - ->updateSchemaAfterCommand(), + ->run(function (MakerTestRunner $runner) { + $this->copyEntity($runner, 'User-custom-namespace.php'); + + $runner->writeFile( + 'config/packages/dev/maker.yaml', + Yaml::dump(['maker' => ['root_namespace' => 'Custom']]) + ); + + $runner->runMaker([ + // entity class name + 'Course', + // field name + 'students', + // add a relationship field + 'relation', + // the target entity + 'User', + // relation type + 'ManyToMany', + // inverse side? + 'y', + // field name on opposite side - use default 'courses' + '', + // finish adding fields + '', + ]); + + $this->runCustomTest($runner, 'it_adds_many_to_many_with_custom_root_namespace.php'); + }), ]; - yield 'entity_one_to_one_simple' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'UserProfile', - // field name - 'user', - // add a relationship field - 'relation', - // the target entity - 'User', - // relation type - 'OneToOne', - // nullable - 'n', - // inverse side? - 'y', - // field name on opposite side - use default 'userProfile' - '', - // finish adding fields - '', - ]) - ->setRequiredPhpVersion(80000) - ->useDoctrineAttributeMapping() - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntityOneToOne') - ->configureDatabase() - ->updateSchemaAfterCommand(), + yield 'it_adds_one_to_one_simple' => [$this->createMakeEntityTest() + ->run(function (MakerTestRunner $runner) { + $this->copyEntity($runner, 'User-basic.php'); + + $runner->runMaker([ + // entity class name + 'UserProfile', + // field name + 'user', + // add a relationship field + 'relation', + // the target entity + 'User', + // relation type + 'OneToOne', + // nullable + 'n', + // inverse side? + 'y', + // field name on opposite side - use default 'userProfile' + '', + // finish adding fields + '', + ]); + + $this->runCustomTest($runner, 'it_adds_one_to_one_simple.php'); + }), ]; - yield 'entity_many_to_one_vendor_target' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'User', - // field name - 'userGroup', - // add a relationship field - 'ManyToOne', - // the target entity - 'Some\\Vendor\\Group', - // nullable - '', - /* - * normally, we ask for the field on the *other* side, but we - * do not here, since the other side won't be mapped. - */ - // finish adding fields - '', - ]) - ->setRequiredPhpVersion(80000) - ->useDoctrineAttributeMapping() - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntityRelationVendorTarget') - ->configureDatabase() - ->addReplacement( - 'composer.json', - '"App\\\Tests\\\": "tests/",', - '"App\\\Tests\\\": "tests/",'."\n".' "Some\\\Vendor\\\": "vendor/some-vendor/src",' - ) - ->assert(function (string $output, string $directory) { + yield 'it_adds_many_to_one_to_vendor_target' => [$this->createMakeEntityTest() + ->run(function (MakerTestRunner $runner) { + $this->copyEntity($runner, 'User-basic.php'); + $this->setupGroupEntityInVendor($runner); + + $output = $runner->runMaker([ + // entity class name + 'User', + // field name + 'userGroup', + // add a relationship field + 'ManyToOne', + // the target entity + 'Some\\Vendor\\Group', + // nullable + '', + /* + * normally, we ask for the field on the *other* side, but we + * do not here, since the other side won't be mapped. + */ + // finish adding fields + '', + ]); + $this->assertStringContainsString('updated: src/Entity/User.php', $output); $this->assertStringNotContainsString('updated: vendor/', $output); // sanity checks on the generated code $finder = new Finder(); - $finder->in($directory.'/src/Entity')->files()->name('*.php'); + $finder->in($runner->getPath('src/Entity'))->files()->name('*.php'); $this->assertCount(1, $finder); - $this->assertStringNotContainsString('inversedBy', file_get_contents($directory.'/src/Entity/User.php')); + $this->assertStringNotContainsString('inversedBy', file_get_contents($runner->getPath('src/Entity/User.php'))); }), ]; - yield 'entity_many_to_many_vendor_target' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'User', - // field name - 'userGroups', - // add a relationship field - 'ManyToMany', - // the target entity - 'Some\Vendor\Group', - /* - * normally, we ask for the field on the *other* side, but we - * do not here, since the other side won't be mapped. - */ - // finish adding fields - '', - ]) - ->setRequiredPhpVersion(80000) - ->useDoctrineAttributeMapping() - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntityRelationVendorTarget') - ->configureDatabase() - ->addReplacement( - 'composer.json', - '"App\\\Tests\\\": "tests/",', - '"App\\\Tests\\\": "tests/",'."\n".' "Some\\\Vendor\\\": "vendor/some-vendor/src",' - ) - ->assert(function (string $output, string $directory) { + yield 'it_adds_many_to_many_to_vendor_target' => [$this->createMakeEntityTest() + ->run(function (MakerTestRunner $runner) { + $this->copyEntity($runner, 'User-basic.php'); + $this->setupGroupEntityInVendor($runner); + + $output = $runner->runMaker([ + // entity class name + 'User', + // field name + 'userGroups', + // add a relationship field + 'ManyToMany', + // the target entity + 'Some\Vendor\Group', + /* + * normally, we ask for the field on the *other* side, but we + * do not here, since the other side won't be mapped. + */ + // finish adding fields + '', + ]); + $this->assertStringNotContainsString('updated: vendor/', $output); - $this->assertStringNotContainsString('inversedBy', file_get_contents($directory.'/src/Entity/User.php')); + $this->assertStringNotContainsString('inversedBy', file_get_contents($runner->getPath('src/Entity/User.php'))); }), ]; - yield 'entity_one_to_one_vendor_target' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'User', - // field name - 'userGroup', - // add a relationship field - 'OneToOne', - // the target entity - 'Some\Vendor\Group', - // nullable, - '', - /* - * normally, we ask for the field on the *other* side, but we - * do not here, since the other side won't be mapped. - */ - // finish adding fields - '', - ]) - ->setRequiredPhpVersion(80000) - ->useDoctrineAttributeMapping() - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntityRelationVendorTarget') - ->configureDatabase() - ->addReplacement( - 'composer.json', - '"App\\\Tests\\\": "tests/",', - '"App\\\Tests\\\": "tests/",'."\n".' "Some\\\Vendor\\\": "vendor/some-vendor/src",' - ) - ->assert(function (string $output, string $directory) { + yield 'it_adds_one_to_one_to_vendor_target' => [$this->createMakeEntityTest() + ->run(function (MakerTestRunner $runner) { + $this->copyEntity($runner, 'User-basic.php'); + $this->setupGroupEntityInVendor($runner); + + $output = $runner->runMaker([ + // entity class name + 'User', + // field name + 'userGroup', + // add a relationship field + 'OneToOne', + // the target entity + 'Some\Vendor\Group', + // nullable, + '', + /* + * normally, we ask for the field on the *other* side, but we + * do not here, since the other side won't be mapped. + */ + // finish adding fields + '', + ]); + $this->assertStringNotContainsString('updated: vendor/', $output); - $this->assertStringNotContainsString('inversedBy', file_get_contents($directory.'/src/Entity/User.php')); + $this->assertStringNotContainsString('inversedBy', file_get_contents($runner->getPath('src/Entity/User.php'))); }), ]; - yield 'entity_regenerate' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // namespace: use default App\Entity - '', - ]) - ->setRequiredPhpVersion(80000) - ->useDoctrineAttributeMapping() - ->setArgumentsString('--regenerate') - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntityRegenerate') - ->configureDatabase(true), + yield 'it_regenerates_entities' => [$this->createMakeEntityTest() + ->run(function (MakerTestRunner $runner) { + $this->copyEntityDirectory($runner, 'regenerate'); + + $runner->runMaker([ + // namespace: use default App\Entity + '', + ], '--regenerate'); + + $this->runCustomTest($runner, 'it_regenerates_entities.php'); + }), ]; - yield 'entity_regenerate_embeddable_object' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // namespace: use default App\Entity - '', - ]) - ->setRequiredPhpVersion(80000) - ->useDoctrineAttributeMapping() - ->setArgumentsString('--regenerate') - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntityRegenerateEmbeddableObject') - ->configureDatabase(), + yield 'it_regenerates_embedded_entities' => [$this->createMakeEntityTest() + ->run(function (MakerTestRunner $runner) { + $this->copyEntityDirectory($runner, 'regenerate-embedded'); + + $runner->runMaker([ + // namespace: use default App\Entity + '', + ], '--regenerate'); + + $this->runCustomTest($runner, 'it_regenerates_embedded_entities.php'); + }), ]; - yield 'entity_regenerate_embeddable' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // namespace: use default App\Entity - '', - ]) - ->setRequiredPhpVersion(80000) - ->useDoctrineAttributeMapping() - ->setArgumentsString('--regenerate --overwrite') - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntityRegenerateEmbedable') - ->configureDatabase(), + yield 'it_regenerates_embeddable_entity' => [$this->createMakeEntityTest() + ->run(function (MakerTestRunner $runner) { + $this->copyEntityDirectory($runner, 'regenerate-embeddable'); + + $runner->runMaker([ + // namespace: use default App\Entity + '', + ], '--regenerate'); + + $this->runCustomTest($runner, 'it_regenerates_embeddable_entity.php'); + }), ]; - yield 'entity_regenerate_overwrite' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // namespace: use default App\Entity - '', - ]) - ->setRequiredPhpVersion(80000) - ->useDoctrineAttributeMapping() - ->setArgumentsString('--regenerate --overwrite') - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntityRegenerateOverwrite') - ->configureDatabase(false), + yield 'it_regenerates_with_overwrite' => [$this->createMakeEntityTest(false) + ->run(function (MakerTestRunner $runner) { + $this->copyEntity($runner, 'User-invalid-method.php'); + + $runner->runMaker([ + // namespace: use default App\Entity + '', + ], '--regenerate --overwrite'); + + $this->runCustomTest($runner, 'it_regenerates_with_overwrite.php', false); + }), ]; - yield 'entity_regenerate_xml' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // namespace: use default App\Entity - '', - ]) - ->setArgumentsString('--regenerate') - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntityRegenerateXml') - ->addReplacement( - 'config/packages/doctrine.yaml', - 'type: annotation', - 'type: xml' - ) - ->addReplacement( - 'config/packages/doctrine.yaml', - "dir: '%kernel.project_dir%/src/Entity'", - "dir: '%kernel.project_dir%/config/doctrine'" - ) - ->configureDatabase(false), + yield 'it_regenerates_from_xml' => [$this->createMakeEntityTest(false) + ->run(function (MakerTestRunner $runner) { + $this->copyEntity($runner, 'User-basic.php'); + + $runner->copy( + 'make-entity/regenerate-xml', + '' + ); + + $this->changeToXmlMapping($runner); + + $runner->runMaker([ + // namespace: use default App\Entity + '', + ], '--regenerate'); + + $this->runCustomTest($runner, 'it_regenerates_from_xml.php', false); + }), ]; - yield 'entity_xml_mapping_error_existing' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - 'User', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntityXmlMappingError') - ->addReplacement( - 'config/packages/doctrine.yaml', - 'type: annotation', - 'type: xml' - ) - ->addReplacement( - 'config/packages/doctrine.yaml', - "dir: '%kernel.project_dir%/src/Entity'", - "dir: '%kernel.project_dir%/config/doctrine'" - ) - ->configureDatabase(false) - ->setCommandAllowedToFail(true) - ->assert(function (string $output, string $directory) { + yield 'it_display_an_error_using_with_xml' => [$this->createMakeEntityTest(false) + ->run(function (MakerTestRunner $runner) { + $this->copyEntity($runner, 'User-basic.php'); + + $runner->copy( + 'make-entity/xml-mapping', + '' + ); + + $this->changeToXmlMapping($runner); + + $output = $runner->runMaker([ + 'User', + '', + ], '', true /* allow failure */); + $this->assertStringContainsString('Only annotation or attribute mapping is supported', $output); }), ]; - yield 'entity_xml_mapping_error_new_class' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - 'UserAvatarPhoto', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntityXmlMappingError') - ->addReplacement( - 'config/packages/doctrine.yaml', - 'type: annotation', - 'type: xml' - ) - ->addReplacement( - 'config/packages/doctrine.yaml', - "dir: '%kernel.project_dir%/src/Entity'", - "dir: '%kernel.project_dir%/config/doctrine'" - ) - ->configureDatabase(false) - ->setCommandAllowedToFail(true) - ->assert(function (string $output, string $directory) { + yield 'it_display_an_error_using_with_xml_with_new_class' => [$this->createMakeEntityTest(false) + ->run(function (MakerTestRunner $runner) { + $this->copyEntity($runner, 'User-basic.php'); + + $runner->copy( + 'make-entity/xml-mapping', + '' + ); + + $this->changeToXmlMapping($runner); + + $output = $runner->runMaker([ + 'UserAvatarPhoto', + '', + ], '', true /* allow failure */); + $this->assertStringContainsString('Only annotation or attribute mapping is supported', $output); }), ]; - yield 'entity_updating_overwrite' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'User', - // field name - 'firstName', - 'string', - '', // length (default 255) - // nullable - '', - // finish adding fields - '', - ]) - ->setRequiredPhpVersion(80000) - ->useDoctrineAttributeMapping() - ->setArgumentsString('--overwrite') - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntityOverwrite'), + yield 'it_can_overwrite_while_adding_fields' => [$this->createMakeEntityTest() + ->run(function (MakerTestRunner $runner) { + $this->copyEntity($runner, 'User-invalid-method-no-property.php'); + + $runner->runMaker([ + // entity class name + 'User', + // field name + 'firstName', + 'string', + '', // length (default 255) + // nullable + '', + // finish adding fields + '', + ], '--overwrite'); + + $this->runCustomTest($runner, 'it_regenerates_with_overwrite.php'); + }), ]; // see #192 - yield 'entity_into_sub_namespace_matching_entity' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'Product\\Category', - // add not additional fields - '', - ]) - ->setRequiredPhpVersion(80000) - ->useDoctrineAttributeMapping() - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntitySubNamespaceMatchingEntity') - ->configureDatabase() - ->updateSchemaAfterCommand(), + yield 'it_creates_class_that_matches_existing_namespace' => [$this->createMakeEntityTest() + ->run(function (MakerTestRunner $runner) { + $this->copyEntity($runner, 'User-basic.php'); + + $runner->runMaker([ + // entity class name + 'User\\Category', + // add not additional fields + '', + ]); + + $this->runCustomTest($runner, 'it_creates_class_that_matches_existing_namespace.php'); + }), ]; - $broadCastTest = MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'User', - // Mark the entity as broadcasted - 'y', - // add not additional fields - '', - ]) - ->setRequiredPhpVersion(80000) - ->useDoctrineAttributeMapping() - ->addExtraDependencies('symfony/ux-turbo-mercure') - ->configureDatabase() - ->addReplacement( - '.env', - 'https://example.com/.well-known/mercure', - 'http://127.0.0.1:1337/.well-known/mercure' - ) - ->updateSchemaAfterCommand() - ->assert(function (string $output, string $directory) { - $this->assertFileExists($directory.'/src/Entity/User.php'); - - $content = file_get_contents($directory.'/src/Entity/User.php'); + yield 'it_makes_new_entity_with_mercure_broadcast' => [$this->createMakeEntityTestForMercure() + // special setup done in createMakeEntityTestForMercure() + ->run(function (MakerTestRunner $runner) { + $runner->replaceInFile( + '.env', + 'https://example.com/.well-known/mercure', + 'http://127.0.0.1:1337/.well-known/mercure' + ); + + $runner->runMaker([ + // entity class name + 'User', + // Mark the entity as broadcasted + 'y', + // add not additional fields + '', + ]); + + $this->assertFileExists($runner->getPath('src/Entity/User.php')); + + $content = file_get_contents($runner->getPath('src/Entity/User.php')); $this->assertStringContainsString('use Symfony\UX\Turbo\Attribute\Broadcast;', $content); - $this->assertStringContainsString('#[Broadcast]', $content); - }) - ; - // use the fixtures - which contains a test for Mercure - unless specified to skip those - $skipMercureTest = $_SERVER['MAKER_SKIP_MERCURE_TEST'] ?? false; - if (!$skipMercureTest) { - $broadCastTest->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntity'); - } - yield 'entity_new_broadcast' => [$broadCastTest]; + $this->assertStringContainsString($this->useAttributes($runner) ? '#[Broadcast]' : '@Broadcast', $content); - yield 'entity_new_with_api_and_broadcast_dependencies' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeEntity::class), - [ - // entity class name - 'User', - // Mark the entity as not an API Platform resource - 'n', - // Mark the entity as not broadcasted - 'n', - // add not additional fields - '', - ]) - ->setRequiredPhpVersion(80000) - ->useDoctrineAttributeMapping() + $skipMercureTest = $_SERVER['MAKER_SKIP_MERCURE_TEST'] ?? false; + if (!$skipMercureTest) { + $this->runEntityTest($runner); + } + }), + ]; + + yield 'it_makes_new_entity_no_to_all_extras' => [$this->createMakeEntityTestForMercure() ->addExtraDependencies('api') - ->addExtraDependencies('symfony/ux-turbo-mercure') - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntity') - ->configureDatabase() - ->updateSchemaAfterCommand() - ->assert(function (string $output, string $directory) { - $this->assertFileExists($directory.'/src/Entity/User.php'); + // special setup done in createMakeEntityTestForMercure() + ->run(function (MakerTestRunner $runner) { + $runner->runMaker([ + // entity class name + 'User', + // Mark the entity as not an API Platform resource + 'n', + // Mark the entity as not broadcasted + 'n', + // add not additional fields + '', + ]); + + $this->assertFileExists($runner->getPath('src/Entity/User.php')); + $this->runEntityTest($runner); }), ]; } + + private function runEntityTest(MakerTestRunner $runner, array $data = []) + { + $runner->renderTemplateFile( + 'make-entity/GeneratedEntityTest.php.twig', + 'tests/GeneratedEntityTest.php', + [ + 'data' => $data, + ] + ); + + $runner->updateSchema(); + $runner->runTests(); + } + + private function runCustomTest(MakerTestRunner $runner, string $filename, bool $withDatabase = true) + { + $runner->copy( + 'make-entity/tests/'.$filename, + 'tests/GeneratedEntityTest.php' + ); + + if ($withDatabase) { + $runner->updateSchema(); + } + $runner->runTests(); + } + + private function setupGroupEntityInVendor(MakerTestRunner $runner) + { + $runner->copy( + 'make-entity/Group-vendor.php', + 'vendor/some-vendor/src/Group.php' + ); + + $runner->addToAutoloader( + 'Some\\\Vendor\\\\', + 'vendor/some-vendor/src' + ); + } + + private function changeToXmlMapping(MakerTestRunner $runner) + { + $runner->replaceInFile( + 'config/packages/doctrine.yaml', + $this->useAttributes($runner) ? 'type: attribute' : 'type: annotation', + 'type: xml' + ); + $runner->replaceInFile( + 'config/packages/doctrine.yaml', + "dir: '%kernel.project_dir%/src/Entity'", + "dir: '%kernel.project_dir%/config/doctrine'" + ); + } + + private function useAttributes(MakerTestRunner $runner): bool + { + return \PHP_VERSION_ID >= 80000 + && $runner->doesClassExist(AttributeReader::class) + && $runner->getSymfonyVersion() >= 50200; + } + + private function copyEntity(MakerTestRunner $runner, string $filename) + { + $entityClassName = substr( + $filename, + 0, + strpos($filename, '-') + ); + + $runner->copy( + sprintf( + 'make-entity/entities/%s/%s', + $this->useAttributes($runner) ? 'attributes' : 'annotations', + $filename + ), + sprintf('src/Entity/%s.php', $entityClassName) + ); + } + + private function copyEntityDirectory(MakerTestRunner $runner, string $directory) + { + $runner->copy( + sprintf( + 'make-entity/%s/%s', + $directory, + $this->useAttributes($runner) ? 'attributes' : 'annotations' + ), + '' + ); + } } diff --git a/tests/Maker/MakeFixturesTest.php b/tests/Maker/MakeFixturesTest.php index 4aeb87a9f..b9443076b 100644 --- a/tests/Maker/MakeFixturesTest.php +++ b/tests/Maker/MakeFixturesTest.php @@ -13,18 +13,23 @@ use Symfony\Bundle\MakerBundle\Maker\MakeFixtures; use Symfony\Bundle\MakerBundle\Test\MakerTestCase; -use Symfony\Bundle\MakerBundle\Test\MakerTestDetails; +use Symfony\Bundle\MakerBundle\Test\MakerTestRunner; class MakeFixturesTest extends MakerTestCase { + protected function getMakerClass(): string + { + return MakeFixtures::class; + } + public function getTestDetails() { - yield 'fixtures' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeFixtures::class), - [ - 'FooFixtures', - ]) - ->assert(function (string $output, string $directory) { + yield 'it_generates_fixtures' => [$this->createMakerTest() + ->run(function (MakerTestRunner $runner) { + $output = $runner->runMaker([ + 'FooFixtures', + ]); + $this->assertStringContainsString('created: src/DataFixtures/FooFixtures.php', $output); }), ]; diff --git a/tests/Maker/MakeFormTest.php b/tests/Maker/MakeFormTest.php index c35fcdaee..dc69add33 100644 --- a/tests/Maker/MakeFormTest.php +++ b/tests/Maker/MakeFormTest.php @@ -13,63 +13,121 @@ use Symfony\Bundle\MakerBundle\Maker\MakeForm; use Symfony\Bundle\MakerBundle\Test\MakerTestCase; -use Symfony\Bundle\MakerBundle\Test\MakerTestDetails; +use Symfony\Bundle\MakerBundle\Test\MakerTestRunner; class MakeFormTest extends MakerTestCase { + protected function getMakerClass(): string + { + return MakeForm::class; + } + public function getTestDetails() { - yield 'form_basic' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeForm::class), - [ - // form name - 'FooBar', - '', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeForm'), + yield 'it_generates_basic_form' => [$this->createMakerTest() + ->run(function (MakerTestRunner $runner) { + $runner->runMaker([ + // form name + 'FooBar', + '', + ]); + + $this->runFormTest($runner, 'it_generates_basic_form.php'); + }), ]; - yield 'form_with_entity' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeForm::class), - [ - // Entity name - 'SourFoodType', - 'SourFood', - ]) + yield 'it_generates_form_with_entity' => [$this->createMakerTest() ->addExtraDependencies('orm') - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeFormForEntity'), + ->run(function (MakerTestRunner $runner) { + $runner->copy( + 'make-form/Property.php', + 'src/Entity/Property.php' + ); + $runner->copy( + 'make-form/SourFood.php', + 'src/Entity/SourFood.php' + ); + + $runner->runMaker([ + // Entity name + 'SourFoodType', + 'SourFood', + ]); + + $this->runFormTest($runner, 'it_generates_form_with_entity.php'); + }), ]; - yield 'form_for_non_entity_dto' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeForm::class), - [ - // Entity name - 'TaskType', - '\\App\\Form\\Data\\TaskData', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeFormForNonEntityDto'), + yield 'it_generates_form_with_non_entity_dto' => [$this->createMakerTest() + ->run(function (MakerTestRunner $runner) { + $runner->copy( + 'make-form/TaskData.php', + 'src/Form/Data/TaskData.php' + ); + + $runner->runMaker([ + // Entity name + 'TaskType', + '\\App\\Form\\Data\\TaskData', + ]); + + $this->runFormTest($runner, 'it_generates_form_with_non_entity_dto.php'); + }), ]; - yield 'form_for_sti_entity' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeForm::class), - [ - // Entity name - 'SourFoodType', - 'SourFood', - ]) + yield 'it_generates_form_with_single_table_inheritance_entity' => [$this->createMakerTest() ->addExtraDependencies('orm') - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeFormSTIEntity'), + ->run(function (MakerTestRunner $runner) { + $runner->copy( + 'make-form/inheritance/Food.php', + 'src/Entity/Food.php' + ); + $runner->copy( + 'make-form/inheritance/SourFood.php', + 'src/Entity/SourFood.php' + ); + + $runner->runMaker([ + // Entity name + 'SourFoodType', + 'SourFood', + ]); + + $this->runFormTest($runner, 'it_generates_form_with_single_table_inheritance_entity.php'); + }), ]; - yield 'form_for_embebadle_entity' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeForm::class), - [ - // Entity name - 'FoodType', - 'Food', - ]) + yield 'it_generates_form_with_embeddable_entity' => [$this->createMakerTest() ->addExtraDependencies('orm') - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeFormEmbedableEntity'), + ->run(function (MakerTestRunner $runner) { + $runner->copy( + 'make-form/embeddable/Food.php', + 'src/Entity/Food.php' + ); + $runner->copy( + 'make-form/embeddable/Receipt.php', + 'src/Entity/Receipt.php' + ); + + $runner->runMaker([ + // Entity name + 'FoodType', + 'Food', + ]); + + $this->runFormTest($runner, 'it_generates_form_with_embeddable_entity.php'); + }), ]; } + + private function runFormTest(MakerTestRunner $runner, string $filename) + { + $runner->copy( + 'make-form/tests/'.$filename, + 'tests/GeneratedFormTest.php' + ); + + $runner->configureDatabase(); + $runner->runTests(); + } } diff --git a/tests/Maker/MakeFunctionalTestTest.php b/tests/Maker/MakeFunctionalTestTest.php index 252b27cf4..16dcdf2e2 100644 --- a/tests/Maker/MakeFunctionalTestTest.php +++ b/tests/Maker/MakeFunctionalTestTest.php @@ -13,33 +13,39 @@ use Symfony\Bundle\MakerBundle\Maker\MakeFunctionalTest; use Symfony\Bundle\MakerBundle\Test\MakerTestCase; -use Symfony\Bundle\MakerBundle\Test\MakerTestDetails; +use Symfony\Bundle\MakerBundle\Test\MakerTestRunner; /** * @group legacy */ class MakeFunctionalTestTest extends MakerTestCase { - public function getTestDetails() + protected function getMakerClass(): string { - yield 'functional_maker' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeFunctionalTest::class), - [ - // functional test class name - 'FooBar', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeFunctional') - ->skip('See https://github.com/symfony/maker-bundle/pull/807/files#r571308250'), - ]; + return MakeFunctionalTest::class; + } - yield 'functional_with_panther' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeFunctionalTest::class), - [ - // functional test class name - 'FooBar', - ]) + public function getTestDetails() + { + yield 'it_generates_test_with_panther' => [$this->createMakerTest() ->addExtraDependencies('panther') - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeFunctional'), + ->run(function (MakerTestRunner $runner) { + $runner->copy( + 'make-functional/MainController.php', + 'src/Controller/MainController.php' + ); + $runner->copy( + 'make-functional/routes.yaml', + 'config/routes.yaml' + ); + + $runner->runMaker([ + // functional test class name + 'FooBar', + ]); + + $runner->runTests(); + }), ]; } } diff --git a/tests/Maker/MakeMessageTest.php b/tests/Maker/MakeMessageTest.php index f6d9062fa..984f01e85 100644 --- a/tests/Maker/MakeMessageTest.php +++ b/tests/Maker/MakeMessageTest.php @@ -14,61 +14,107 @@ use Symfony\Bundle\MakerBundle\Maker\MakeMessage; use Symfony\Bundle\MakerBundle\Test\MakerTestCase; use Symfony\Bundle\MakerBundle\Test\MakerTestDetails; +use Symfony\Bundle\MakerBundle\Test\MakerTestRunner; use Symfony\Component\Yaml\Yaml; class MakeMessageTest extends MakerTestCase { + protected function getMakerClass(): string + { + return MakeMessage::class; + } + + private function createMakeMessageTest(): MakerTestDetails + { + return $this->createMakerTest() + ->preRun(function (MakerTestRunner $runner) { + $runner->writeFile( + 'config/services_test.yaml', + Yaml::dump([ + 'services' => [ + '_defaults' => ['public' => true], + 'test.message_bus' => '@messenger.bus.default', + ], + ]) + ); + }); + } + public function getTestDetails() { - yield 'message_basic' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeMessage::class), - [ - 'SendWelcomeEmail', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeMessageBasic'), + yield 'it_generates_basic_message' => [$this->createMakeMessageTest() + ->run(function (MakerTestRunner $runner) { + $runner->runMaker([ + 'SendWelcomeEmail', + ]); + + $this->runMessageTest($runner, 'it_generates_basic_message.php'); + }), ]; - yield 'message_with_transport' => [ - MakerTestDetails::createTest( - $this->getMakerInstance(MakeMessage::class), - [ + yield 'it_generates_message_with_transport' => [$this->createMakeMessageTest() + ->run(function (MakerTestRunner $runner) { + $this->configureTransports($runner); + + $output = $runner->runMaker([ 'SendWelcomeEmail', 1, - ] - ) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeMessageWithTransport') - ->assert( - function (string $output, string $directory) { - $this->assertStringContainsString('Success', $output); - - $messengerConfig = Yaml::parse(file_get_contents(sprintf('%s/config/packages/messenger.yaml', $directory))); - $this->assertArrayHasKey('routing', $messengerConfig['framework']['messenger']); - $this->assertArrayHasKey('App\Message\SendWelcomeEmail', $messengerConfig['framework']['messenger']['routing']); - $this->assertSame( - 'async', - $messengerConfig['framework']['messenger']['routing']['App\Message\SendWelcomeEmail'] - ); - } - ), + ]); + + $this->assertStringContainsString('Success', $output); + + $messengerConfig = $runner->readYaml('config/packages/messenger.yaml'); + $this->assertArrayHasKey('routing', $messengerConfig['framework']['messenger']); + $this->assertArrayHasKey('App\Message\SendWelcomeEmail', $messengerConfig['framework']['messenger']['routing']); + $this->assertSame( + 'async', + $messengerConfig['framework']['messenger']['routing']['App\Message\SendWelcomeEmail'] + ); + + $this->runMessageTest($runner, 'it_generates_message_with_transport.php'); + }), ]; - yield 'message_with_no_transport' => [ - MakerTestDetails::createTest( - $this->getMakerInstance(MakeMessage::class), - [ + yield 'it_generates_message_with_no_transport' => [$this->createMakeMessageTest() + ->run(function (MakerTestRunner $runner) { + $this->configureTransports($runner); + + $output = $runner->runMaker([ 'SendWelcomeEmail', 0, - ] - ) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeMessageWithTransport') - ->assert( - function (string $output, string $directory) { - $this->assertStringContainsString('Success', $output); - - $messengerConfig = Yaml::parse(file_get_contents(sprintf('%s/config/packages/messenger.yaml', $directory))); - $this->assertArrayNotHasKey('routing', $messengerConfig['framework']['messenger']); - } - ), + ]); + + $this->assertStringContainsString('Success', $output); + + $messengerConfig = $runner->readYaml('config/packages/messenger.yaml'); + $this->assertArrayNotHasKey('routing', $messengerConfig['framework']['messenger']); + + $this->runMessageTest($runner, 'it_generates_message_with_transport.php'); + }), ]; } + + private function runMessageTest(MakerTestRunner $runner, string $filename) + { + $runner->copy( + 'make-message/tests/'.$filename, + 'tests/GeneratedMessageHandlerTest.php' + ); + + $runner->runTests(); + } + + private function configureTransports(MakerTestRunner $runner) + { + $runner->writeFile( + 'config/packages/messenger.yaml', + << [MakerTestDetails::createTest( - $this->getMakerInstance(MakeMessengerMiddleware::class), - [ - // middleware name - 'CustomMiddleware', - ])->assert(function (string $output, string $directory) { - $this->assertFileExists($directory.'/src/Middleware/CustomMiddleware.php'); + yield 'it_generates_messenger_middleware' => [$this->createMakerTest() + ->run(function (MakerTestRunner $runner) { + $runner->runMaker( + [ + // middleware name + 'CustomMiddleware', + ]); + + $this->assertFileExists($runner->getPath('src/Middleware/CustomMiddleware.php')); }), ]; } diff --git a/tests/Maker/MakeMigrationTest.php b/tests/Maker/MakeMigrationTest.php index 8bd5f31bd..310b99b67 100644 --- a/tests/Maker/MakeMigrationTest.php +++ b/tests/Maker/MakeMigrationTest.php @@ -14,29 +14,47 @@ use Symfony\Bundle\MakerBundle\Maker\MakeMigration; use Symfony\Bundle\MakerBundle\Test\MakerTestCase; use Symfony\Bundle\MakerBundle\Test\MakerTestDetails; +use Symfony\Bundle\MakerBundle\Test\MakerTestRunner; use Symfony\Component\Finder\Finder; class MakeMigrationTest extends MakerTestCase { - public function getTestDetails() + protected function getMakerClass(): string { - yield 'migration_with_changes' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeMigration::class), - [/* no input */]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeMigration') - ->configureDatabase(false) + return MakeMigration::class; + } + + private function createMakeMigrationTest(): MakerTestDetails + { + return $this->createMakerTest() // doctrine-migrations-bundle only requires doctrine-bundle, which // only requires doctrine/dbal. But we're testing with the ORM, // so let's install it ->addExtraDependencies('doctrine/orm:@stable') - ->assert(function (string $output, string $directory) { + ->preRun(function (MakerTestRunner $runner) { + $runner->copy( + 'make-migration/SpicyFood.php', + 'src/Entity/SpicyFood.php' + ); + + $runner->configureDatabase(false); + }) + ; + } + + public function getTestDetails() + { + yield 'it_generates_migration_with_changes' => [$this->createMakeMigrationTest() + ->run(function (MakerTestRunner $runner) { + $output = $runner->runMaker([/* no input */]); + $this->assertStringContainsString('Success', $output); // support for Migrations 3 (/migrations) and earlier - $migrationsDirectoryPath = file_exists($directory.'/migrations') ? 'migrations' : 'src/Migrations'; + $migrationsDirectoryPath = file_exists($runner->getPath('/migrations')) ? 'migrations' : 'src/Migrations'; $finder = new Finder(); - $finder->in($directory.'/'.$migrationsDirectoryPath) + $finder->in($runner->getPath($migrationsDirectoryPath)) ->name('*.php'); $this->assertCount(1, $finder); @@ -47,52 +65,46 @@ public function getTestDetails() }), ]; - yield 'migration_no_changes' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeMigration::class), - [/* no input */]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeMigration') - // sync the database, so no changes are needed - ->configureDatabase() - ->addExtraDependencies('doctrine/orm:@stable') - ->assert(function (string $output, string $directory) { + yield 'it_generates_migration_with_no_changes' => [$this->createMakeMigrationTest() + ->run(function (MakerTestRunner $runner) { + // sync so there are no changes + $runner->updateSchema(); + $output = $runner->runMaker([/* no input */]); + $this->assertStringNotContainsString('Success', $output); $this->assertStringContainsString('No database changes were detected', $output); }), ]; - yield 'migration_with_previous_migration_question' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeMigration::class), - [ - // confirm migration - 'y', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeMigration') - ->configureDatabase(false) + yield 'it_asks_previous_migration_question' => [$this->createMakeMigrationTest() ->addRequiredPackageVersion('doctrine/doctrine-migrations-bundle', '>=3') - ->addExtraDependencies('doctrine/orm:@stable') - // generate a migration first - ->addPreMakeCommand('php bin/console make:migration') - ->assert(function (string $output, string $directory) { + ->run(function (MakerTestRunner $runner) { + // generate a migration first + $runner->runConsole('make:migration', []); + + $output = $runner->runMaker([ + // confirm migration + 'y', + ]); + $this->assertStringContainsString('You have 1 available migrations to execute', $output); $this->assertStringContainsString('Success', $output); $this->assertCount(14, explode("\n", $output), 'Asserting that very specific output is shown - some should be hidden'); }), ]; - yield 'migration_with_previous_migration_decline_question' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeMigration::class), - [ - // no to confirm - 'n', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeMigration') - ->configureDatabase(false) + yield 'it_asks_previous_migration_question_and_decline' => [$this->createMakeMigrationTest() ->addRequiredPackageVersion('doctrine/doctrine-migrations-bundle', '>=3') - ->addExtraDependencies('doctrine/orm:@stable') - // generate a migration first - ->addPreMakeCommand('php bin/console make:migration') - ->assert(function (string $output, string $directory) { + ->run(function (MakerTestRunner $runner) { + // generate a migration first + $runner->runConsole('make:migration', []); + + $output = $runner->runMaker([ + // no to confirm + 'n', + ]); + $this->assertStringNotContainsString('Success', $output); }), ]; diff --git a/tests/Maker/MakeRegistrationFormTest.php b/tests/Maker/MakeRegistrationFormTest.php index 1f057bedf..10438a9ad 100644 --- a/tests/Maker/MakeRegistrationFormTest.php +++ b/tests/Maker/MakeRegistrationFormTest.php @@ -14,139 +14,183 @@ use Symfony\Bundle\MakerBundle\Maker\MakeRegistrationForm; use Symfony\Bundle\MakerBundle\Test\MakerTestCase; use Symfony\Bundle\MakerBundle\Test\MakerTestDetails; -use Symfony\Component\Filesystem\Filesystem; +use Symfony\Bundle\MakerBundle\Test\MakerTestRunner; +use Symfony\Component\Yaml\Yaml; class MakeRegistrationFormTest extends MakerTestCase { + protected function getMakerClass(): string + { + return MakeRegistrationForm::class; + } + + private function createRegistrationFormTest(): MakerTestDetails + { + return $this->createMakerTest() + ->preRun(function (MakerTestRunner $runner) { + $runner->copy( + 'make-registration-form/standard_setup', + '' + ); + $runner->adjustAuthenticatorForLegacyPassportInterface('src/Security/StubAuthenticator.php'); + }) + ; + } + public function getTestDetails() { - yield 'registration_form_entity_guard_authenticate' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeRegistrationForm::class), - [ - // user class guessed, - // username field guessed - // password guessed - '', // yes to add UniqueEntity - 'n', // verify user - // firewall name guessed - '', // yes authenticate after - // 1 authenticator will be guessed - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeRegistrationFormEntity') - ->configureDatabase() - ->updateSchemaAfterCommand() - // workaround for a strange behavior where, every other - // test run, the UniqueEntity would not be seen, because - // the the validation cache was out of date. The cause - // is currently unknown, so this workaround was added - ->addPostMakeCommand('php bin/console cache:clear --env=test'), - ]; + yield 'it_generates_registration_with_entity_and_authenticator' => [$this->createRegistrationFormTest() + ->addRequiredPackageVersion('symfony/security-bundle', '>=5.2') + ->run(function (MakerTestRunner $runner) { + $this->makeUser($runner); - // sanity check on all the interactive questions - yield 'registration_form_no_guessing' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeRegistrationForm::class), - [ - 'App\\Entity\\User', - 'emailAlt', // username field - 'passwordAlt', // password field - 'n', // no UniqueEntity - 'n', // no verify user - '', // yes authenticate after - 'main', // firewall - '1', // authenticator - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeRegistrationFormNoGuessing'), - ]; + $runner->modifyYamlFile('config/packages/security.yaml', function (array $data) { + $data['security']['firewalls']['main']['custom_authenticator'] = 'App\\Security\\StubAuthenticator'; - yield 'registration_form_entity_no_authenticate' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeRegistrationForm::class), - [ - // all basic data guessed - 'y', // add UniqueEntity - 'n', // no verify user - 'n', // no authenticate after - 'app_anonymous', // route name to redirect to - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeRegistrationFormEntity') - ->configureDatabase() - ->updateSchemaAfterCommand() - // workaround for strange failure - see test case - // registration_form_entity_guard_authenticate for details - ->addPostMakeCommand('php bin/console cache:clear --env=test'), - ]; + return $data; + }); - yield 'registration_form_with_email_verification' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeRegistrationForm::class), - [ - 'n', // add UniqueEntity - 'y', // verify user - 'y', // require authentication to verify user email - 'jr@rushlow.dev', // from email address - 'SymfonyCasts', // From Name - 'n', // no authenticate after - 0, // route number to redirect to - ]) - ->setRequiredPhpVersion(70200) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeRegistrationFormVerifyEmail') - ->addExtraDependencies('symfonycasts/verify-email-bundle') - ->assert( - function (string $output, string $directory) { - $this->assertStringContainsString('Success', $output); + $runner->runMaker([ + // user class guessed, + // username field guessed + // password guessed + '', // yes to add UniqueEntity + 'n', // verify user + // firewall name guessed + '', // yes authenticate after + // 1 authenticator will be guessed + ]); + + $this->runRegistrationTest($runner, 'it_generates_registration_with_entity_and_authenticator.php'); + }), + ]; - $fs = new Filesystem(); + yield 'it_generates_registration_with_entity_and_legacy_guard_authenticator' => [$this->createRegistrationFormTest() + ->addRequiredPackageVersion('symfony/security-bundle', '<5.2') + ->run(function (MakerTestRunner $runner) { + $this->makeUser($runner); - $generatedFiles = [ - 'src/Security/EmailVerifier.php', - 'templates/registration/confirmation_email.html.twig', + $runner->modifyYamlFile('config/packages/security.yaml', function (array $data) { + $data['security']['firewalls']['main']['guard'] = [ + 'authenticators' => ['App\\Security\\LegacyGuardStubAuthenticator'], ]; - foreach ($generatedFiles as $file) { - $this->assertTrue($fs->exists(sprintf('%s/%s', $directory, $file))); - } - } - ), + return $data; + }); + + $runner->runMaker([ + // user class guessed, + // username field guessed + // password guessed + '', // yes to add UniqueEntity + 'n', // verify user + // firewall name guessed + '', // yes authenticate after + // 1 authenticator will be guessed + ]); + + $this->runRegistrationTest($runner, 'it_generates_registration_with_entity_and_authenticator.php'); + }), ]; - yield 'verify_email_functional_test' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeRegistrationForm::class), - [ - 'n', // add UniqueEntity - 'y', // verify user - 'n', // require authentication to verify user email - 'jr@rushlow.dev', // from email address - 'SymfonyCasts', // From Name - '', // yes authenticate after - 'app_register', - ]) - ->setRequiredPhpVersion(70200) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeRegistrationFormVerifyEmailFunctionalTest') - ->addExtraDependencies('symfonycasts/verify-email-bundle') - ->configureDatabase() - ->updateSchemaAfterCommand() - // needed for internal functional test - ->addExtraDependencies('symfony/web-profiler-bundle') - ->addExtraDependencies('mailer'), + yield 'it_generates_registration_form_with_no_guessing' => [$this->createRegistrationFormTest() + ->run(function (MakerTestRunner $runner) { + $this->makeUser($runner, 'emailAlt'); + + $runner->runMaker([ + 'App\\Entity\\User', + 'emailAlt', // username field + 'passwordAlt', // password field + 'n', // no UniqueEntity + 'n', // no verify user + '', // yes authenticate after + 'main', // firewall + '1', // authenticator + ]); + }), ]; - yield 'verify_email_no_auth_functional_test' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeRegistrationForm::class), - [ - 'n', // add UniqueEntity - 'y', // verify user's email - 'y', // require authentication to verify user email - 'jr@rushlow.dev', // from email address - 'SymfonyCasts', // From Name - '', // yes authenticate after - 'main', // redirect to route after registration - ]) + yield 'it_generates_registration_form_with_entity_no_login' => [$this->createRegistrationFormTest() + ->run(function (MakerTestRunner $runner) { + $this->makeUser($runner); + + $runner->runMaker([ + // all basic data guessed + 'y', // add UniqueEntity + 'n', // no verify user + 'n', // no authenticate after + 'app_anonymous', // route name to redirect to + ]); + + $this->runRegistrationTest($runner, 'it_generates_registration_with_entity_and_authenticator.php'); + }), + ]; + + yield 'it_generates_registration_form_with_verification' => [$this->createRegistrationFormTest() ->setRequiredPhpVersion(70200) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeRegistrationFormVerifyEmailNoAuthFunctionalTest') ->addExtraDependencies('symfonycasts/verify-email-bundle') - ->configureDatabase() - ->updateSchemaAfterCommand() // needed for internal functional test - ->addExtraDependencies('symfony/web-profiler-bundle') - ->addExtraDependencies('mailer'), + ->addExtraDependencies('symfony/web-profiler-bundle', 'mailer') + ->run(function (MakerTestRunner $runner) { + $runner->writeFile( + 'config/packages/mailer.yaml', + Yaml::dump(['framework' => [ + 'mailer' => ['dsn' => 'null://null'], + ]]) + ); + + $this->makeUser($runner); + + $output = $runner->runMaker([ + 'n', // add UniqueEntity + 'y', // verify user + 'y', // require authentication to verify user email + 'jr@rushlow.dev', // from email address + 'SymfonyCasts', // From Name + 'n', // no authenticate after + 0, // route number to redirect to + ]); + + $this->assertStringContainsString('Success', $output); + + $generatedFiles = [ + 'src/Security/EmailVerifier.php', + 'templates/registration/confirmation_email.html.twig', + ]; + + foreach ($generatedFiles as $file) { + $this->assertFileExists($runner->getPath($file)); + } + + $this->runRegistrationTest($runner, 'it_generates_registration_form_with_verification.php'); + }), ]; } + + private function makeUser(MakerTestRunner $runner, string $identifier = 'email') + { + $runner->runConsole('make:user', [ + 'User', // class name + 'y', // entity + $identifier, // identifier + 'y', // password + ]); + } + + private function runRegistrationTest(MakerTestRunner $runner, string $filename) + { + $runner->copy( + 'make-registration-form/tests/'.$filename, + 'tests/RegistrationFormTest.php' + ); + + // workaround for a strange behavior where, every other + // test run, the UniqueEntity would not be seen, because + // the validation cache was out of date. The cause + // is currently unknown, so this workaround was added + $runner->runConsole('cache:clear', [], '--env=test'); + + $runner->configureDatabase(); + $runner->runTests(); + } } diff --git a/tests/Maker/MakeResetPasswordTest.php b/tests/Maker/MakeResetPasswordTest.php index 6120127ee..8f85793bc 100644 --- a/tests/Maker/MakeResetPasswordTest.php +++ b/tests/Maker/MakeResetPasswordTest.php @@ -14,156 +14,188 @@ use Symfony\Bundle\MakerBundle\Maker\MakeResetPassword; use Symfony\Bundle\MakerBundle\Test\MakerTestCase; use Symfony\Bundle\MakerBundle\Test\MakerTestDetails; -use Symfony\Component\Filesystem\Filesystem; +use Symfony\Bundle\MakerBundle\Test\MakerTestRunner; +use Symfony\Bundle\MakerBundle\Util\ClassSourceManipulator; use Symfony\Component\Yaml\Yaml; class MakeResetPasswordTest extends MakerTestCase { + protected function getMakerClass(): string + { + return MakeResetPassword::class; + } + + private function createResetPasswordTest(): MakerTestDetails + { + return $this->createMakerTest() + ->setRequiredPhpVersion(70200); + } + public function getTestDetails() { - yield 'reset_password_replaces_flex_config' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeResetPassword::class), - [ - 'App\Entity\User', - 'app_home', - 'jr@rushlow.dev', - 'SymfonyCasts', - ]) - ->setRequiredPhpVersion(70200) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeResetPassword') - ->assert( - function (string $output, string $directory) { - $this->assertStringContainsString('Success', $output); - - $fs = new Filesystem(); - - $generatedFiles = [ - 'src/Controller/ResetPasswordController.php', - 'src/Entity/ResetPasswordRequest.php', - 'src/Form/ChangePasswordFormType.php', - 'src/Form/ResetPasswordRequestFormType.php', - 'src/Repository/ResetPasswordRequestRepository.php', - 'templates/reset_password/check_email.html.twig', - 'templates/reset_password/email.html.twig', - 'templates/reset_password/request.html.twig', - 'templates/reset_password/reset.html.twig', - ]; - - foreach ($generatedFiles as $file) { - $this->assertTrue($fs->exists(sprintf('%s/%s', $directory, $file))); - } - - $configFileContents = file_get_contents(sprintf('%s/config/packages/reset_password.yaml', $directory)); - - // Flex recipe adds comments in reset_password.yaml, check file was replaced by maker - $this->assertStringNotContainsString('#', $configFileContents); - - $resetPasswordConfig = Yaml::parse($configFileContents); - - $this->assertSame('App\Repository\ResetPasswordRequestRepository', $resetPasswordConfig['symfonycasts_reset_password']['request_password_repository']); + yield 'it_generates_with_normal_setup' => [$this->createResetPasswordTest() + ->run(function (MakerTestRunner $runner) { + $this->makeUser($runner); + + $output = $runner->runMaker([ + 'App\Entity\User', + 'app_home', + 'jr@rushlow.dev', + 'SymfonyCasts', + ]); + + $this->assertStringContainsString('Success', $output); + + $generatedFiles = [ + 'src/Controller/ResetPasswordController.php', + 'src/Entity/ResetPasswordRequest.php', + 'src/Form/ChangePasswordFormType.php', + 'src/Form/ResetPasswordRequestFormType.php', + 'src/Repository/ResetPasswordRequestRepository.php', + 'templates/reset_password/check_email.html.twig', + 'templates/reset_password/email.html.twig', + 'templates/reset_password/request.html.twig', + 'templates/reset_password/reset.html.twig', + ]; + + foreach ($generatedFiles as $file) { + $this->assertFileExists($runner->getPath($file)); } - ), - ]; - yield 'reset_password_custom_config' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeResetPassword::class), - [ - 'App\Entity\User', - 'app_home', - 'jr@rushlow.dev', - 'SymfonyCasts', - ]) - ->setRequiredPhpVersion(70200) - ->deleteFile('config/packages/reset_password.yaml') - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeResetPasswordCustomConfig') - ->assert( - function (string $output, string $directory) { - $this->assertStringContainsString('Success', $output); - - $fs = new Filesystem(); - $this->assertFalse($fs->exists(sprintf('%s/config/packages/reset_password.yaml', $directory))); - $this->assertStringContainsString( - 'Just remember to set the request_password_repository in your configuration.', - $output - ); - } - ), + $configFileContents = file_get_contents($runner->getPath('config/packages/reset_password.yaml')); + + // Flex recipe adds comments in reset_password.yaml, check file was replaced by maker + $this->assertStringNotContainsString('#', $configFileContents); + + $resetPasswordConfig = $runner->readYaml('config/packages/reset_password.yaml'); + + $this->assertSame('App\Repository\ResetPasswordRequestRepository', $resetPasswordConfig['symfonycasts_reset_password']['request_password_repository']); + + $this->runResetPasswordTest($runner, 'it_generates_with_normal_setup.php'); + }), ]; - yield 'reset_password_amends_config' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeResetPassword::class), - [ - 'App\Entity\User', - 'app_home', - 'jr@rushlow.dev', - 'SymfonyCasts', - ]) - ->setRequiredPhpVersion(70200) - ->addReplacement( - 'config/packages/reset_password.yaml', - 'symfonycasts_reset_password:', - Yaml::dump(['symfonycasts_reset_password' => ['lifetime' => 9999]]) - ) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeResetPasswordModifiedConfig') - ->assert( - function (string $output, string $directory) { - $this->assertStringContainsString('Success', $output); - - $configFileContents = file_get_contents(sprintf('%s/config/packages/reset_password.yaml', $directory)); - - $resetPasswordConfig = Yaml::parse($configFileContents); - - $this->assertStringContainsString('9999', $resetPasswordConfig['symfonycasts_reset_password']['lifetime']); - $this->assertSame('App\Repository\ResetPasswordRequestRepository', $resetPasswordConfig['symfonycasts_reset_password']['request_password_repository']); + yield 'it_generates_with_custom_config' => [$this->createResetPasswordTest() + ->run(function (MakerTestRunner $runner) { + $runner->deleteFile('config/packages/reset_password.yaml'); + $runner->writeFile( + 'config/packages/custom_reset_password.yaml', + Yaml::dump(['symfonycasts_reset_password' => [ + 'request_password_repository' => 'symfonycasts.reset_password.fake_request_repository', + ]]) + ); + + $this->makeUser($runner); + + $output = $runner->runMaker([ + 'App\Entity\User', + 'app_home', + 'jr@rushlow.dev', + 'SymfonyCasts', + ]); + + $this->assertStringContainsString('Success', $output); + + if (method_exists($this, 'assertFileDoesNotExist')) { + $this->assertFileDoesNotExist($runner->getPath('config/packages/reset_password.yaml')); + } else { + $this->assertFileNotExists($runner->getPath('config/packages/reset_password.yaml')); } - ), + $this->assertStringContainsString( + 'Just remember to set the request_password_repository in your configuration.', + $output + ); + }), ]; - yield 'reset_password_functional_test' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeResetPassword::class), - [ - 'App\Entity\User', - 'app_home', - 'jr@rushlow.dev', - 'SymfonyCasts', - ]) - ->setRequiredPhpVersion(70200) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeResetPasswordFunctionalTest'), + yield 'it_amends_configuration' => [$this->createResetPasswordTest() + ->run(function (MakerTestRunner $runner) { + $runner->modifyYamlFile('config/packages/reset_password.yaml', function (array $config) { + $config['symfonycasts_reset_password']['lifetime'] = 9999; + + return $config; + }); + + $this->makeUser($runner); + + $output = $runner->runMaker([ + 'App\Entity\User', + 'app_home', + 'jr@rushlow.dev', + 'SymfonyCasts', + ]); + + $this->assertStringContainsString('Success', $output); + + $resetPasswordConfig = $runner->readYaml('config/packages/reset_password.yaml'); + + $this->assertStringContainsString('9999', $resetPasswordConfig['symfonycasts_reset_password']['lifetime']); + $this->assertSame('App\Repository\ResetPasswordRequestRepository', $resetPasswordConfig['symfonycasts_reset_password']['request_password_repository']); + }), ]; - yield 'reset_password_custom_user' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeResetPassword::class), - [ - 'App\Entity\UserCustom', - 'emailAddress', - 'setMyPassword', - 'app_home', - 'jr@rushlow.dev', - 'SymfonyCasts', - ]) - ->setRequiredPhpVersion(70200) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeResetPasswordCustomUserAttribute') - ->assert( - function (string $output, string $directory) { - $this->assertStringContainsString('Success', $output); - - // check ResetPasswordController - $contentResetPasswordController = file_get_contents($directory.'/src/Controller/ResetPasswordController.php'); - $this->assertStringContainsString('$form->get(\'emailAddress\')->getData()', $contentResetPasswordController); - $this->assertStringContainsString('\'emailAddress\' => $emailFormData,', $contentResetPasswordController); - $this->assertStringContainsString('$user->setMyPassword($encodedPassword);', $contentResetPasswordController); - $this->assertStringContainsString('->to($user->getEmailAddress())', $contentResetPasswordController); - // check ResetPasswordRequest - $contentResetPasswordRequest = file_get_contents($directory.'/src/Entity/ResetPasswordRequest.php'); - $this->assertStringContainsString('@ORM\ManyToOne(targetEntity=UserCustom::class)', $contentResetPasswordRequest); - // check ResetPasswordRequestFormType - $contentResetPasswordRequestFormType = file_get_contents($directory.'/src/Form/ResetPasswordRequestFormType.php'); - $this->assertStringContainsString('->add(\'emailAddress\', EmailType::class, [', $contentResetPasswordRequestFormType); - // check request.html.twig - $contentRequestHtml = file_get_contents($directory.'/templates/reset_password/request.html.twig'); - $this->assertStringContainsString('{{ form_row(requestForm.emailAddress) }}', $contentRequestHtml); - } - ), + yield 'it_generates_with_custom_user' => [$this->createResetPasswordTest() + ->run(function (MakerTestRunner $runner) { + $this->makeUser($runner, 'emailAddress', 'UserCustom', false); + + $runner->manipulateClass('src/Entity/UserCustom.php', function (ClassSourceManipulator $manipulator) { + $manipulator->addSetter('myPassword', 'string', true); + }); + + $output = $runner->runMaker([ + 'App\Entity\UserCustom', + 'emailAddress', + 'setMyPassword', + 'app_home', + 'jr@rushlow.dev', + 'SymfonyCasts', + ]); + + $this->assertStringContainsString('Success', $output); + + // check ResetPasswordController + $contentResetPasswordController = file_get_contents($runner->getPath('src/Controller/ResetPasswordController.php')); + $this->assertStringContainsString('$form->get(\'emailAddress\')->getData()', $contentResetPasswordController); + $this->assertStringContainsString('\'emailAddress\' => $emailFormData,', $contentResetPasswordController); + $this->assertStringContainsString('$user->setMyPassword($encodedPassword);', $contentResetPasswordController); + $this->assertStringContainsString('->to($user->getEmailAddress())', $contentResetPasswordController); + // check ResetPasswordRequest + $contentResetPasswordRequest = file_get_contents($runner->getPath('src/Entity/ResetPasswordRequest.php')); + $this->assertStringContainsString('ORM\ManyToOne(targetEntity=UserCustom::class)', $contentResetPasswordRequest); + // check ResetPasswordRequestFormType + $contentResetPasswordRequestFormType = file_get_contents($runner->getPath('/src/Form/ResetPasswordRequestFormType.php')); + $this->assertStringContainsString('->add(\'emailAddress\', EmailType::class, [', $contentResetPasswordRequestFormType); + // check request.html.twig + $contentRequestHtml = file_get_contents($runner->getPath('templates/reset_password/request.html.twig')); + $this->assertStringContainsString('{{ form_row(requestForm.emailAddress) }}', $contentRequestHtml); + }), ]; } + + private function runResetPasswordTest(MakerTestRunner $runner, string $filename) + { + $runner->writeFile( + 'config/packages/mailer.yaml', + Yaml::dump(['framework' => [ + 'mailer' => ['dsn' => 'null://null'], + ]]) + ); + + $runner->copy( + 'make-reset-password/tests/'.$filename, + 'tests/ResetPasswordFunctionalTest.php' + ); + + $runner->runTests(); + } + + private function makeUser(MakerTestRunner $runner, string $identifier = 'email', string $userClass = 'User', bool $checkPassword = true) + { + $runner->runConsole('make:user', [ + $userClass, // class name + 'y', // entity + $identifier, // identifier + $checkPassword ? 'y' : 'n', // password + ]); + } } diff --git a/tests/Maker/MakeSerializerEncoderTest.php b/tests/Maker/MakeSerializerEncoderTest.php index bf0579a15..9f4953e1b 100644 --- a/tests/Maker/MakeSerializerEncoderTest.php +++ b/tests/Maker/MakeSerializerEncoderTest.php @@ -13,20 +13,28 @@ use Symfony\Bundle\MakerBundle\Maker\MakeSerializerEncoder; use Symfony\Bundle\MakerBundle\Test\MakerTestCase; -use Symfony\Bundle\MakerBundle\Test\MakerTestDetails; +use Symfony\Bundle\MakerBundle\Test\MakerTestRunner; class MakeSerializerEncoderTest extends MakerTestCase { + protected function getMakerClass(): string + { + return MakeSerializerEncoder::class; + } + public function getTestDetails() { - yield 'serializer_encoder' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeSerializerEncoder::class), - [ - // encoder class name - 'FooBarEncoder', - // encoder format - 'foobar', - ]), + yield 'it_makes_serializer_encoder' => [$this->createMakerTest() + ->run(function (MakerTestRunner $runner) { + $runner->runMaker( + [ + // encoder class name + 'FooBarEncoder', + // encoder format + 'foobar', + ] + ); + }), ]; } } diff --git a/tests/Maker/MakeSerializerNormalizerTest.php b/tests/Maker/MakeSerializerNormalizerTest.php index c39cfb55d..2f38e7f0c 100644 --- a/tests/Maker/MakeSerializerNormalizerTest.php +++ b/tests/Maker/MakeSerializerNormalizerTest.php @@ -13,18 +13,26 @@ use Symfony\Bundle\MakerBundle\Maker\MakeSerializerNormalizer; use Symfony\Bundle\MakerBundle\Test\MakerTestCase; -use Symfony\Bundle\MakerBundle\Test\MakerTestDetails; +use Symfony\Bundle\MakerBundle\Test\MakerTestRunner; class MakeSerializerNormalizerTest extends MakerTestCase { + protected function getMakerClass(): string + { + return MakeSerializerNormalizer::class; + } + public function getTestDetails() { - yield 'serializer_normalizer' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeSerializerNormalizer::class), - [ - // normalizer class name - 'FooBarNormalizer', - ]), + yield 'it_makes_serializer_normalizer' => [$this->createMakerTest() + ->run(function (MakerTestRunner $runner) { + $runner->runMaker( + [ + // normalizer class name + 'FooBarNormalizer', + ] + ); + }), ]; } } diff --git a/tests/Maker/MakeSubscriberTest.php b/tests/Maker/MakeSubscriberTest.php index 85ba3f6d7..41b52ef83 100644 --- a/tests/Maker/MakeSubscriberTest.php +++ b/tests/Maker/MakeSubscriberTest.php @@ -13,30 +13,41 @@ use Symfony\Bundle\MakerBundle\Maker\MakeSubscriber; use Symfony\Bundle\MakerBundle\Test\MakerTestCase; -use Symfony\Bundle\MakerBundle\Test\MakerTestDetails; +use Symfony\Bundle\MakerBundle\Test\MakerTestRunner; class MakeSubscriberTest extends MakerTestCase { + protected function getMakerClass(): string + { + return MakeSubscriber::class; + } + public function getTestDetails() { - yield 'subscriber' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeSubscriber::class), - [ - // subscriber name - 'FooBar', - // event name - 'kernel.request', - ]), + yield 'it_makes_subscriber_for_known_event' => [$this->createMakerTest() + ->run(function (MakerTestRunner $runner) { + $runner->runMaker( + [ + // subscriber name + 'FooBar', + // event name + 'kernel.request', + ] + ); + }), ]; - yield 'subscriber_unknown_event_class' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeSubscriber::class), - [ - // subscriber name - 'FooBar', - // event name - 'foo.unknown_event', - ]), + yield 'it_makes_subscriber_for_unknown_event_class' => [$this->createMakerTest() + ->run(function (MakerTestRunner $runner) { + $runner->runMaker( + [ + // subscriber name + 'FooBar', + // event name + 'foo.unknown_event', + ] + ); + }), ]; } } diff --git a/tests/Maker/MakeTestTest.php b/tests/Maker/MakeTestTest.php index 85ebce17c..72e85f358 100644 --- a/tests/Maker/MakeTestTest.php +++ b/tests/Maker/MakeTestTest.php @@ -13,54 +13,97 @@ use Symfony\Bundle\MakerBundle\Maker\MakeTest; use Symfony\Bundle\MakerBundle\Test\MakerTestCase; -use Symfony\Bundle\MakerBundle\Test\MakerTestDetails; +use Symfony\Bundle\MakerBundle\Test\MakerTestRunner; class MakeTestTest extends MakerTestCase { + protected function getMakerClass(): string + { + return MakeTest::class; + } + public function getTestDetails() { - yield 'TestCase' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeTest::class), - [ - // type - 'TestCase', - // class name - 'FooBar', - ]), + yield 'it_makes_TestCase_type' => [$this->createMakerTest() + ->run(function (MakerTestRunner $runner) { + $runner->runMaker( + [ + // type + 'TestCase', + // class name + 'FooBar', + ] + ); + + $runner->runTests(); + }), ]; - yield 'KernelTestCase' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeTest::class), - [ - // type - 'KernelTestCase', - // functional test class name - 'FooBar', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeFunctional'), + yield 'it_makes_KernelTestCase_type' => [$this->createMakerTest() + ->run(function (MakerTestRunner $runner) { + $runner->copy( + 'make-test/basic_setup', + '' + ); + + $runner->runMaker( + [ + // type + 'KernelTestCase', + // functional test class name + 'FooBar', + ] + ); + + $runner->runTests(); + }), ]; - yield 'WebTestCase' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeTest::class), - [ - // type - 'WebTestCase', - // functional test class name - 'FooBar', - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeFunctional'), + yield 'it_makes_WebTestCase_type' => [$this->createMakerTest() + ->run(function (MakerTestRunner $runner) { + $runner->copy( + 'make-test/basic_setup', + '' + ); + + $runner->runMaker( + [ + // type + 'WebTestCase', + // functional test class name + 'FooBar', + ] + ); + + $runner->runTests(); + }), ]; - yield 'PantherTestCase' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeTest::class), - [ - // type - 'PantherTestCase', - // functional test class name - 'FooBar', - ]) + yield 'it_makes_PantherTestCase_type' => [$this->createMakerTest() ->addExtraDependencies('panther') - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeFunctional'), + ->run(function (MakerTestRunner $runner) { + $runner->copy( + 'make-test/basic_setup', + '' + ); + + $runner->runMaker( + [ + // type + 'PantherTestCase', + // functional test class name + 'FooBar', + ] + ); + + // bdi requires 7.2 at this time + if (\PHP_VERSION_ID >= 70200) { + $runner->runProcess('composer require --dev dbrekelmans/bdi'); + $runner->runProcess('php vendor/dbrekelmans/bdi/bdi detect drivers'); + + $runner->runTests(); + } + }), ]; } } diff --git a/tests/Maker/MakeTwigExtensionTest.php b/tests/Maker/MakeTwigExtensionTest.php index 011c349d9..458d59b9a 100644 --- a/tests/Maker/MakeTwigExtensionTest.php +++ b/tests/Maker/MakeTwigExtensionTest.php @@ -13,18 +13,26 @@ use Symfony\Bundle\MakerBundle\Maker\MakeTwigExtension; use Symfony\Bundle\MakerBundle\Test\MakerTestCase; -use Symfony\Bundle\MakerBundle\Test\MakerTestDetails; +use Symfony\Bundle\MakerBundle\Test\MakerTestRunner; class MakeTwigExtensionTest extends MakerTestCase { + protected function getMakerClass(): string + { + return MakeTwigExtension::class; + } + public function getTestDetails() { - yield 'twig_extension' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeTwigExtension::class), - [ - // extension class name - 'FooBar', - ]), + yield 'it_makes_twig_extension' => [$this->createMakerTest() + ->run(function (MakerTestRunner $runner) { + $runner->runMaker( + [ + // extension class name + 'FooBar', + ] + ); + }), ]; } } diff --git a/tests/Maker/MakeUnitTestTest.php b/tests/Maker/MakeUnitTestTest.php index d64fc3822..c84069694 100644 --- a/tests/Maker/MakeUnitTestTest.php +++ b/tests/Maker/MakeUnitTestTest.php @@ -13,21 +13,31 @@ use Symfony\Bundle\MakerBundle\Maker\MakeUnitTest; use Symfony\Bundle\MakerBundle\Test\MakerTestCase; -use Symfony\Bundle\MakerBundle\Test\MakerTestDetails; +use Symfony\Bundle\MakerBundle\Test\MakerTestRunner; /** * @group legacy */ class MakeUnitTestTest extends MakerTestCase { + protected function getMakerClass(): string + { + return MakeUnitTest::class; + } + public function getTestDetails() { - yield 'unit_test' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeUnitTest::class), - [ - // class name - 'FooBar', - ]), + yield 'it_makes_unit_test' => [$this->createMakerTest() + ->run(function (MakerTestRunner $runner) { + $runner->runMaker( + [ + // class name + 'FooBar', + ] + ); + + $runner->runTests(); + }), ]; } } diff --git a/tests/Maker/MakeUserTest.php b/tests/Maker/MakeUserTest.php index 060030968..2086361c0 100644 --- a/tests/Maker/MakeUserTest.php +++ b/tests/Maker/MakeUserTest.php @@ -13,60 +13,107 @@ use Symfony\Bundle\MakerBundle\Maker\MakeUser; use Symfony\Bundle\MakerBundle\Test\MakerTestCase; -use Symfony\Bundle\MakerBundle\Test\MakerTestDetails; +use Symfony\Bundle\MakerBundle\Test\MakerTestRunner; +use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; class MakeUserTest extends MakerTestCase { + protected function getMakerClass(): string + { + return MakeUser::class; + } + public function getTestDetails() { - yield 'user_security_entity_with_password' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeUser::class), - [ - // user class name - 'User', - 'y', // entity - 'email', // identity property - 'y', // with password - 'y', // argon @TODO This should only be done in <5.0 - ]) + yield 'it_generates_entity_with_password' => [$this->createMakerTest() ->addExtraDependencies('doctrine') - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeUserEntityPassword') - ->configureDatabase() - ->addExtraDependencies('doctrine') - ->setGuardAuthenticator('main', 'App\\Security\\AutomaticAuthenticator') - ->updateSchemaAfterCommand(), + ->run(function (MakerTestRunner $runner) { + $runner->copy( + 'make-user/standard_setup', + '' + ); + $runner->adjustAuthenticatorForLegacyPassportInterface('src/Security/AutomaticAuthenticator.php'); + + $runner->runMaker([ + // user class name + 'User', + 'y', // entity + 'email', // identity property + 'y', // with password + ]); + + // require 5.3 so we can use password hasher + if ($runner->getSymfonyVersion() >= 50300) { + $this->runUserTest($runner, 'it_generates_entity_with_password.php'); + } + }), ]; - yield 'user_security_entity_with_password_authenticated_user_interface' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeUser::class), - [ - // user class name - 'User', - 'y', // entity - 'email', // identity property - 'y', // with password - ]) - ->addRequiredPackageVersion('symfony/security-bundle', '>=5.3') + yield 'it_generates_non_entity_no_password' => [$this->createMakerTest() ->addExtraDependencies('doctrine') - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeUserEntityPasswordAuthenticatedUserInterface'), - ]; + ->run(function (MakerTestRunner $runner) { + $runner->copy( + 'make-user/standard_setup', + '' + ); + $runner->adjustAuthenticatorForLegacyPassportInterface('src/Security/AutomaticAuthenticator.php'); + + $runner->runMaker([ + // user class name (with non-traditional name) + 'FunUser', + 'n', // entity + 'username', // identity property + 'n', // login with password? + ]); + + // simplification: allows us to assume loadUserByIdentifier in test + if ($runner->getSymfonyVersion() >= 50300) { + $runner->replaceInFile( + 'src/Security/UserProvider.php', + 'throw new \Exception(\'TODO: fill in refreshUser() inside \'.__FILE__);', + 'return $user;' + ); + + $runner->replaceInFile( + 'src/Security/UserProvider.php', + 'throw new \Exception(\'TODO: fill in loadUserByIdentifier() inside \'.__FILE__);', + 'return (new FunUser())->setUsername($identifier);' + ); - yield 'user_security_model_no_password' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeUser::class), - [ - // user class name (with non-traditional name) - 'FunUser', - 'n', // entity - 'username', // identity property - 'n', // login with password? - ]) - ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeUserModelNoPassword') - ->setGuardAuthenticator('main', 'App\\Security\\AutomaticAuthenticator') - ->addPostMakeReplacement( - 'src/Security/UserProvider.php', - 'throw new \Exception(\'TODO: fill in refreshUser() inside \'.__FILE__);', - 'return $user;' - ), + $this->runUserTest($runner, 'it_generates_non_entity_no_password.php'); + } + }), ]; } + + private function runUserTest(MakerTestRunner $runner, string $filename, bool $withDatabase = true) + { + $runner->copy( + 'make-user/tests/'.$filename, + 'tests/GeneratedUserTest.php' + ); + + $runner->modifyYamlFile('config/packages/security.yaml', function (array $config) { + $config['security']['firewalls']['main']['custom_authenticator'] = 'App\Security\AutomaticAuthenticator'; + + return $config; + }); + + // make a service accessible in the test + // (the real one is removed as it's never used in the app) + $runner->modifyYamlFile('config/services.yaml', function (array $config) { + $config['services']['test_password_hasher'] = [ + 'public' => true, + 'alias' => UserPasswordHasherInterface::class, + ]; + + return $config; + }); + + if ($withDatabase) { + $runner->configureDatabase(); + } + + $runner->runTests(); + } } diff --git a/tests/Maker/MakeValidatorTest.php b/tests/Maker/MakeValidatorTest.php index 904980e4b..9ef973c0d 100644 --- a/tests/Maker/MakeValidatorTest.php +++ b/tests/Maker/MakeValidatorTest.php @@ -13,18 +13,26 @@ use Symfony\Bundle\MakerBundle\Maker\MakeValidator; use Symfony\Bundle\MakerBundle\Test\MakerTestCase; -use Symfony\Bundle\MakerBundle\Test\MakerTestDetails; +use Symfony\Bundle\MakerBundle\Test\MakerTestRunner; class MakeValidatorTest extends MakerTestCase { + protected function getMakerClass(): string + { + return MakeValidator::class; + } + public function getTestDetails() { - yield 'validator' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeValidator::class), - [ - // validator name - 'FooBar', - ]), + yield 'it_makes_validator' => [$this->createMakerTest() + ->run(function (MakerTestRunner $runner) { + $runner->runMaker( + [ + // validator name + 'FooBar', + ] + ); + }), ]; } } diff --git a/tests/Maker/MakeVoterTest.php b/tests/Maker/MakeVoterTest.php index a9fa6d773..3efec8b3a 100644 --- a/tests/Maker/MakeVoterTest.php +++ b/tests/Maker/MakeVoterTest.php @@ -13,18 +13,26 @@ use Symfony\Bundle\MakerBundle\Maker\MakeVoter; use Symfony\Bundle\MakerBundle\Test\MakerTestCase; -use Symfony\Bundle\MakerBundle\Test\MakerTestDetails; +use Symfony\Bundle\MakerBundle\Test\MakerTestRunner; class MakeVoterTest extends MakerTestCase { + protected function getMakerClass(): string + { + return MakeVoter::class; + } + public function getTestDetails() { - yield 'voter' => [MakerTestDetails::createTest( - $this->getMakerInstance(MakeVoter::class), - [ - // voter class name - 'FooBar', - ]), + yield 'it_makes_voter' => [$this->createMakerTest() + ->run(function (MakerTestRunner $runner) { + $runner->runMaker( + [ + // voter class name + 'FooBar', + ] + ); + }), ]; } } diff --git a/tests/Util/TemplateComponentGeneratorTest.php b/tests/Util/TemplateComponentGeneratorTest.php index f0a3431fa..93eca9e78 100644 --- a/tests/Util/TemplateComponentGeneratorTest.php +++ b/tests/Util/TemplateComponentGeneratorTest.php @@ -146,8 +146,8 @@ 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', 'POST'])]\n", true, ['GET', 'POST']]; + yield [" * @Route(\"/\", name=\"app_home\", methods={\"GET\", \"POST\"})\n", false, ['GET', 'POST']]; } /** diff --git a/tests/Util/fixtures/add_one_to_one_relation/User_simple_self.php b/tests/Util/fixtures/add_one_to_one_relation/User_simple_self.php index f84ea0ce7..eb755c43a 100644 --- a/tests/Util/fixtures/add_one_to_one_relation/User_simple_self.php +++ b/tests/Util/fixtures/add_one_to_one_relation/User_simple_self.php @@ -12,7 +12,7 @@ class User #[ORM\Column(type: 'integer')] private $id; - #[ORM\OneToOne(inversedBy: 'user', targetEntity: User::class, cascade: ['persist', 'remove'])] + #[ORM\OneToOne(inversedBy: 'user', targetEntity: self::class, cascade: ['persist', 'remove'])] private $embeddedUser; public function getId(): ?int diff --git a/tests/fixtures/MakeAuthenticator/config/packages/security.yaml b/tests/fixtures/MakeAuthenticator/config/packages/security.yaml deleted file mode 100644 index 48128ebee..000000000 --- a/tests/fixtures/MakeAuthenticator/config/packages/security.yaml +++ /dev/null @@ -1,24 +0,0 @@ -security: - # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers - providers: - in_memory: { memory: ~ } - firewalls: - dev: - pattern: ^/(_(profiler|wdt)|css|images|js)/ - security: false - main: - anonymous: true - - # activate different ways to authenticate - - # http_basic: true - # https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate - - # form_login: true - # https://symfony.com/doc/current/security/form_login_setup.html - - # Easy way to control access for large sections of your site - # Note: Only the *first* access control that matches will be used - access_control: - # - { path: ^/admin, roles: ROLE_ADMIN } - # - { path: ^/profile, roles: ROLE_USER } diff --git a/tests/fixtures/MakeAuthenticatorExistingAuthenticator/config/packages/security.yaml b/tests/fixtures/MakeAuthenticatorExistingAuthenticator/config/packages/security.yaml deleted file mode 100644 index e92c5f287..000000000 --- a/tests/fixtures/MakeAuthenticatorExistingAuthenticator/config/packages/security.yaml +++ /dev/null @@ -1,27 +0,0 @@ -security: - # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers - providers: - in_memory: { memory: ~ } - firewalls: - dev: - pattern: ^/(_(profiler|wdt)|css|images|js)/ - security: false - main: - anonymous: true - guard: - authenticators: - - App\Security\Authenticator - - # activate different ways to authenticate - - # http_basic: true - # https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate - - # form_login: true - # https://symfony.com/doc/current/security/form_login_setup.html - - # Easy way to control access for large sections of your site - # Note: Only the *first* access control that matches will be used - access_control: - # - { path: ^/admin, roles: ROLE_ADMIN } - # - { path: ^/profile, roles: ROLE_USER } diff --git a/tests/fixtures/MakeAuthenticatorExistingAuthenticator/src/Security/Authenticator.php b/tests/fixtures/MakeAuthenticatorExistingAuthenticator/src/Security/Authenticator.php deleted file mode 100644 index bb2a7859c..000000000 --- a/tests/fixtures/MakeAuthenticatorExistingAuthenticator/src/Security/Authenticator.php +++ /dev/null @@ -1,53 +0,0 @@ -userEmail; - } - - public function setUserEmail(string $userEmail): self - { - $this->userEmail = $userEmail; - - return $this; - } - - /** - * A visual identifier that represents this user. - * - * @see UserInterface - */ - public function getUsername(): string - { - return (string) $this->userEmail; - } - - /** - * @see UserInterface - */ - public function getRoles(): array - { - $roles = $this->roles; - // guarantee every user at least has ROLE_USER - $roles[] = 'ROLE_USER'; - - return array_unique($roles); - } - - public function setRoles(array $roles): self - { - $this->roles = $roles; - - return $this; - } - - /** - * @see UserInterface - */ - public function getPassword(): string - { - return (string) $this->password; - } - - public function setPassword(string $password): self - { - $this->password = $password; - - return $this; - } - - /** - * @see UserInterface - */ - public function getSalt() - { - // not needed when using the "bcrypt" algorithm in security.yaml - } - - /** - * @see UserInterface - */ - public function eraseCredentials() - { - // If you store any temporary, sensitive data on the user, clear it here - // $this->plainPassword = null; - } -} diff --git a/tests/fixtures/MakeAuthenticatorLoginFormCustomUsernameField/src/Security/UserProvider.php b/tests/fixtures/MakeAuthenticatorLoginFormCustomUsernameField/src/Security/UserProvider.php deleted file mode 100644 index 2d853f3f4..000000000 --- a/tests/fixtures/MakeAuthenticatorLoginFormCustomUsernameField/src/Security/UserProvider.php +++ /dev/null @@ -1,33 +0,0 @@ -setUserEmail($username) - ->setPassword($username); - } - - /** - * {@inheritdoc} - */ - public function refreshUser(UserInterface $user) - { - } - - /** - * {@inheritdoc} - */ - public function supportsClass($class) - { - } -} diff --git a/tests/fixtures/MakeAuthenticatorLoginFormCustomUsernameField/tests/SecurityControllerTest.php b/tests/fixtures/MakeAuthenticatorLoginFormCustomUsernameField/tests/SecurityControllerTest.php deleted file mode 100644 index 9ef67623f..000000000 --- a/tests/fixtures/MakeAuthenticatorLoginFormCustomUsernameField/tests/SecurityControllerTest.php +++ /dev/null @@ -1,46 +0,0 @@ -getConstructor()->getParameters(); - $this->assertSame('urlGenerator', $constructorParameters[0]->getName()); - - // assert authenticator is injected - $this->assertCount(3, $constructorParameters); - - $client = self::createClient(); - $crawler = $client->request('GET', '/login'); - - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - - $form = $crawler->filter('form')->form(); - $form->setValues( - [ - 'userEmail' => 'bar', - 'password' => 'foo', - ] - ); - $client->submit($form); - - $this->assertEquals(302, $client->getResponse()->getStatusCode()); - $client->followRedirect(); - $this->assertStringContainsString('Invalid credentials.', $client->getResponse()->getContent()); - $form->setValues( - [ - 'userEmail' => 'test@symfony.com', - 'password' => 'test@symfony.com', - ] - ); - $client->submit($form); - - $this->assertStringContainsString('TODO: provide a valid redirect', $client->getResponse()->getContent()); - } -} diff --git a/tests/fixtures/MakeAuthenticatorLoginFormExistingController/config/packages/security.yaml b/tests/fixtures/MakeAuthenticatorLoginFormExistingController/config/packages/security.yaml deleted file mode 100644 index e23084340..000000000 --- a/tests/fixtures/MakeAuthenticatorLoginFormExistingController/config/packages/security.yaml +++ /dev/null @@ -1,31 +0,0 @@ -security: - encoders: - App\Entity\User: plaintext - - # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers - providers: - app_user_provider: - entity: - class: App\Entity\User - property: email - - firewalls: - dev: - pattern: ^/(_(profiler|wdt)|css|images|js)/ - security: false - main: - anonymous: true - - # activate different ways to authenticate - - # http_basic: true - # https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate - - # form_login: true - # https://symfony.com/doc/current/security/form_login_setup.html - - # Easy way to control access for large sections of your site - # Note: Only the *first* access control that matches will be used - access_control: - # - { path: ^/admin, roles: ROLE_ADMIN } - # - { path: ^/profile, roles: ROLE_USER } diff --git a/tests/fixtures/MakeAuthenticatorLoginFormExistingController/src/Entity/User.php b/tests/fixtures/MakeAuthenticatorLoginFormExistingController/src/Entity/User.php deleted file mode 100644 index 1911a6ebe..000000000 --- a/tests/fixtures/MakeAuthenticatorLoginFormExistingController/src/Entity/User.php +++ /dev/null @@ -1,113 +0,0 @@ -id; - } - - public function getEmail() - { - return $this->email; - } - - public function setEmail(string $email): self - { - $this->email = $email; - - return $this; - } - - /** - * A visual identifier that represents this user. - * - * @see UserInterface - */ - public function getUsername(): string - { - return (string) $this->email; - } - - /** - * @see UserInterface - */ - public function getRoles(): array - { - $roles = $this->roles; - // guarantee every user at least has ROLE_USER - $roles[] = 'ROLE_USER'; - - return array_unique($roles); - } - - public function setRoles(array $roles): self - { - $this->roles = $roles; - - return $this; - } - - /** - * @see UserInterface - */ - public function getPassword(): string - { - return (string) $this->password; - } - - public function setPassword(string $password): self - { - $this->password = $password; - - return $this; - } - - /** - * @see UserInterface - */ - public function getSalt() - { - // not needed when using the "bcrypt" algorithm in security.yaml - } - - /** - * @see UserInterface - */ - public function eraseCredentials() - { - // If you store any temporary, sensitive data on the user, clear it here - // $this->plainPassword = null; - } -} diff --git a/tests/fixtures/MakeAuthenticatorLoginFormExistingController/tests/SecurityControllerTest.php b/tests/fixtures/MakeAuthenticatorLoginFormExistingController/tests/SecurityControllerTest.php deleted file mode 100644 index a1081f308..000000000 --- a/tests/fixtures/MakeAuthenticatorLoginFormExistingController/tests/SecurityControllerTest.php +++ /dev/null @@ -1,55 +0,0 @@ -assertTrue(method_exists(SecurityController::class, 'login')); - - $client = self::createClient(); - $crawler = $client->request('GET', '/login'); - - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - - /** @var EntityManagerInterface $em */ - $em = self::$kernel->getContainer() - ->get('doctrine') - ->getManager(); - - $user = (new User())->setEmail('test@symfony.com') - ->setPassword('password'); - $em->persist($user); - $em->flush(); - - $form = $crawler->filter('form')->form(); - $form->setValues( - [ - 'email' => 'test@symfony.com', - 'password' => 'foo', - ] - ); - $client->submit($form); - - $this->assertEquals(302, $client->getResponse()->getStatusCode()); - $client->followRedirect(); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertStringContainsString('Invalid credentials.', $client->getResponse()->getContent()); - - $form->setValues( - [ - 'email' => 'test@symfony.com', - 'password' => 'password', - ] - ); - $client->submit($form); - - $this->assertStringContainsString('TODO: provide a valid redirect', $client->getResponse()->getContent()); - } -} diff --git a/tests/fixtures/MakeAuthenticatorLoginFormUserEntity/config/packages/security.yaml b/tests/fixtures/MakeAuthenticatorLoginFormUserEntity/config/packages/security.yaml deleted file mode 100644 index 287d8fdb1..000000000 --- a/tests/fixtures/MakeAuthenticatorLoginFormUserEntity/config/packages/security.yaml +++ /dev/null @@ -1,31 +0,0 @@ -security: - encoders: - App\Entity\User: plaintext - - # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers - providers: - app_user_provider: - entity: - class: App\Entity\User - property: userEmail - - firewalls: - dev: - pattern: ^/(_(profiler|wdt)|css|images|js)/ - security: false - main: - anonymous: true - - # activate different ways to authenticate - - # http_basic: true - # https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate - - # form_login: true - # https://symfony.com/doc/current/security/form_login_setup.html - - # Easy way to control access for large sections of your site - # Note: Only the *first* access control that matches will be used - access_control: - # - { path: ^/admin, roles: ROLE_ADMIN } - # - { path: ^/profile, roles: ROLE_USER } diff --git a/tests/fixtures/MakeAuthenticatorLoginFormUserEntity/src/Entity/User.php b/tests/fixtures/MakeAuthenticatorLoginFormUserEntity/src/Entity/User.php deleted file mode 100644 index d88f9b5ac..000000000 --- a/tests/fixtures/MakeAuthenticatorLoginFormUserEntity/src/Entity/User.php +++ /dev/null @@ -1,113 +0,0 @@ -id; - } - - public function getUserEmail() - { - return $this->userEmail; - } - - public function setUserEmail(string $userEmail): self - { - $this->userEmail = $userEmail; - - return $this; - } - - /** - * A visual identifier that represents this user. - * - * @see UserInterface - */ - public function getUsername(): string - { - return (string) $this->userEmail; - } - - /** - * @see UserInterface - */ - public function getRoles(): array - { - $roles = $this->roles; - // guarantee every user at least has ROLE_USER - $roles[] = 'ROLE_USER'; - - return array_unique($roles); - } - - public function setRoles(array $roles): self - { - $this->roles = $roles; - - return $this; - } - - /** - * @see UserInterface - */ - public function getPassword(): string - { - return (string) $this->password; - } - - public function setPassword(string $password): self - { - $this->password = $password; - - return $this; - } - - /** - * @see UserInterface - */ - public function getSalt() - { - // not needed when using the "bcrypt" algorithm in security.yaml - } - - /** - * @see UserInterface - */ - public function eraseCredentials() - { - // If you store any temporary, sensitive data on the user, clear it here - // $this->plainPassword = null; - } -} diff --git a/tests/fixtures/MakeAuthenticatorLoginFormUserEntityLogout/config/packages/security.yaml b/tests/fixtures/MakeAuthenticatorLoginFormUserEntityLogout/config/packages/security.yaml deleted file mode 100644 index 287d8fdb1..000000000 --- a/tests/fixtures/MakeAuthenticatorLoginFormUserEntityLogout/config/packages/security.yaml +++ /dev/null @@ -1,31 +0,0 @@ -security: - encoders: - App\Entity\User: plaintext - - # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers - providers: - app_user_provider: - entity: - class: App\Entity\User - property: userEmail - - firewalls: - dev: - pattern: ^/(_(profiler|wdt)|css|images|js)/ - security: false - main: - anonymous: true - - # activate different ways to authenticate - - # http_basic: true - # https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate - - # form_login: true - # https://symfony.com/doc/current/security/form_login_setup.html - - # Easy way to control access for large sections of your site - # Note: Only the *first* access control that matches will be used - access_control: - # - { path: ^/admin, roles: ROLE_ADMIN } - # - { path: ^/profile, roles: ROLE_USER } diff --git a/tests/fixtures/MakeAuthenticatorLoginFormUserEntityLogout/src/Entity/User.php b/tests/fixtures/MakeAuthenticatorLoginFormUserEntityLogout/src/Entity/User.php deleted file mode 100644 index d88f9b5ac..000000000 --- a/tests/fixtures/MakeAuthenticatorLoginFormUserEntityLogout/src/Entity/User.php +++ /dev/null @@ -1,113 +0,0 @@ -id; - } - - public function getUserEmail() - { - return $this->userEmail; - } - - public function setUserEmail(string $userEmail): self - { - $this->userEmail = $userEmail; - - return $this; - } - - /** - * A visual identifier that represents this user. - * - * @see UserInterface - */ - public function getUsername(): string - { - return (string) $this->userEmail; - } - - /** - * @see UserInterface - */ - public function getRoles(): array - { - $roles = $this->roles; - // guarantee every user at least has ROLE_USER - $roles[] = 'ROLE_USER'; - - return array_unique($roles); - } - - public function setRoles(array $roles): self - { - $this->roles = $roles; - - return $this; - } - - /** - * @see UserInterface - */ - public function getPassword(): string - { - return (string) $this->password; - } - - public function setPassword(string $password): self - { - $this->password = $password; - - return $this; - } - - /** - * @see UserInterface - */ - public function getSalt() - { - // not needed when using the "bcrypt" algorithm in security.yaml - } - - /** - * @see UserInterface - */ - public function eraseCredentials() - { - // If you store any temporary, sensitive data on the user, clear it here - // $this->plainPassword = null; - } -} diff --git a/tests/fixtures/MakeAuthenticatorLoginFormUserEntityLogout/tests/SecurityControllerTest.php b/tests/fixtures/MakeAuthenticatorLoginFormUserEntityLogout/tests/SecurityControllerTest.php deleted file mode 100644 index 07ef684ac..000000000 --- a/tests/fixtures/MakeAuthenticatorLoginFormUserEntityLogout/tests/SecurityControllerTest.php +++ /dev/null @@ -1,84 +0,0 @@ -getConstructor()->getParameters(); - $this->assertSame('entityManager', $constructorParameters[0]->getName()); - - // assert authenticator is injected - $this->assertCount(4, $constructorParameters); - - $client = self::createClient(); - $crawler = $client->request('GET', '/login'); - - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - - /** @var EntityManagerInterface $em */ - $em = self::$kernel->getContainer() - ->get('doctrine') - ->getManager(); - - $user = (new User())->setUserEmail('test@symfony.com') - ->setPassword('password'); - $em->persist($user); - $em->flush(); - - $form = $crawler->filter('form')->form(); - $form->setValues( - [ - 'userEmail' => 'test@symfony.com', - 'password' => 'foo', - ] - ); - $crawler = $client->submit($form); - - if (500 === $client->getResponse()->getStatusCode()) { - $this->assertEquals('', $crawler->filter('h1.exception-message')->text()); - } - - $this->assertEquals(302, $client->getResponse()->getStatusCode()); - $client->followRedirect(); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertStringContainsString('Invalid credentials.', $client->getResponse()->getContent()); - - $form->setValues( - [ - 'userEmail' => 'test@symfony.com', - 'password' => 'password', - ] - ); - $client->submit($form); - - $this->assertStringContainsString('TODO: provide a valid redirect', $client->getResponse()->getContent()); - $this->assertInstanceOf(User::class, $this->getToken()->getUser()); - - $client->request('GET', '/logout'); - $this->assertNull($this->getToken()); - } - - /** - * Handle Session deprecations in Symfony 5.3+ - */ - private function getToken(): ?TokenInterface - { - $tokenStorage = static::$container->get('security.token_storage'); - - if (Kernel::VERSION_ID >= 50300) { - $tokenStorage->disableUsageTracking(); - } - - return $tokenStorage->getToken(); - } -} diff --git a/tests/fixtures/MakeAuthenticatorLoginFormUserEntityNoEncoder/config/packages/security.yaml b/tests/fixtures/MakeAuthenticatorLoginFormUserEntityNoEncoder/config/packages/security.yaml deleted file mode 100644 index 78ec73799..000000000 --- a/tests/fixtures/MakeAuthenticatorLoginFormUserEntityNoEncoder/config/packages/security.yaml +++ /dev/null @@ -1,28 +0,0 @@ -security: - # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers - providers: - app_user_provider: - entity: - class: App\Entity\User - property: email - - firewalls: - dev: - pattern: ^/(_(profiler|wdt)|css|images|js)/ - security: false - main: - anonymous: true - - # activate different ways to authenticate - - # http_basic: true - # https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate - - # form_login: true - # https://symfony.com/doc/current/security/form_login_setup.html - - # Easy way to control access for large sections of your site - # Note: Only the *first* access control that matches will be used - access_control: - # - { path: ^/admin, roles: ROLE_ADMIN } - # - { path: ^/profile, roles: ROLE_USER } diff --git a/tests/fixtures/MakeAuthenticatorLoginFormUserEntityNoEncoder/src/Entity/User.php b/tests/fixtures/MakeAuthenticatorLoginFormUserEntityNoEncoder/src/Entity/User.php deleted file mode 100644 index 1911a6ebe..000000000 --- a/tests/fixtures/MakeAuthenticatorLoginFormUserEntityNoEncoder/src/Entity/User.php +++ /dev/null @@ -1,113 +0,0 @@ -id; - } - - public function getEmail() - { - return $this->email; - } - - public function setEmail(string $email): self - { - $this->email = $email; - - return $this; - } - - /** - * A visual identifier that represents this user. - * - * @see UserInterface - */ - public function getUsername(): string - { - return (string) $this->email; - } - - /** - * @see UserInterface - */ - public function getRoles(): array - { - $roles = $this->roles; - // guarantee every user at least has ROLE_USER - $roles[] = 'ROLE_USER'; - - return array_unique($roles); - } - - public function setRoles(array $roles): self - { - $this->roles = $roles; - - return $this; - } - - /** - * @see UserInterface - */ - public function getPassword(): string - { - return (string) $this->password; - } - - public function setPassword(string $password): self - { - $this->password = $password; - - return $this; - } - - /** - * @see UserInterface - */ - public function getSalt() - { - // not needed when using the "bcrypt" algorithm in security.yaml - } - - /** - * @see UserInterface - */ - public function eraseCredentials() - { - // If you store any temporary, sensitive data on the user, clear it here - // $this->plainPassword = null; - } -} diff --git a/tests/fixtures/MakeAuthenticatorLoginFormUserEntityNoEncoder/tests/SecurityControllerTest.php b/tests/fixtures/MakeAuthenticatorLoginFormUserEntityNoEncoder/tests/SecurityControllerTest.php deleted file mode 100644 index ee07c9987..000000000 --- a/tests/fixtures/MakeAuthenticatorLoginFormUserEntityNoEncoder/tests/SecurityControllerTest.php +++ /dev/null @@ -1,48 +0,0 @@ -getConstructor()->getParameters(); - $this->assertSame('entityManager', $constructorParameters[0]->getName()); - - // assert authenticator is *not* injected - $this->assertCount(3, $constructorParameters); - - $client = self::createClient(); - $crawler = $client->request('GET', '/login'); - - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - - /** @var EntityManagerInterface $em */ - $em = self::$kernel->getContainer() - ->get('doctrine') - ->getManager(); - - $user = (new User())->setEmail('test@symfony.com') - ->setPassword('password'); - $em->persist($user); - $em->flush(); - - $form = $crawler->filter('form')->form(); - $form->setValues( - [ - 'email' => 'test@symfony.com', - 'password' => 'foo', - ] - ); - - $client->submit($form); - - $this->assertStringContainsString('TODO: check the credentials', $client->getResponse()->getContent()); - } -} diff --git a/tests/fixtures/MakeAuthenticatorLoginFormUserNotEntity/config/packages/security.yaml b/tests/fixtures/MakeAuthenticatorLoginFormUserNotEntity/config/packages/security.yaml deleted file mode 100644 index 6d3260fb6..000000000 --- a/tests/fixtures/MakeAuthenticatorLoginFormUserNotEntity/config/packages/security.yaml +++ /dev/null @@ -1,29 +0,0 @@ -security: - encoders: - App\Security\User: plaintext - - # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers - providers: - app_user_provider: - id: App\Security\UserProvider - - firewalls: - dev: - pattern: ^/(_(profiler|wdt)|css|images|js)/ - security: false - main: - anonymous: true - - # activate different ways to authenticate - - # http_basic: true - # https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate - - # form_login: true - # https://symfony.com/doc/current/security/form_login_setup.html - - # Easy way to control access for large sections of your site - # Note: Only the *first* access control that matches will be used - access_control: - # - { path: ^/admin, roles: ROLE_ADMIN } - # - { path: ^/profile, roles: ROLE_USER } diff --git a/tests/fixtures/MakeAuthenticatorLoginFormUserNotEntity/src/Security/User.php b/tests/fixtures/MakeAuthenticatorLoginFormUserNotEntity/src/Security/User.php deleted file mode 100644 index e7bd9b1e3..000000000 --- a/tests/fixtures/MakeAuthenticatorLoginFormUserNotEntity/src/Security/User.php +++ /dev/null @@ -1,90 +0,0 @@ -email; - } - - public function setEmail(string $email): self - { - $this->email = $email; - - return $this; - } - - /** - * A visual identifier that represents this user. - * - * @see UserInterface - */ - public function getUsername(): string - { - return (string) $this->email; - } - - /** - * @see UserInterface - */ - public function getRoles(): array - { - $roles = $this->roles; - // guarantee every user at least has ROLE_USER - $roles[] = 'ROLE_USER'; - - return array_unique($roles); - } - - public function setRoles(array $roles): self - { - $this->roles = $roles; - - return $this; - } - - /** - * @see UserInterface - */ - public function getPassword(): string - { - return (string) $this->password; - } - - public function setPassword(string $password): self - { - $this->password = $password; - - return $this; - } - - /** - * @see UserInterface - */ - public function getSalt() - { - // not needed when using the "bcrypt" algorithm in security.yaml - } - - /** - * @see UserInterface - */ - public function eraseCredentials() - { - // If you store any temporary, sensitive data on the user, clear it here - // $this->plainPassword = null; - } -} diff --git a/tests/fixtures/MakeAuthenticatorLoginFormUserNotEntity/src/Security/UserProvider.php b/tests/fixtures/MakeAuthenticatorLoginFormUserNotEntity/src/Security/UserProvider.php deleted file mode 100644 index 565d84e9b..000000000 --- a/tests/fixtures/MakeAuthenticatorLoginFormUserNotEntity/src/Security/UserProvider.php +++ /dev/null @@ -1,33 +0,0 @@ -setEmail($username) - ->setPassword($username); - } - - /** - * {@inheritdoc} - */ - public function refreshUser(UserInterface $user) - { - } - - /** - * {@inheritdoc} - */ - public function supportsClass($class) - { - } -} diff --git a/tests/fixtures/MakeAuthenticatorLoginFormUserNotEntity/tests/SecurityControllerTest.php b/tests/fixtures/MakeAuthenticatorLoginFormUserNotEntity/tests/SecurityControllerTest.php deleted file mode 100644 index 9f6b1723b..000000000 --- a/tests/fixtures/MakeAuthenticatorLoginFormUserNotEntity/tests/SecurityControllerTest.php +++ /dev/null @@ -1,46 +0,0 @@ -getConstructor()->getParameters(); - $this->assertSame('urlGenerator', $constructorParameters[0]->getName()); - - // assert authenticator is injected - $this->assertCount(3, $constructorParameters); - - $client = self::createClient(); - $crawler = $client->request('GET', '/login'); - - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - - $form = $crawler->filter('form')->form(); - $form->setValues( - [ - 'email' => 'bar', - 'password' => 'foo', - ] - ); - $client->submit($form); - - $this->assertEquals(302, $client->getResponse()->getStatusCode()); - $client->followRedirect(); - $this->assertStringContainsString('Invalid credentials.', $client->getResponse()->getContent()); - $form->setValues( - [ - 'email' => 'test@symfony.com', - 'password' => 'test@symfony.com', - ] - ); - $client->submit($form); - - $this->assertStringContainsString('TODO: provide a valid redirect', $client->getResponse()->getContent()); - } -} diff --git a/tests/fixtures/MakeAuthenticatorLoginFormUserNotEntityNoEncoder/config/packages/security.yaml b/tests/fixtures/MakeAuthenticatorLoginFormUserNotEntityNoEncoder/config/packages/security.yaml deleted file mode 100644 index 930ad4e89..000000000 --- a/tests/fixtures/MakeAuthenticatorLoginFormUserNotEntityNoEncoder/config/packages/security.yaml +++ /dev/null @@ -1,26 +0,0 @@ -security: - # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers - providers: - app_user_provider: - id: App\Security\UserProvider - - firewalls: - dev: - pattern: ^/(_(profiler|wdt)|css|images|js)/ - security: false - main: - anonymous: true - - # activate different ways to authenticate - - # http_basic: true - # https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate - - # form_login: true - # https://symfony.com/doc/current/security/form_login_setup.html - - # Easy way to control access for large sections of your site - # Note: Only the *first* access control that matches will be used - access_control: - # - { path: ^/admin, roles: ROLE_ADMIN } - # - { path: ^/profile, roles: ROLE_USER } diff --git a/tests/fixtures/MakeAuthenticatorLoginFormUserNotEntityNoEncoder/src/Security/User.php b/tests/fixtures/MakeAuthenticatorLoginFormUserNotEntityNoEncoder/src/Security/User.php deleted file mode 100644 index e7bd9b1e3..000000000 --- a/tests/fixtures/MakeAuthenticatorLoginFormUserNotEntityNoEncoder/src/Security/User.php +++ /dev/null @@ -1,90 +0,0 @@ -email; - } - - public function setEmail(string $email): self - { - $this->email = $email; - - return $this; - } - - /** - * A visual identifier that represents this user. - * - * @see UserInterface - */ - public function getUsername(): string - { - return (string) $this->email; - } - - /** - * @see UserInterface - */ - public function getRoles(): array - { - $roles = $this->roles; - // guarantee every user at least has ROLE_USER - $roles[] = 'ROLE_USER'; - - return array_unique($roles); - } - - public function setRoles(array $roles): self - { - $this->roles = $roles; - - return $this; - } - - /** - * @see UserInterface - */ - public function getPassword(): string - { - return (string) $this->password; - } - - public function setPassword(string $password): self - { - $this->password = $password; - - return $this; - } - - /** - * @see UserInterface - */ - public function getSalt() - { - // not needed when using the "bcrypt" algorithm in security.yaml - } - - /** - * @see UserInterface - */ - public function eraseCredentials() - { - // If you store any temporary, sensitive data on the user, clear it here - // $this->plainPassword = null; - } -} diff --git a/tests/fixtures/MakeAuthenticatorLoginFormUserNotEntityNoEncoder/src/Security/UserProvider.php b/tests/fixtures/MakeAuthenticatorLoginFormUserNotEntityNoEncoder/src/Security/UserProvider.php deleted file mode 100644 index 565d84e9b..000000000 --- a/tests/fixtures/MakeAuthenticatorLoginFormUserNotEntityNoEncoder/src/Security/UserProvider.php +++ /dev/null @@ -1,33 +0,0 @@ -setEmail($username) - ->setPassword($username); - } - - /** - * {@inheritdoc} - */ - public function refreshUser(UserInterface $user) - { - } - - /** - * {@inheritdoc} - */ - public function supportsClass($class) - { - } -} diff --git a/tests/fixtures/MakeAuthenticatorLoginFormUserNotEntityNoEncoder/tests/SecurityControllerTest.php b/tests/fixtures/MakeAuthenticatorLoginFormUserNotEntityNoEncoder/tests/SecurityControllerTest.php deleted file mode 100644 index cef8b357e..000000000 --- a/tests/fixtures/MakeAuthenticatorLoginFormUserNotEntityNoEncoder/tests/SecurityControllerTest.php +++ /dev/null @@ -1,35 +0,0 @@ -getConstructor()->getParameters(); - $this->assertSame('urlGenerator', $constructorParameters[0]->getName()); - - // assert authenticator is *not* injected - $this->assertCount(2, $constructorParameters); - - $client = self::createClient(); - $crawler = $client->request('GET', '/login'); - - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - - $form = $crawler->filter('form')->form(); - $form->setValues( - [ - 'email' => 'bar', - 'password' => 'foo', - ] - ); - $client->submit($form); - - $this->assertStringContainsString('TODO: check the credentials', $client->getResponse()->getContent()); - } -} diff --git a/tests/fixtures/MakeAuthenticatorMultipleFirewalls/config/packages/security.yaml b/tests/fixtures/MakeAuthenticatorMultipleFirewalls/config/packages/security.yaml deleted file mode 100644 index 23ddcbda6..000000000 --- a/tests/fixtures/MakeAuthenticatorMultipleFirewalls/config/packages/security.yaml +++ /dev/null @@ -1,26 +0,0 @@ -security: - # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers - providers: - in_memory: { memory: ~ } - firewalls: - dev: - pattern: ^/(_(profiler|wdt)|css|images|js)/ - security: false - main: - anonymous: true - second: - anonymous: true - - # activate different ways to authenticate - - # http_basic: true - # https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate - - # form_login: true - # https://symfony.com/doc/current/security/form_login_setup.html - - # Easy way to control access for large sections of your site - # Note: Only the *first* access control that matches will be used - access_control: - # - { path: ^/admin, roles: ROLE_ADMIN } - # - { path: ^/profile, roles: ROLE_USER } diff --git a/tests/fixtures/MakeAuthenticatorMultipleFirewallsExistingAuthenticator/config/packages/security.yaml b/tests/fixtures/MakeAuthenticatorMultipleFirewallsExistingAuthenticator/config/packages/security.yaml deleted file mode 100644 index 984406ab6..000000000 --- a/tests/fixtures/MakeAuthenticatorMultipleFirewallsExistingAuthenticator/config/packages/security.yaml +++ /dev/null @@ -1,29 +0,0 @@ -security: - # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers - providers: - in_memory: { memory: ~ } - firewalls: - dev: - pattern: ^/(_(profiler|wdt)|css|images|js)/ - security: false - main: - anonymous: true - second: - anonymous: true - guard: - authenticators: - - App\Security\Authenticator - - # activate different ways to authenticate - - # http_basic: true - # https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate - - # form_login: true - # https://symfony.com/doc/current/security/form_login_setup.html - - # Easy way to control access for large sections of your site - # Note: Only the *first* access control that matches will be used - access_control: - # - { path: ^/admin, roles: ROLE_ADMIN } - # - { path: ^/profile, roles: ROLE_USER } diff --git a/tests/fixtures/MakeAuthenticatorMultipleFirewallsExistingAuthenticator/src/Security/Authenticator.php b/tests/fixtures/MakeAuthenticatorMultipleFirewallsExistingAuthenticator/src/Security/Authenticator.php deleted file mode 100644 index bb2a7859c..000000000 --- a/tests/fixtures/MakeAuthenticatorMultipleFirewallsExistingAuthenticator/src/Security/Authenticator.php +++ /dev/null @@ -1,53 +0,0 @@ -id; - } - - public function getUserEmail() - { - return $this->userEmail; - } - - public function setUserEmail(string $userEmail): self - { - $this->userEmail = $userEmail; - - return $this; - } - - /** - * A visual identifier that represents this user. - * - * @see UserInterface - */ - public function getUsername(): string - { - return (string) $this->userEmail; - } - - /** - * @see UserInterface - */ - public function getRoles(): array - { - $roles = $this->roles; - // guarantee every user at least has ROLE_USER - $roles[] = 'ROLE_USER'; - - return array_unique($roles); - } - - public function setRoles(array $roles): self - { - $this->roles = $roles; - - return $this; - } - - /** - * @see UserInterface - */ - public function getPassword(): string - { - return (string) $this->password; - } - - public function setPassword(string $password): self - { - $this->password = $password; - - return $this; - } - - /** - * @see UserInterface - */ - public function getSalt() - { - // not needed when using the "bcrypt" algorithm in security.yaml - } - - /** - * @see UserInterface - */ - public function eraseCredentials() - { - // If you store any temporary, sensitive data on the user, clear it here - // $this->plainPassword = null; - } -} diff --git a/tests/fixtures/MakeAuthenticatorSecurity52LoginForm/src/Repository/UserRepository.php b/tests/fixtures/MakeAuthenticatorSecurity52LoginForm/src/Repository/UserRepository.php deleted file mode 100644 index 3455d5c52..000000000 --- a/tests/fixtures/MakeAuthenticatorSecurity52LoginForm/src/Repository/UserRepository.php +++ /dev/null @@ -1,38 +0,0 @@ -setPassword($newEncodedPassword); - $this->_em->persist($user); - $this->_em->flush(); - } -} \ No newline at end of file diff --git a/tests/fixtures/MakeAuthenticatorSecurity52LoginForm/tests/SecurityControllerTest.php b/tests/fixtures/MakeAuthenticatorSecurity52LoginForm/tests/SecurityControllerTest.php deleted file mode 100644 index 8475ca2c1..000000000 --- a/tests/fixtures/MakeAuthenticatorSecurity52LoginForm/tests/SecurityControllerTest.php +++ /dev/null @@ -1,85 +0,0 @@ - - */ -class SecurityControllerTest extends WebTestCase -{ - public function testGeneratedAuthenticatorHasExpectedConstructorArgs(): void - { - $authenticatorReflection = new \ReflectionClass(AppTestSecurity52LoginFormAuthenticator::class); - $constructorParameters = $authenticatorReflection->getConstructor()->getParameters(); - - self::assertSame(UrlGeneratorInterface::class, $constructorParameters[0]->getType()->getName()); - self::assertSame('urlGenerator', $constructorParameters[0]->getName()); - } - - public function testLoginFormAuthenticatorUsingSecurity51(): void - { - $client = self::createClient(); - $crawler = $client->request('GET', '/login'); - - self::assertEquals(200, $client->getResponse()->getStatusCode()); - - /** @var EntityManagerInterface $em */ - $em = self::$kernel->getContainer() - ->get('doctrine') - ->getManager(); - - $user = (new User())->setUserEmail('test@symfony.com') - ->setPassword('password'); - $em->persist($user); - $em->flush(); - - $form = $crawler->filter('form')->form(); - $form->setValues( - [ - 'userEmail' => 'test@symfony.com', - 'password' => 'foo', - ] - ); - $crawler = $client->submit($form); - - if (500 === $client->getResponse()->getStatusCode()) { - self::assertEquals('', $crawler->filter('h1.exception-message')->text()); - } - - self::assertEquals(302, $client->getResponse()->getStatusCode()); - - $client->followRedirect(); - - self::assertEquals(200, $client->getResponse()->getStatusCode()); - self::assertStringContainsString('Invalid credentials.', $client->getResponse()->getContent()); - - $form->setValues( - [ - 'userEmail' => 'test@symfony.com', - 'password' => 'password', - ] - ); - $client->submit($form); - - self::assertStringContainsString('TODO: provide a valid redirect', $client->getResponse()->getContent()); - - $tokenStorage = static::$container->get('security.token_storage'); - - // Handle Session deprecations in Symfony 5.3+ - if (Kernel::VERSION_ID >= 50300) { - $tokenStorage->disableUsageTracking(); - } - - $token = $tokenStorage->getToken(); - - self::assertNotNull($token); - self::assertInstanceOf(User::class, $token->getUser()); - } -} diff --git a/tests/fixtures/MakeCommandInCustomRootNamespace/config/packages/dev/maker.yaml b/tests/fixtures/MakeCommandInCustomRootNamespace/config/packages/dev/maker.yaml deleted file mode 100644 index 2691e7bf5..000000000 --- a/tests/fixtures/MakeCommandInCustomRootNamespace/config/packages/dev/maker.yaml +++ /dev/null @@ -1,2 +0,0 @@ -maker: - root_namespace: 'Custom' diff --git a/tests/fixtures/MakeCrudCustomController/src/Entity/SweetFood.php b/tests/fixtures/MakeCrudCustomController/src/Entity/SweetFood.php deleted file mode 100644 index 66590eaf7..000000000 --- a/tests/fixtures/MakeCrudCustomController/src/Entity/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/MakeCrudInCustomRootNamespace/config/packages/dev/maker.yaml b/tests/fixtures/MakeCrudInCustomRootNamespace/config/packages/dev/maker.yaml deleted file mode 100644 index 2691e7bf5..000000000 --- a/tests/fixtures/MakeCrudInCustomRootNamespace/config/packages/dev/maker.yaml +++ /dev/null @@ -1,2 +0,0 @@ -maker: - root_namespace: 'Custom' diff --git a/tests/fixtures/MakeCrudRepository/src/Entity/SweetFood.php b/tests/fixtures/MakeCrudRepository/src/Entity/SweetFood.php deleted file mode 100644 index 0336089ca..000000000 --- a/tests/fixtures/MakeCrudRepository/src/Entity/SweetFood.php +++ /dev/null @@ -1,45 +0,0 @@ -id; - } - - /** - * @return string - */ - public function getTitle() - { - return $this->title; - } - - /** - * @param string $title - */ - public function setTitle($title) - { - $this->title = $title; - } -} diff --git a/tests/fixtures/MakeCrudRepository/tests/GeneratedCrudControllerTest.php b/tests/fixtures/MakeCrudRepository/tests/GeneratedCrudControllerTest.php deleted file mode 100644 index c501fce37..000000000 --- a/tests/fixtures/MakeCrudRepository/tests/GeneratedCrudControllerTest.php +++ /dev/null @@ -1,15 +0,0 @@ -request('GET', '/sweet/food/'); - $this->assertTrue($client->getResponse()->isSuccessful()); - } -} diff --git a/tests/fixtures/MakeEntityExistsInRoot/src/Entity/Directory.php b/tests/fixtures/MakeEntityExistsInRoot/src/Entity/Directory.php deleted file mode 100644 index 1534b3aa1..000000000 --- a/tests/fixtures/MakeEntityExistsInRoot/src/Entity/Directory.php +++ /dev/null @@ -1,45 +0,0 @@ -id; - } - - public function getName() - { - return $this->name; - } - - public function setName(?string $name) - { - $this->name = $name; - } - - public function getCreatedAt(): ?\DateTimeInterface - { - return $this->createdAt; - } - - public function setCreatedAt(?\DateTimeInterface $createdAt) - { - $this->createdAt = $createdAt; - } -} diff --git a/tests/fixtures/MakeEntityExistsInRoot/tests/GeneratedEntityTest.php b/tests/fixtures/MakeEntityExistsInRoot/tests/GeneratedEntityTest.php deleted file mode 100644 index 9d31ee177..000000000 --- a/tests/fixtures/MakeEntityExistsInRoot/tests/GeneratedEntityTest.php +++ /dev/null @@ -1,49 +0,0 @@ -getContainer() - ->get('doctrine') - ->getManager(); - - $em->createQuery('DELETE FROM App\\Entity\\Directory u')->execute(); - - $directory = new Directory(); - // check that the constructor was instantiated properly - $this->assertInstanceOf(ArrayCollection::class, $directory->getChildDirectories()); - // set existing field - $directory->setName('root'); - $em->persist($directory); - - $subDir = new Directory(); - $subDir->setName('settings'); - $subDir->setParentDirectory($directory); - $em->persist($subDir); - - // set via the inverse side - $subDir2 = new Directory(); - $subDir2->setName('fixtures'); - $directory->addChildDirectory($subDir2); - $em->persist($subDir2); - - $em->flush(); - $em->refresh($directory); - - $actualDirectory = $em->getRepository(Directory::class) - ->findAll(); - - $this->assertCount(3, $actualDirectory); - $this->assertCount(2, $actualDirectory[0]->getChildDirectories()); - } -} diff --git a/tests/fixtures/MakeEntityManyToMany/src/Entity/User.php b/tests/fixtures/MakeEntityManyToMany/src/Entity/User.php deleted file mode 100644 index a8e96ecc1..000000000 --- a/tests/fixtures/MakeEntityManyToMany/src/Entity/User.php +++ /dev/null @@ -1,45 +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/MakeEntityManyToManyInCustomNamespace/config/packages/dev/maker.yaml b/tests/fixtures/MakeEntityManyToManyInCustomNamespace/config/packages/dev/maker.yaml deleted file mode 100644 index 2691e7bf5..000000000 --- a/tests/fixtures/MakeEntityManyToManyInCustomNamespace/config/packages/dev/maker.yaml +++ /dev/null @@ -1,2 +0,0 @@ -maker: - root_namespace: 'Custom' diff --git a/tests/fixtures/MakeEntityManyToOne/src/Entity/User.php b/tests/fixtures/MakeEntityManyToOne/src/Entity/User.php deleted file mode 100644 index a8e96ecc1..000000000 --- a/tests/fixtures/MakeEntityManyToOne/src/Entity/User.php +++ /dev/null @@ -1,45 +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/MakeEntityManyToOne/tests/GeneratedEntityTest.php b/tests/fixtures/MakeEntityManyToOne/tests/GeneratedEntityTest.php deleted file mode 100644 index 0f4ad20f4..000000000 --- a/tests/fixtures/MakeEntityManyToOne/tests/GeneratedEntityTest.php +++ /dev/null @@ -1,49 +0,0 @@ -getContainer() - ->get('doctrine') - ->getManager(); - - $em->createQuery('DELETE FROM App\\Entity\\User u')->execute(); - $em->createQuery('DELETE FROM App\\Entity\\UserAvatarPhoto u')->execute(); - - $user = new User(); - // check that the constructor was instantiated properly - $this->assertInstanceOf(ArrayCollection::class, $user->getUserAvatarPhotos()); - // set existing field - $user->setFirstName('Ryan'); - $em->persist($user); - - $photo = new UserAvatarPhoto(); - $photo->setUser($user); - $em->persist($photo); - - // set via the inverse side - $photo2 = new UserAvatarPhoto(); - $user->addUserAvatarPhoto($photo2); - $em->persist($photo2); - - $em->flush(); - $em->refresh($user); - - $actualUser = $em->getRepository(User::class) - ->findAll(); - - $this->assertcount(1, $actualUser); - $this->assertCount(2, $actualUser[0]->getUserAvatarPhotos()); - } -} diff --git a/tests/fixtures/MakeEntityManyToOneNoInverse/src/Entity/User.php b/tests/fixtures/MakeEntityManyToOneNoInverse/src/Entity/User.php deleted file mode 100644 index 0ca1ef7b2..000000000 --- a/tests/fixtures/MakeEntityManyToOneNoInverse/src/Entity/User.php +++ /dev/null @@ -1,19 +0,0 @@ -id; - } -} diff --git a/tests/fixtures/MakeEntityOneToOne/src/Entity/User.php b/tests/fixtures/MakeEntityOneToOne/src/Entity/User.php deleted file mode 100644 index a8e96ecc1..000000000 --- a/tests/fixtures/MakeEntityOneToOne/src/Entity/User.php +++ /dev/null @@ -1,45 +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/MakeEntityRegenerateOverwrite/tests/GeneratedEntityTest.php b/tests/fixtures/MakeEntityRegenerateOverwrite/tests/GeneratedEntityTest.php deleted file mode 100644 index 8873b3a8f..000000000 --- a/tests/fixtures/MakeEntityRegenerateOverwrite/tests/GeneratedEntityTest.php +++ /dev/null @@ -1,17 +0,0 @@ -setFirstName('Ryan'); - $this->assertSame('Ryan', $user->getFirstName()); - } -} diff --git a/tests/fixtures/MakeEntityRegenerateXml/src/Entity/User.php b/tests/fixtures/MakeEntityRegenerateXml/src/Entity/User.php deleted file mode 100644 index ab713de92..000000000 --- a/tests/fixtures/MakeEntityRegenerateXml/src/Entity/User.php +++ /dev/null @@ -1,14 +0,0 @@ -id; - } -} diff --git a/tests/fixtures/MakeEntityRelationVendorTarget/src/Entity/User.php b/tests/fixtures/MakeEntityRelationVendorTarget/src/Entity/User.php deleted file mode 100644 index 0ca1ef7b2..000000000 --- a/tests/fixtures/MakeEntityRelationVendorTarget/src/Entity/User.php +++ /dev/null @@ -1,19 +0,0 @@ -id; - } -} diff --git a/tests/fixtures/MakeEntitySelfReferencing/src/Entity/User.php b/tests/fixtures/MakeEntitySelfReferencing/src/Entity/User.php deleted file mode 100644 index a8e96ecc1..000000000 --- a/tests/fixtures/MakeEntitySelfReferencing/src/Entity/User.php +++ /dev/null @@ -1,45 +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/MakeEntitySubNamespaceMatchingEntity/src/Entity/Product.php b/tests/fixtures/MakeEntitySubNamespaceMatchingEntity/src/Entity/Product.php deleted file mode 100644 index caa008892..000000000 --- a/tests/fixtures/MakeEntitySubNamespaceMatchingEntity/src/Entity/Product.php +++ /dev/null @@ -1,14 +0,0 @@ -getContainer() - ->get('doctrine') - ->getManager(); - - $em->createQuery('DELETE FROM App\\Entity\\User f') - ->execute(); - - $food = new User(); - // set existing field - $food->setFirstName('Mr. Chocolate'); - // set the new, generated field - $food->setLastName('Cake'); - $em->persist($food); - $em->flush(); - - $actualFood = $em->getRepository(User::class) - ->findAll(); - - $this->assertcount(1, $actualFood); - } -} diff --git a/tests/fixtures/MakeEntityXmlMappingError/src/Entity/User.php b/tests/fixtures/MakeEntityXmlMappingError/src/Entity/User.php deleted file mode 100644 index ab713de92..000000000 --- a/tests/fixtures/MakeEntityXmlMappingError/src/Entity/User.php +++ /dev/null @@ -1,14 +0,0 @@ -id; - } -} diff --git a/tests/fixtures/MakeMessageBasic/config/services_test.yaml b/tests/fixtures/MakeMessageBasic/config/services_test.yaml deleted file mode 100644 index 885e28d4f..000000000 --- a/tests/fixtures/MakeMessageBasic/config/services_test.yaml +++ /dev/null @@ -1,5 +0,0 @@ -services: - _defaults: - public: true - - test.message_bus: '@messenger.bus.default' \ No newline at end of file diff --git a/tests/fixtures/MakeMessageWithTransport/config/packages/messenger.yaml b/tests/fixtures/MakeMessageWithTransport/config/packages/messenger.yaml deleted file mode 100644 index b4c6ead5c..000000000 --- a/tests/fixtures/MakeMessageWithTransport/config/packages/messenger.yaml +++ /dev/null @@ -1,5 +0,0 @@ -framework: - messenger: - transports: - async: 'sync://' - async_high_priority: 'sync://' \ No newline at end of file diff --git a/tests/fixtures/MakeMessageWithTransport/config/services_test.yaml b/tests/fixtures/MakeMessageWithTransport/config/services_test.yaml deleted file mode 100644 index 885e28d4f..000000000 --- a/tests/fixtures/MakeMessageWithTransport/config/services_test.yaml +++ /dev/null @@ -1,5 +0,0 @@ -services: - _defaults: - public: true - - test.message_bus: '@messenger.bus.default' \ No newline at end of file diff --git a/tests/fixtures/MakeRegistrationFormEntity/config/packages/security.yaml b/tests/fixtures/MakeRegistrationFormEntity/config/packages/security.yaml deleted file mode 100644 index 73a157866..000000000 --- a/tests/fixtures/MakeRegistrationFormEntity/config/packages/security.yaml +++ /dev/null @@ -1,20 +0,0 @@ -security: - encoders: - App\Entity\User: bcrypt - - # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers - providers: - app_user_provider: - entity: - class: App\Entity\User - property: email - - firewalls: - dev: - pattern: ^/(_(profiler|wdt)|css|images|js)/ - security: false - main: - anonymous: true - guard: - authenticators: - - App\Security\StubAuthenticator diff --git a/tests/fixtures/MakeRegistrationFormEntity/src/Entity/User.php b/tests/fixtures/MakeRegistrationFormEntity/src/Entity/User.php deleted file mode 100644 index 5bab0857b..000000000 --- a/tests/fixtures/MakeRegistrationFormEntity/src/Entity/User.php +++ /dev/null @@ -1,104 +0,0 @@ -id; - } - - public function getEmail() - { - return $this->email; - } - - public function setEmail(string $email): self - { - $this->email = $email; - - return $this; - } - - /** - * A visual identifier that represents this user. - * - * @see UserInterface - */ - public function getUsername(): string - { - return (string) $this->email; - } - - /** - * @see UserInterface - */ - public function getRoles(): array - { - $roles = $this->roles; - // guarantee every user at least has ROLE_USER - $roles[] = 'ROLE_USER'; - - return array_unique($roles); - } - - public function setRoles(array $roles): self - { - $this->roles = $roles; - - return $this; - } - - /** - * @see UserInterface - */ - public function getPassword(): string - { - return (string) $this->password; - } - - public function setPassword(string $password): self - { - $this->password = $password; - - return $this; - } - - public function getSalt() - { - } - - public function eraseCredentials() - { - } -} diff --git a/tests/fixtures/MakeRegistrationFormEntity/tests/VerifyEmailDoesntModifyUserEntityTest.php b/tests/fixtures/MakeRegistrationFormEntity/tests/VerifyEmailDoesntModifyUserEntityTest.php deleted file mode 100644 index 6cf26d357..000000000 --- a/tests/fixtures/MakeRegistrationFormEntity/tests/VerifyEmailDoesntModifyUserEntityTest.php +++ /dev/null @@ -1,15 +0,0 @@ -id; - } - - public function getEmailAlt() - { - return $this->emailAlt; - } - - public function setEmailAlt(string $email): self - { - $this->emailAlt = $email; - - return $this; - } - - /** - * A visual identifier that represents this user. - * - * @see UserInterface - */ - public function getUsername(): string - { - return (string) $this->emailAlt; - } - - /** - * @see UserInterface - */ - public function getRoles(): array - { - $roles = $this->roles; - // guarantee every user at least has ROLE_USER - $roles[] = 'ROLE_USER'; - - return array_unique($roles); - } - - public function setRoles(array $roles): self - { - $this->roles = $roles; - - return $this; - } - - /** - * @see UserInterface - */ - public function getPasswordAlt(): string - { - return (string) $this->passwordAlt; - } - - public function setPasswordAlt(string $password): self - { - $this->passwordAlt = $password; - - return $this; - } - - public function getPassword() - { - return $this->passwordAlt; - } - - public function getSalt() - { - } - - public function eraseCredentials() - { - } -} diff --git a/tests/fixtures/MakeRegistrationFormNoGuessing/src/Security/AuthenticatorFirst.php b/tests/fixtures/MakeRegistrationFormNoGuessing/src/Security/AuthenticatorFirst.php deleted file mode 100644 index 84df7f1da..000000000 --- a/tests/fixtures/MakeRegistrationFormNoGuessing/src/Security/AuthenticatorFirst.php +++ /dev/null @@ -1,7 +0,0 @@ -id; - } - - public function getEmail() - { - return $this->email; - } - - public function setEmail(string $email): self - { - $this->email = $email; - - return $this; - } - - /** - * A visual identifier that represents this user. - * - * @see UserInterface - */ - public function getUsername(): string - { - return (string) $this->email; - } - - /** - * @see UserInterface - */ - public function getRoles(): array - { - $roles = $this->roles; - // guarantee every user at least has ROLE_USER - $roles[] = 'ROLE_USER'; - - return array_unique($roles); - } - - public function setRoles(array $roles): self - { - $this->roles = $roles; - - return $this; - } - - /** - * @see UserInterface - */ - public function getPassword(): string - { - return (string) $this->password; - } - - public function setPassword(string $password): self - { - $this->password = $password; - - return $this; - } - - public function getSalt() - { - } - - public function eraseCredentials() - { - } -} diff --git a/tests/fixtures/MakeRegistrationFormVerifyEmail/tests/UserEntityTest.php b/tests/fixtures/MakeRegistrationFormVerifyEmail/tests/UserEntityTest.php deleted file mode 100644 index 5409965d4..000000000 --- a/tests/fixtures/MakeRegistrationFormVerifyEmail/tests/UserEntityTest.php +++ /dev/null @@ -1,15 +0,0 @@ -id; - } - - public function getEmail() - { - return $this->email; - } - - public function setEmail(string $email): self - { - $this->email = $email; - - return $this; - } - - public function getUsername(): string - { - return (string) $this->email; - } - - public function getRoles(): array - { - $roles = $this->roles; - // guarantee every user at least has ROLE_USER - $roles[] = 'ROLE_USER'; - - return array_unique($roles); - } - - public function setRoles(array $roles): self - { - $this->roles = $roles; - - return $this; - } - - public function getPassword(): string - { - return (string) $this->password; - } - - public function setPassword(string $password): self - { - $this->password = $password; - - return $this; - } - - public function getSalt() - { - } - - public function eraseCredentials() - { - } -} diff --git a/tests/fixtures/MakeRegistrationFormVerifyEmailFunctionalTest/src/Repository/UserRepository.php b/tests/fixtures/MakeRegistrationFormVerifyEmailFunctionalTest/src/Repository/UserRepository.php deleted file mode 100644 index 8f695cbe0..000000000 --- a/tests/fixtures/MakeRegistrationFormVerifyEmailFunctionalTest/src/Repository/UserRepository.php +++ /dev/null @@ -1,21 +0,0 @@ -entityManager = $entityManager; - $this->urlGenerator = $urlGenerator; - $this->csrfTokenManager = $csrfTokenManager; - $this->passwordEncoder = $passwordEncoder; - } - - public function supports(Request $request) - { - return self::LOGIN_ROUTE === $request->attributes->get('_route') - && $request->isMethod('POST'); - } - - public function getCredentials(Request $request) - { - $credentials = [ - 'email' => $request->request->get('email'), - 'password' => $request->request->get('password'), - 'csrf_token' => $request->request->get('_csrf_token'), - ]; - $request->getSession()->set( - Security::LAST_USERNAME, - $credentials['email'] - ); - - return $credentials; - } - - public function getUser($credentials, UserProviderInterface $userProvider) - { - $token = new CsrfToken('authenticate', $credentials['csrf_token']); - if (!$this->csrfTokenManager->isTokenValid($token)) { - throw new InvalidCsrfTokenException(); - } - - $user = $this->entityManager->getRepository(User::class)->findOneBy(['email' => $credentials['email']]); - - if (!$user) { - throw new UsernameNotFoundException('Email could not be found.'); - } - - return $user; - } - - public function checkCredentials($credentials, UserInterface $user) - { - return $this->passwordEncoder->isPasswordValid($user, $credentials['password']); - } - - public function getPassword($credentials): ?string - { - return $credentials['password']; - } - - public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey) - { - if ($targetPath = $this->getTargetPath($request->getSession(), $providerKey)) { - return new RedirectResponse($targetPath); - } - - return new RedirectResponse($this->urlGenerator->generate('app_login')); - } - - protected function getLoginUrl() - { - return $this->urlGenerator->generate(self::LOGIN_ROUTE); - } -} diff --git a/tests/fixtures/MakeRegistrationFormVerifyEmailNoAuthFunctionalTest/config/packages/mailer.yaml b/tests/fixtures/MakeRegistrationFormVerifyEmailNoAuthFunctionalTest/config/packages/mailer.yaml deleted file mode 100644 index 6da81a36b..000000000 --- a/tests/fixtures/MakeRegistrationFormVerifyEmailNoAuthFunctionalTest/config/packages/mailer.yaml +++ /dev/null @@ -1,3 +0,0 @@ -framework: - mailer: - dsn: 'null://null' \ No newline at end of file diff --git a/tests/fixtures/MakeRegistrationFormVerifyEmailNoAuthFunctionalTest/config/packages/security.yaml b/tests/fixtures/MakeRegistrationFormVerifyEmailNoAuthFunctionalTest/config/packages/security.yaml deleted file mode 100644 index 2fa285946..000000000 --- a/tests/fixtures/MakeRegistrationFormVerifyEmailNoAuthFunctionalTest/config/packages/security.yaml +++ /dev/null @@ -1,20 +0,0 @@ -security: - encoders: - App\Entity\User: bcrypt - - # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers - providers: - app_user_provider: - entity: - class: App\Entity\User - property: email - - firewalls: - dev: - pattern: ^/(_(profiler|wdt)|css|images|js)/ - security: false - main: - anonymous: true -# guard: -# authenticators: -# - App\Security\StubAuthenticator \ No newline at end of file diff --git a/tests/fixtures/MakeRegistrationFormVerifyEmailNoAuthFunctionalTest/src/Controller/MyController.php b/tests/fixtures/MakeRegistrationFormVerifyEmailNoAuthFunctionalTest/src/Controller/MyController.php deleted file mode 100644 index 72d6fab61..000000000 --- a/tests/fixtures/MakeRegistrationFormVerifyEmailNoAuthFunctionalTest/src/Controller/MyController.php +++ /dev/null @@ -1,18 +0,0 @@ -id; - } - - public function getEmail() - { - return $this->email; - } - - public function setEmail(string $email): self - { - $this->email = $email; - - return $this; - } - - public function getUsername(): string - { - return (string) $this->email; - } - - public function getRoles(): array - { - $roles = $this->roles; - // guarantee every user at least has ROLE_USER - $roles[] = 'ROLE_USER'; - - return array_unique($roles); - } - - public function setRoles(array $roles): self - { - $this->roles = $roles; - - return $this; - } - - public function getPassword(): string - { - return (string) $this->password; - } - - public function setPassword(string $password): self - { - $this->password = $password; - - return $this; - } - - public function getSalt() - { - } - - public function eraseCredentials() - { - } -} diff --git a/tests/fixtures/MakeRegistrationFormVerifyEmailNoAuthFunctionalTest/src/Repository/UserRepository.php b/tests/fixtures/MakeRegistrationFormVerifyEmailNoAuthFunctionalTest/src/Repository/UserRepository.php deleted file mode 100644 index 8f695cbe0..000000000 --- a/tests/fixtures/MakeRegistrationFormVerifyEmailNoAuthFunctionalTest/src/Repository/UserRepository.php +++ /dev/null @@ -1,21 +0,0 @@ -request('GET', '/register'); - - $form = $crawler->selectButton('Register')->form(); - $form['registration_form[email]'] = 'jr@rushlow.dev'; - $form['registration_form[plainPassword]'] = 'noAuth'; - $form['registration_form[agreeTerms]'] = true; - - $client->submit($form); - - $messages = $this->getMailerMessages(); - self::assertCount(1, $messages); - - /** @var EntityManager $em */ - $em = self::$kernel->getContainer() - ->get('doctrine') - ->getManager() - ; - - $query = $em->createQuery('SELECT u FROM App\\Entity\\User u WHERE u.email = \'jr@rushlow.dev\''); - - self::assertFalse(($query->getSingleResult())->isVerified()); - - $context = $messages[0]->getContext(); - - $client->request('GET', $context['signedUrl']); - - self::assertTrue(($query->getSingleResult())->isVerified()); - } -} diff --git a/tests/fixtures/MakeResetPassword/config/packages/security.yml b/tests/fixtures/MakeResetPassword/config/packages/security.yml deleted file mode 100644 index 0cdc923bd..000000000 --- a/tests/fixtures/MakeResetPassword/config/packages/security.yml +++ /dev/null @@ -1,3 +0,0 @@ -security: - encoders: - App\Entity\User: bcrypt diff --git a/tests/fixtures/MakeResetPassword/src/Entity/User.php b/tests/fixtures/MakeResetPassword/src/Entity/User.php deleted file mode 100644 index 98fcf97e9..000000000 --- a/tests/fixtures/MakeResetPassword/src/Entity/User.php +++ /dev/null @@ -1,38 +0,0 @@ -denyAccessUnlessGranted('ROLE_USER'); - - return new Response('Homepage Success'); - } -} diff --git a/tests/fixtures/MakeUserEntityPassword/src/Security/AutomaticAuthenticator.php b/tests/fixtures/MakeUserEntityPassword/src/Security/AutomaticAuthenticator.php deleted file mode 100644 index 237079d51..000000000 --- a/tests/fixtures/MakeUserEntityPassword/src/Security/AutomaticAuthenticator.php +++ /dev/null @@ -1,64 +0,0 @@ -em = $em; - $this->router = $router; - } - - public function supports(Request $request) - { - return '/login' === $request->getPathInfo() && $request->query->has('email'); - } - - public function getCredentials(Request $request) - { - return $request->query->get('email'); - } - - public function getUser($credentials, UserProviderInterface $userProvider) - { - return $this->em->getRepository(User::class)->findOneBy(['email' => $credentials]); - } - - public function checkCredentials($credentials, UserInterface $user) - { - return true; - } - - public function onAuthenticationFailure(Request $request, AuthenticationException $exception) - { - } - - public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey) - { - return new RedirectResponse($this->router->generate('app_homepage')); - } - - public function supportsRememberMe() - { - return true; - } - - public function start(Request $request, AuthenticationException $authException = null) - { - } -} diff --git a/tests/fixtures/MakeUserEntityPasswordAuthenticatedUserInterface/tests/GeneratedEntityTest.php b/tests/fixtures/MakeUserEntityPasswordAuthenticatedUserInterface/tests/GeneratedEntityTest.php deleted file mode 100644 index b1f158f2b..000000000 --- a/tests/fixtures/MakeUserEntityPasswordAuthenticatedUserInterface/tests/GeneratedEntityTest.php +++ /dev/null @@ -1,18 +0,0 @@ -implementsInterface(PasswordAuthenticatedUserInterface::class)); - self::assertTrue($reflectedUser->hasMethod('getPassword')); - } -} diff --git a/tests/fixtures/MakeUserModelNoPassword/config/routes.yaml b/tests/fixtures/MakeUserModelNoPassword/config/routes.yaml deleted file mode 100644 index 168829ea4..000000000 --- a/tests/fixtures/MakeUserModelNoPassword/config/routes.yaml +++ /dev/null @@ -1,7 +0,0 @@ -app_homepage: - path: / - controller: App\Controller\TestingController::homepage - -app_login: - path: /login - controller: ~ diff --git a/tests/fixtures/MakeUserModelNoPassword/src/Security/AutomaticAuthenticator.php b/tests/fixtures/MakeUserModelNoPassword/src/Security/AutomaticAuthenticator.php deleted file mode 100644 index 337adcef2..000000000 --- a/tests/fixtures/MakeUserModelNoPassword/src/Security/AutomaticAuthenticator.php +++ /dev/null @@ -1,63 +0,0 @@ -router = $router; - } - - public function supports(Request $request) - { - return '/login' === $request->getPathInfo() && $request->query->has('username'); - } - - public function getCredentials(Request $request) - { - return $request->query->get('username'); - } - - public function getUser($credentials, UserProviderInterface $userProvider) - { - $user = new FunUser(); - $user->setUsername($credentials); - - return $user; - } - - public function checkCredentials($credentials, UserInterface $user) - { - return true; - } - - public function onAuthenticationFailure(Request $request, AuthenticationException $exception) - { - } - - public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey) - { - return new RedirectResponse($this->router->generate('app_homepage')); - } - - public function supportsRememberMe() - { - return true; - } - - public function start(Request $request, AuthenticationException $authException = null) - { - } -} diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntity/tests/GeneratedEntityTest.php b/tests/fixtures/legacy/MakeEntity/MakeEntity/tests/GeneratedEntityTest.php deleted file mode 100644 index 50922ddaa..000000000 --- a/tests/fixtures/legacy/MakeEntity/MakeEntity/tests/GeneratedEntityTest.php +++ /dev/null @@ -1,35 +0,0 @@ -getContainer() - ->get('doctrine') - ->getManager(); - - $em->createQuery('DELETE FROM App\\Entity\\User u') - ->execute(); - - $user = new User(); - $em->persist($user); - $em->flush(); - $em->refresh($user); - - $actualUser = $em->getRepository(User::class) - ->findAll(); - - $this->assertcount(1, $actualUser); - } -} diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityExistsInRoot/src/Entity/Directory.php b/tests/fixtures/legacy/MakeEntity/MakeEntityExistsInRoot/src/Entity/Directory.php deleted file mode 100644 index 0ec7ee4f6..000000000 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityExistsInRoot/src/Entity/Directory.php +++ /dev/null @@ -1,53 +0,0 @@ -id; - } - - public function getName() - { - return $this->name; - } - - public function setName(?string $name) - { - $this->name = $name; - } - - public function getCreatedAt(): ?\DateTimeInterface - { - return $this->createdAt; - } - - public function setCreatedAt(?\DateTimeInterface $createdAt) - { - $this->createdAt = $createdAt; - } -} diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityExistsInRoot/tests/GeneratedEntityTest.php b/tests/fixtures/legacy/MakeEntity/MakeEntityExistsInRoot/tests/GeneratedEntityTest.php deleted file mode 100644 index 9d31ee177..000000000 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityExistsInRoot/tests/GeneratedEntityTest.php +++ /dev/null @@ -1,49 +0,0 @@ -getContainer() - ->get('doctrine') - ->getManager(); - - $em->createQuery('DELETE FROM App\\Entity\\Directory u')->execute(); - - $directory = new Directory(); - // check that the constructor was instantiated properly - $this->assertInstanceOf(ArrayCollection::class, $directory->getChildDirectories()); - // set existing field - $directory->setName('root'); - $em->persist($directory); - - $subDir = new Directory(); - $subDir->setName('settings'); - $subDir->setParentDirectory($directory); - $em->persist($subDir); - - // set via the inverse side - $subDir2 = new Directory(); - $subDir2->setName('fixtures'); - $directory->addChildDirectory($subDir2); - $em->persist($subDir2); - - $em->flush(); - $em->refresh($directory); - - $actualDirectory = $em->getRepository(Directory::class) - ->findAll(); - - $this->assertCount(3, $actualDirectory); - $this->assertCount(2, $actualDirectory[0]->getChildDirectories()); - } -} diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityManyToMany/src/Entity/User.php b/tests/fixtures/legacy/MakeEntity/MakeEntityManyToMany/src/Entity/User.php deleted file mode 100644 index e64f975d9..000000000 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityManyToMany/src/Entity/User.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/legacy/MakeEntity/MakeEntityManyToMany/tests/GeneratedEntityTest.php b/tests/fixtures/legacy/MakeEntity/MakeEntityManyToMany/tests/GeneratedEntityTest.php deleted file mode 100644 index 0b2b0aa1e..000000000 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityManyToMany/tests/GeneratedEntityTest.php +++ /dev/null @@ -1,61 +0,0 @@ -getContainer() - ->get('doctrine') - ->getManager(); - - $em->createQuery('DELETE FROM App\\Entity\\User u')->execute(); - $em->createQuery('DELETE FROM App\\Entity\\Course u')->execute(); - - $user = new User(); - // check that the constructor was instantiated properly - $this->assertInstanceOf(ArrayCollection::class, $user->getCourses()); - $em->persist($user); - - $course = new Course(); - $course->addStudent($user); - $em->persist($course); - - // set via the inverse side - $course2 = new Course(); - $user->addCourse($course2); - $em->persist($course2); - - $course3 = new Course(); - $user->addCourse($course3); - $em->persist($course3); - - $em->flush(); - $em->refresh($user); - - $actualUser = $em->getRepository(User::class) - ->findAll(); - - $this->assertcount(1, $actualUser); - $this->assertCount(3, $actualUser[0]->getCourses()); - - // remove some! - $user->removeCourse($course3); - $course2->removeStudent($user); - $em->flush(); - $em->refresh($user); - $em->refresh($course2); - // we removed course3, and course2 removed us! - $this->assertCount(1, $user->getCourses()); - $this->assertEmpty($course2->getStudents()); - } -} diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityManyToManyInCustomNamespace/config/packages/dev/maker.yaml b/tests/fixtures/legacy/MakeEntity/MakeEntityManyToManyInCustomNamespace/config/packages/dev/maker.yaml deleted file mode 100644 index 2691e7bf5..000000000 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityManyToManyInCustomNamespace/config/packages/dev/maker.yaml +++ /dev/null @@ -1,2 +0,0 @@ -maker: - root_namespace: 'Custom' diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityManyToManyInCustomNamespace/tests/GeneratedEntityTest.php b/tests/fixtures/legacy/MakeEntity/MakeEntityManyToManyInCustomNamespace/tests/GeneratedEntityTest.php deleted file mode 100644 index fcc0130da..000000000 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityManyToManyInCustomNamespace/tests/GeneratedEntityTest.php +++ /dev/null @@ -1,64 +0,0 @@ -getContainer() - ->get('doctrine') - ->getManager(); - - $em->createQuery('DELETE FROM Custom\\Entity\\User u')->execute(); - $em->createQuery('DELETE FROM Custom\\Entity\\Course u')->execute(); - - $user = new User(); - // check that the constructor was instantiated properly - $this->assertInstanceOf(ArrayCollection::class, $user->getCourses()); - $em->persist($user); - - $course = new Course(); - $course->addStudent($user); - $em->persist($course); - - // set via the inverse side - $course2 = new Course(); - $user->addCourse($course2); - $em->persist($course2); - - $course3 = new Course(); - $user->addCourse($course3); - $em->persist($course3); - - $em->flush(); - $em->refresh($user); - - $actualUser = $em->getRepository(User::class) - ->findAll(); - - $this->assertcount(1, $actualUser); - $this->assertCount(3, $actualUser[0]->getCourses()); - - // remove some! - $user->removeCourse($course3); - $course2->removeStudent($user); - $em->flush(); - $em->refresh($user); - $em->refresh($course2); - // we removed course3, and course2 removed us! - $this->assertCount(1, $user->getCourses()); - $this->assertEmpty($course2->getStudents()); - - // check repository namespace - $this->assertStringStartsWith('Custom\\', \get_class($em->getRepository(Course::class))); - } -} diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityManyToOne/src/Entity/User.php b/tests/fixtures/legacy/MakeEntity/MakeEntityManyToOne/src/Entity/User.php deleted file mode 100644 index e64f975d9..000000000 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityManyToOne/src/Entity/User.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/legacy/MakeEntity/MakeEntityManyToOne/tests/GeneratedEntityTest.php b/tests/fixtures/legacy/MakeEntity/MakeEntityManyToOne/tests/GeneratedEntityTest.php deleted file mode 100644 index 0f4ad20f4..000000000 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityManyToOne/tests/GeneratedEntityTest.php +++ /dev/null @@ -1,49 +0,0 @@ -getContainer() - ->get('doctrine') - ->getManager(); - - $em->createQuery('DELETE FROM App\\Entity\\User u')->execute(); - $em->createQuery('DELETE FROM App\\Entity\\UserAvatarPhoto u')->execute(); - - $user = new User(); - // check that the constructor was instantiated properly - $this->assertInstanceOf(ArrayCollection::class, $user->getUserAvatarPhotos()); - // set existing field - $user->setFirstName('Ryan'); - $em->persist($user); - - $photo = new UserAvatarPhoto(); - $photo->setUser($user); - $em->persist($photo); - - // set via the inverse side - $photo2 = new UserAvatarPhoto(); - $user->addUserAvatarPhoto($photo2); - $em->persist($photo2); - - $em->flush(); - $em->refresh($user); - - $actualUser = $em->getRepository(User::class) - ->findAll(); - - $this->assertcount(1, $actualUser); - $this->assertCount(2, $actualUser[0]->getUserAvatarPhotos()); - } -} diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityManyToOneNoInverse/src/Entity/User.php b/tests/fixtures/legacy/MakeEntity/MakeEntityManyToOneNoInverse/src/Entity/User.php deleted file mode 100644 index 773668263..000000000 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityManyToOneNoInverse/src/Entity/User.php +++ /dev/null @@ -1,23 +0,0 @@ -id; - } -} diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityManyToOneNoInverse/tests/GeneratedEntityTest.php b/tests/fixtures/legacy/MakeEntity/MakeEntityManyToOneNoInverse/tests/GeneratedEntityTest.php deleted file mode 100644 index af5e1f900..000000000 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityManyToOneNoInverse/tests/GeneratedEntityTest.php +++ /dev/null @@ -1,35 +0,0 @@ -getContainer() - ->get('doctrine') - ->getManager(); - - $em->createQuery('DELETE FROM App\\Entity\\User u')->execute(); - $em->createQuery('DELETE FROM App\\Entity\\UserAvatarPhoto u')->execute(); - - $user = new User(); - $em->persist($user); - - $photo = new UserAvatarPhoto(); - $photo->setUser($user); - $em->persist($photo); - - $em->flush(); - $em->refresh($photo); - - $this->assertSame($photo->getUser(), $user); - } -} diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityOneToMany/tests/GeneratedEntityTest.php b/tests/fixtures/legacy/MakeEntity/MakeEntityOneToMany/tests/GeneratedEntityTest.php deleted file mode 100644 index 80211a65f..000000000 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityOneToMany/tests/GeneratedEntityTest.php +++ /dev/null @@ -1,64 +0,0 @@ -getContainer() - ->get('doctrine') - ->getManager(); - - $em->createQuery('DELETE FROM App\\Entity\\User u')->execute(); - $em->createQuery('DELETE FROM App\\Entity\\UserAvatarPhoto u')->execute(); - - $user = new User(); - // check that the constructor was instantiated properly - $this->assertInstanceOf(ArrayCollection::class, $user->getPhotos()); - $em->persist($user); - - $photo = new UserAvatarPhoto(); - $photo->setUser($user); - $em->persist($photo); - - // set via the inverse side - $photo2 = new UserAvatarPhoto(); - $user->addPhoto($photo2); - $em->persist($photo2); - - $photo3 = new UserAvatarPhoto(); - $user->addPhoto($photo3); - $em->persist($photo3); - - $em->flush(); - $em->refresh($user); - - $actualUser = $em->getRepository(User::class) - ->findAll(); - - $this->assertcount(1, $actualUser); - $this->assertCount(3, $actualUser[0]->getPhotos()); - - // remove some photos! - $user->removePhoto($photo3); - $em->flush(); - $em->refresh($user); - - $actualUser = $em->getRepository(User::class) - ->findAll(); - $this->assertCount(2, $actualUser[0]->getPhotos()); - $allUserPhotos = $em->getRepository(UserAvatarPhoto::class) - ->findAll(); - // thanks to orphanRemoval, photo3 should be fully deleted - $this->assertCount(2, $allUserPhotos); - } -} diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityOneToOne/src/Entity/User.php b/tests/fixtures/legacy/MakeEntity/MakeEntityOneToOne/src/Entity/User.php deleted file mode 100644 index e64f975d9..000000000 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityOneToOne/src/Entity/User.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/legacy/MakeEntity/MakeEntityOneToOne/tests/GeneratedEntityTest.php b/tests/fixtures/legacy/MakeEntity/MakeEntityOneToOne/tests/GeneratedEntityTest.php deleted file mode 100644 index 6f544e1bb..000000000 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityOneToOne/tests/GeneratedEntityTest.php +++ /dev/null @@ -1,47 +0,0 @@ -getContainer() - ->get('doctrine') - ->getManager(); - - $em->createQuery('DELETE FROM App\\Entity\\User u')->execute(); - $em->createQuery('DELETE FROM App\\Entity\\UserProfile u')->execute(); - - $user = new User(); - // set existing field - $user->setFirstName('Ryan'); - $em->persist($user); - - $profile = new UserProfile(); - // set inverse side - will set owning - $user->setUserProfile($profile); - // purposely don't persist: cascade should be set - // $em->persist($profile); - - $em->flush(); - $em->refresh($user); - $em->refresh($profile); - - $this->assertSame($profile, $user->getUserProfile()); - $this->assertSame($user, $profile->getUser()); - - $em->remove($user); - // don't remove the profile, rely on cascade - $em->flush(); - - $this->assertEmpty($em->getRepository(UserProfile::class)->findAll()); - } -} diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityOverwrite/tests/GeneratedEntityTest.php b/tests/fixtures/legacy/MakeEntity/MakeEntityOverwrite/tests/GeneratedEntityTest.php deleted file mode 100644 index 8873b3a8f..000000000 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityOverwrite/tests/GeneratedEntityTest.php +++ /dev/null @@ -1,17 +0,0 @@ -setFirstName('Ryan'); - $this->assertSame('Ryan', $user->getFirstName()); - } -} diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityRegenerate/tests/GeneratedEntityTest.php b/tests/fixtures/legacy/MakeEntity/MakeEntityRegenerate/tests/GeneratedEntityTest.php deleted file mode 100644 index 2d0969990..000000000 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityRegenerate/tests/GeneratedEntityTest.php +++ /dev/null @@ -1,50 +0,0 @@ -getContainer() - ->get('doctrine') - ->getManager(); - - $em->createQuery('DELETE FROM App\\Entity\\User u')->execute(); - $em->createQuery('DELETE FROM App\\Entity\\UserAvatar u')->execute(); - - $user = new User(); - // check that the constructor was instantiated properly - $this->assertInstanceOf(ArrayCollection::class, $user->getAvatars()); - // fields should now have setters - $user->setFirstName('Ryan'); - $user->setCreatedAt(new \DateTime()); - $em->persist($user); - - $photo = new UserAvatar(); - $photo->setUser($user); - $em->persist($photo); - - // set via the inverse side - $photo2 = new UserAvatar(); - $user->addAvatar($photo2); - $em->persist($photo2); - - $em->flush(); - $em->refresh($user); - - $actualUser = $em->getRepository(User::class) - ->findAll(); - - $this->assertcount(1, $actualUser); - $this->assertCount(2, $actualUser[0]->getAvatars()); - } -} diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateEmbedable/tests/GeneratedEntityTest.php b/tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateEmbedable/tests/GeneratedEntityTest.php deleted file mode 100644 index 66d37545e..000000000 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateEmbedable/tests/GeneratedEntityTest.php +++ /dev/null @@ -1,51 +0,0 @@ -getContainer() - ->get('doctrine') - ->getManager(); - - $em->createQuery('DELETE FROM App\\Entity\\Food f')->execute(); - - $food = new Food(); - // check that the constructor was instantiated properly - $this->assertInstanceOf(Recipe::class, $food->getRecipe()); - // fields should now have setters - $food->setTitle('Borscht'); - - $recipe = new Recipe(); - $recipe->setIngredients('ingridients'); - $recipe->setSteps('steps'); - $food->setRecipe($recipe); - - $em->persist($food); - - $em->flush(); - $em->refresh($food); - - /** @var Food[] $actualFood */ - $actualFood = $em->getRepository(Food::class) - ->findAll(); - - $this->assertcount(1, $actualFood); - - /** @var Recipe $actualRecipe */ - $actualRecipe = $actualFood[0]->getRecipe(); - - $this->assertInstanceOf(Recipe::class, $actualRecipe); - $this->assertEquals('ingridients', $actualRecipe->getIngredients()); - $this->assertEquals('steps', $actualRecipe->getSteps()); - } -} diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateEmbeddableObject/tests/GeneratedEntityTest.php b/tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateEmbeddableObject/tests/GeneratedEntityTest.php deleted file mode 100644 index eb6790735..000000000 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateEmbeddableObject/tests/GeneratedEntityTest.php +++ /dev/null @@ -1,48 +0,0 @@ -getContainer() - ->get('doctrine') - ->getManager(); - - $em->createQuery('DELETE FROM App\\Entity\\Invoice i')->execute(); - - $invoice = new Invoice(); - // check that the constructor was instantiated properly - $this->assertInstanceOf(Money::class, $invoice->getTotal()); - // fields should now have setters - $invoice->setTitle('Borscht'); - - $total = new Money(100, new Currency('EUR')); - $invoice->setTotal($total); - - $em->persist($invoice); - - $em->flush(); - $em->refresh($invoice); - - /** @var Invoice[] $actualInvoice */ - $actualInvoice = $em->getRepository(Invoice::class) - ->findAll(); - - $this->assertcount(1, $actualInvoice); - - /** @var Money $actualTotal */ - $actualTotal = $actualInvoice[0]->getTotal(); - - $this->assertInstanceOf(Money::class, $actualTotal); - } -} diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateOverwrite/tests/GeneratedEntityTest.php b/tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateOverwrite/tests/GeneratedEntityTest.php deleted file mode 100644 index 8873b3a8f..000000000 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateOverwrite/tests/GeneratedEntityTest.php +++ /dev/null @@ -1,17 +0,0 @@ -setFirstName('Ryan'); - $this->assertSame('Ryan', $user->getFirstName()); - } -} diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityRelationVendorTarget/src/Entity/User.php b/tests/fixtures/legacy/MakeEntity/MakeEntityRelationVendorTarget/src/Entity/User.php deleted file mode 100644 index 773668263..000000000 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityRelationVendorTarget/src/Entity/User.php +++ /dev/null @@ -1,23 +0,0 @@ -id; - } -} diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityRelationVendorTarget/vendor/some-vendor/src/Group.php b/tests/fixtures/legacy/MakeEntity/MakeEntityRelationVendorTarget/vendor/some-vendor/src/Group.php deleted file mode 100644 index f38678a23..000000000 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityRelationVendorTarget/vendor/some-vendor/src/Group.php +++ /dev/null @@ -1,8 +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/legacy/MakeEntity/MakeEntitySelfReferencing/tests/GeneratedEntityTest.php b/tests/fixtures/legacy/MakeEntity/MakeEntitySelfReferencing/tests/GeneratedEntityTest.php deleted file mode 100644 index 096be0c5f..000000000 --- a/tests/fixtures/legacy/MakeEntity/MakeEntitySelfReferencing/tests/GeneratedEntityTest.php +++ /dev/null @@ -1,49 +0,0 @@ -getContainer() - ->get('doctrine') - ->getManager(); - - $em->createQuery('DELETE FROM App\\Entity\\User u')->execute(); - - $user = new User(); - // check that the constructor was instantiated properly - $this->assertInstanceOf(ArrayCollection::class, $user->getDependants()); - // set existing field - $user->setFirstName('Ryan'); - $em->persist($user); - - $ward = new User(); - $ward->setFirstName('Tim'); - $ward->setGuardian($user); - $em->persist($ward); - - // set via the inverse side - $ward2 = new User(); - $ward2->setFirstName('Fabien'); - $user->addDependant($ward2); - $em->persist($ward2); - - $em->flush(); - $em->refresh($user); - - $actualUser = $em->getRepository(User::class) - ->findAll(); - - $this->assertCount(3, $actualUser); - $this->assertCount(2, $actualUser[0]->getDependants()); - } -} diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntitySubNamespaceMatchingEntity/src/Entity/Product.php b/tests/fixtures/legacy/MakeEntity/MakeEntitySubNamespaceMatchingEntity/src/Entity/Product.php deleted file mode 100644 index a0a4102d0..000000000 --- a/tests/fixtures/legacy/MakeEntity/MakeEntitySubNamespaceMatchingEntity/src/Entity/Product.php +++ /dev/null @@ -1,18 +0,0 @@ -getContainer() - ->get('doctrine') - ->getManager(); - - $em->createQuery('DELETE FROM App\\Entity\\Product\\Category c') - ->execute(); - - $category = new Category(); - $em->persist($category); - $em->flush(); - $em->refresh($category); - - $actualCategories = $em->getRepository(Category::class) - ->findAll(); - - $this->assertcount(1, $actualCategories); - } -} diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityUpdate/tests/GeneratedEntityTest.php b/tests/fixtures/legacy/MakeEntity/MakeEntityUpdate/tests/GeneratedEntityTest.php deleted file mode 100644 index a3db17da7..000000000 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityUpdate/tests/GeneratedEntityTest.php +++ /dev/null @@ -1,38 +0,0 @@ -getContainer() - ->get('doctrine') - ->getManager(); - - $em->createQuery('DELETE FROM App\\Entity\\User f') - ->execute(); - - $food = new User(); - // set existing field - $food->setFirstName('Mr. Chocolate'); - // set the new, generated field - $food->setLastName('Cake'); - $em->persist($food); - $em->flush(); - - $actualFood = $em->getRepository(User::class) - ->findAll(); - - $this->assertcount(1, $actualFood); - } -} diff --git a/tests/fixtures/make-auth/BlankAuthenticator.php b/tests/fixtures/make-auth/BlankAuthenticator.php new file mode 100644 index 000000000..db97059fb --- /dev/null +++ b/tests/fixtures/make-auth/BlankAuthenticator.php @@ -0,0 +1,30 @@ +getConstructor()->getParameters(); - $this->assertSame('entityManager', $constructorParameters[0]->getName()); - - // assert authenticator is injected - $this->assertCount(4, $constructorParameters); - $client = self::createClient(); $crawler = $client->request('GET', '/login'); $this->assertEquals(200, $client->getResponse()->getStatusCode()); + {% if isEntity %} /** @var EntityManagerInterface $em */ $em = self::$kernel->getContainer() ->get('doctrine') ->getManager(); - $user = (new User())->setUserEmail('test@symfony.com') - ->setPassword('password'); + $user = (new User())->set{{ userIdentifier|title }}('test@symfony.com') + ->setPassword('passw0rd'); $em->persist($user); $em->flush(); + {% endif %} $form = $crawler->filter('form')->form(); $form->setValues( [ - 'userEmail' => 'test@symfony.com', + '{{ userIdentifier }}' => 'test@symfony.com', 'password' => 'foo', ] ); @@ -54,24 +50,35 @@ public function testCommand() $form->setValues( [ - 'userEmail' => 'test@symfony.com', - 'password' => 'password', + '{{ userIdentifier }}' => 'test@symfony.com', + 'password' => 'passw0rd', ] ); $client->submit($form); $this->assertStringContainsString('TODO: provide a valid redirect', $client->getResponse()->getContent()); - $tokenStorage = static::$container->get('security.token_storage'); - - // Handle Session deprecations in Symfony 5.3+ - if (Kernel::VERSION_ID >= 50300) { - $tokenStorage->disableUsageTracking(); - } - - $token = $tokenStorage->getToken(); - + $token = $this->getToken(); self::assertNotNull($token); $this->assertInstanceOf(User::class, $token->getUser()); + + {% if testLogin %} + $client->request('GET', '/logout'); + $this->assertNull($this->getToken()); + {% endif %} } + + /** + * Handle Session deprecations in Symfony 5.3+ + */ + private function getToken(): ?TokenInterface + { + $tokenStorage = static::{{ useLegacyContainerProperty ? '$container' : 'getContainer()' }}->get('security.token_storage'); + + if (Kernel::VERSION_ID >= 50300) { + $tokenStorage->disableUsageTracking(); + } + + return $tokenStorage->getToken(); + } } diff --git a/tests/fixtures/MakeAuthenticatorLoginFormExistingController/src/Controller/SecurityController.php b/tests/fixtures/make-auth/SecurityController-empty.php similarity index 100% rename from tests/fixtures/MakeAuthenticatorLoginFormExistingController/src/Controller/SecurityController.php rename to tests/fixtures/make-auth/SecurityController-empty.php diff --git a/tests/fixtures/make-auth/UserProvider-no-entity.php b/tests/fixtures/make-auth/UserProvider-no-entity.php new file mode 100644 index 000000000..80f4bab66 --- /dev/null +++ b/tests/fixtures/make-auth/UserProvider-no-entity.php @@ -0,0 +1,40 @@ +passwordHasher = $passwordHasher; + } + + public function loadUserByUsername($username): UserInterface + { + return $this->loadUserByIdentifier($username); + } + + public function loadUserByIdentifier(string $identifier): UserInterface + { + $user = (new User()) + ->setUserEmail($identifier); + + $user->setPassword($this->passwordHasher->hashPassword($user, 'passw0rd')); + + return $user; + } + + public function refreshUser(UserInterface $user): UserInterface + { + } + + public function supportsClass(string $class): UserInterface + { + } +} diff --git a/tests/fixtures/MakeCommand/tests/GeneratedCommandTest.php b/tests/fixtures/make-command/tests/it_makes_a_command.php similarity index 100% rename from tests/fixtures/MakeCommand/tests/GeneratedCommandTest.php rename to tests/fixtures/make-command/tests/it_makes_a_command.php diff --git a/tests/fixtures/MakeCommandInCustomRootNamespace/tests/GeneratedCommandTest.php b/tests/fixtures/make-command/tests/it_makes_a_command_in_custom_namespace.php similarity index 100% rename from tests/fixtures/MakeCommandInCustomRootNamespace/tests/GeneratedCommandTest.php rename to tests/fixtures/make-command/tests/it_makes_a_command_in_custom_namespace.php diff --git a/tests/fixtures/MakeController/tests/GeneratedControllerTest.php b/tests/fixtures/make-controller/tests/it_generates_a_controller.php similarity index 100% rename from tests/fixtures/MakeController/tests/GeneratedControllerTest.php rename to tests/fixtures/make-controller/tests/it_generates_a_controller.php diff --git a/tests/fixtures/MakeControllerTwig/tests/GeneratedControllerWithTwigTest.php b/tests/fixtures/make-controller/tests/it_generates_a_controller_with_twig.php similarity index 89% rename from tests/fixtures/MakeControllerTwig/tests/GeneratedControllerWithTwigTest.php rename to tests/fixtures/make-controller/tests/it_generates_a_controller_with_twig.php index c1cd3f34d..c21887ea1 100644 --- a/tests/fixtures/MakeControllerTwig/tests/GeneratedControllerWithTwigTest.php +++ b/tests/fixtures/make-controller/tests/it_generates_a_controller_with_twig.php @@ -4,7 +4,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; -class GeneratedControllerWithTwigTest extends WebTestCase +class GeneratedControllerTest extends WebTestCase { public function testController() { diff --git a/tests/fixtures/MakeCrudInCustomRootNamespace/src/Entity/SweetFood.php b/tests/fixtures/make-crud/SweetFood-custom-namespace.php similarity index 100% rename from tests/fixtures/MakeCrudInCustomRootNamespace/src/Entity/SweetFood.php rename to tests/fixtures/make-crud/SweetFood-custom-namespace.php diff --git a/tests/fixtures/MakeCrud/src/Entity/SweetFood.php b/tests/fixtures/make-crud/SweetFood.php similarity index 100% rename from tests/fixtures/MakeCrud/src/Entity/SweetFood.php rename to tests/fixtures/make-crud/SweetFood.php diff --git a/tests/fixtures/MakeCrudRepository/src/Repository/SweetFoodRepository.php b/tests/fixtures/make-crud/SweetFoodRepository.php similarity index 100% rename from tests/fixtures/MakeCrudRepository/src/Repository/SweetFoodRepository.php rename to tests/fixtures/make-crud/SweetFoodRepository.php diff --git a/tests/fixtures/MakeCrud/tests/GeneratedCrudControllerTest.php b/tests/fixtures/make-crud/tests/it_generates_basic_crud.php similarity index 100% rename from tests/fixtures/MakeCrud/tests/GeneratedCrudControllerTest.php rename to tests/fixtures/make-crud/tests/it_generates_basic_crud.php diff --git a/tests/fixtures/MakeCrudCustomController/tests/GeneratedCrudControllerTest.php b/tests/fixtures/make-crud/tests/it_generates_crud_with_custom_controller.php similarity index 100% rename from tests/fixtures/MakeCrudCustomController/tests/GeneratedCrudControllerTest.php rename to tests/fixtures/make-crud/tests/it_generates_crud_with_custom_controller.php diff --git a/tests/fixtures/MakeCrudInCustomRootNamespace/tests/GeneratedCrudControllerTest.php b/tests/fixtures/make-crud/tests/it_generates_crud_with_custom_root_namespace.php similarity index 100% rename from tests/fixtures/MakeCrudInCustomRootNamespace/tests/GeneratedCrudControllerTest.php rename to tests/fixtures/make-crud/tests/it_generates_crud_with_custom_root_namespace.php diff --git a/tests/fixtures/MakeEntity/tests/GeneratedEntityTest.php b/tests/fixtures/make-entity/GeneratedEntityTest.php.twig similarity index 86% rename from tests/fixtures/MakeEntity/tests/GeneratedEntityTest.php rename to tests/fixtures/make-entity/GeneratedEntityTest.php.twig index 50922ddaa..5ec79071b 100644 --- a/tests/fixtures/MakeEntity/tests/GeneratedEntityTest.php +++ b/tests/fixtures/make-entity/GeneratedEntityTest.php.twig @@ -10,9 +10,6 @@ class GeneratedEntityTest extends KernelTestCase { public function testGeneratedEntity() { - // load up the database - // create an entity, persist & query - self::bootKernel(); /** @var EntityManager $em */ $em = self::$kernel->getContainer() @@ -23,9 +20,11 @@ public function testGeneratedEntity() ->execute(); $user = new User(); + {% for field, value in data %} + $user->set{{ field|title }}('{{ value }}'); + {% endfor %} $em->persist($user); $em->flush(); - $em->refresh($user); $actualUser = $em->getRepository(User::class) ->findAll(); diff --git a/tests/fixtures/MakeEntityRelationVendorTarget/vendor/some-vendor/src/Group.php b/tests/fixtures/make-entity/Group-vendor.php similarity index 100% rename from tests/fixtures/MakeEntityRelationVendorTarget/vendor/some-vendor/src/Group.php rename to tests/fixtures/make-entity/Group-vendor.php diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityUpdate/src/Entity/User.php b/tests/fixtures/make-entity/entities/annotations/User-basic.php similarity index 97% rename from tests/fixtures/legacy/MakeEntity/MakeEntityUpdate/src/Entity/User.php rename to tests/fixtures/make-entity/entities/annotations/User-basic.php index 7c37adc2d..ab0180a14 100644 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityUpdate/src/Entity/User.php +++ b/tests/fixtures/make-entity/entities/annotations/User-basic.php @@ -5,7 +5,7 @@ use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity() + * @ORM\Entity */ class User { diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityManyToManyInCustomNamespace/src/Entity/User.php b/tests/fixtures/make-entity/entities/annotations/User-custom-namespace.php similarity index 98% rename from tests/fixtures/legacy/MakeEntity/MakeEntityManyToManyInCustomNamespace/src/Entity/User.php rename to tests/fixtures/make-entity/entities/annotations/User-custom-namespace.php index 2d7d1b375..754d4f658 100644 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityManyToManyInCustomNamespace/src/Entity/User.php +++ b/tests/fixtures/make-entity/entities/annotations/User-custom-namespace.php @@ -5,7 +5,7 @@ use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity() + * @ORM\Entity */ class User { diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityOverwrite/src/Entity/User.php b/tests/fixtures/make-entity/entities/annotations/User-invalid-method-no-property.php similarity index 95% rename from tests/fixtures/legacy/MakeEntity/MakeEntityOverwrite/src/Entity/User.php rename to tests/fixtures/make-entity/entities/annotations/User-invalid-method-no-property.php index e3f800e07..fda6e89ce 100644 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityOverwrite/src/Entity/User.php +++ b/tests/fixtures/make-entity/entities/annotations/User-invalid-method-no-property.php @@ -5,7 +5,7 @@ use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity() + * @ORM\Entity */ class User { diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateOverwrite/src/Entity/User.php b/tests/fixtures/make-entity/entities/annotations/User-invalid-method.php similarity index 96% rename from tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateOverwrite/src/Entity/User.php rename to tests/fixtures/make-entity/entities/annotations/User-invalid-method.php index 0e8eb71cb..27599b8e1 100644 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateOverwrite/src/Entity/User.php +++ b/tests/fixtures/make-entity/entities/annotations/User-invalid-method.php @@ -5,7 +5,7 @@ use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity() + * @ORM\Entity */ class User { diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityOneToMany/src/Entity/UserAvatarPhoto.php b/tests/fixtures/make-entity/entities/annotations/UserAvatarPhoto-basic.php similarity index 94% rename from tests/fixtures/legacy/MakeEntity/MakeEntityOneToMany/src/Entity/UserAvatarPhoto.php rename to tests/fixtures/make-entity/entities/annotations/UserAvatarPhoto-basic.php index 777b486ec..9d162f108 100644 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityOneToMany/src/Entity/UserAvatarPhoto.php +++ b/tests/fixtures/make-entity/entities/annotations/UserAvatarPhoto-basic.php @@ -5,7 +5,7 @@ use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity() + * @ORM\Entity */ class UserAvatarPhoto { diff --git a/tests/fixtures/MakeEntityUpdate/src/Entity/User.php b/tests/fixtures/make-entity/entities/attributes/User-basic.php similarity index 100% rename from tests/fixtures/MakeEntityUpdate/src/Entity/User.php rename to tests/fixtures/make-entity/entities/attributes/User-basic.php diff --git a/tests/fixtures/MakeEntityManyToManyInCustomNamespace/src/Entity/User.php b/tests/fixtures/make-entity/entities/attributes/User-custom-namespace.php similarity index 100% rename from tests/fixtures/MakeEntityManyToManyInCustomNamespace/src/Entity/User.php rename to tests/fixtures/make-entity/entities/attributes/User-custom-namespace.php diff --git a/tests/fixtures/MakeEntityOverwrite/src/Entity/User.php b/tests/fixtures/make-entity/entities/attributes/User-invalid-method-no-property.php similarity index 100% rename from tests/fixtures/MakeEntityOverwrite/src/Entity/User.php rename to tests/fixtures/make-entity/entities/attributes/User-invalid-method-no-property.php diff --git a/tests/fixtures/MakeEntityRegenerateOverwrite/src/Entity/User.php b/tests/fixtures/make-entity/entities/attributes/User-invalid-method.php similarity index 100% rename from tests/fixtures/MakeEntityRegenerateOverwrite/src/Entity/User.php rename to tests/fixtures/make-entity/entities/attributes/User-invalid-method.php diff --git a/tests/fixtures/MakeEntityOneToMany/src/Entity/UserAvatarPhoto.php b/tests/fixtures/make-entity/entities/attributes/UserAvatarPhoto-basic.php similarity index 100% rename from tests/fixtures/MakeEntityOneToMany/src/Entity/UserAvatarPhoto.php rename to tests/fixtures/make-entity/entities/attributes/UserAvatarPhoto-basic.php diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateEmbedable/src/Entity/Food.php b/tests/fixtures/make-entity/regenerate-embeddable/annotations/src/Entity/Food.php similarity index 64% rename from tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateEmbedable/src/Entity/Food.php rename to tests/fixtures/make-entity/regenerate-embeddable/annotations/src/Entity/Food.php index 92d199341..ec3528443 100644 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateEmbedable/src/Entity/Food.php +++ b/tests/fixtures/make-entity/regenerate-embeddable/annotations/src/Entity/Food.php @@ -10,14 +10,14 @@ class Food { /** - * @ORM\Column(name="id", type="integer") * @ORM\Id - * @ORM\GeneratedValue(strategy="AUTO") + * @ORM\GeneratedValue + * @ORM\Column(type="integer") */ private $id; /** - * @ORM\Column(name="title", type="string", length=255) + * @ORM\Column(type="string", length=255, nullable=true) */ private $title; diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateEmbedable/src/Entity/Recipe.php b/tests/fixtures/make-entity/regenerate-embeddable/annotations/src/Entity/Recipe.php similarity index 92% rename from tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateEmbedable/src/Entity/Recipe.php rename to tests/fixtures/make-entity/regenerate-embeddable/annotations/src/Entity/Recipe.php index 7516c9a1d..6af816f7f 100644 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateEmbedable/src/Entity/Recipe.php +++ b/tests/fixtures/make-entity/regenerate-embeddable/annotations/src/Entity/Recipe.php @@ -5,7 +5,7 @@ use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Embeddable() + * @ORM\Embeddable */ class Recipe { diff --git a/tests/fixtures/MakeEntityRegenerateEmbedable/src/Entity/Food.php b/tests/fixtures/make-entity/regenerate-embeddable/attributes/src/Entity/Food.php similarity index 81% rename from tests/fixtures/MakeEntityRegenerateEmbedable/src/Entity/Food.php rename to tests/fixtures/make-entity/regenerate-embeddable/attributes/src/Entity/Food.php index f47dc9b46..523d991fa 100644 --- a/tests/fixtures/MakeEntityRegenerateEmbedable/src/Entity/Food.php +++ b/tests/fixtures/make-entity/regenerate-embeddable/attributes/src/Entity/Food.php @@ -4,9 +4,6 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity() - */ #[ORM\Entity] class Food { @@ -18,9 +15,6 @@ class Food #[ORM\Column(name: 'title', type: 'string', length: 255)] private $title; - /** - * @ORM\Embedded(class=Recipe::class) - */ #[ORM\Embedded(class: Recipe::class)] private $recipe; } diff --git a/tests/fixtures/MakeEntityRegenerateEmbedable/src/Entity/Recipe.php b/tests/fixtures/make-entity/regenerate-embeddable/attributes/src/Entity/Recipe.php similarity index 100% rename from tests/fixtures/MakeEntityRegenerateEmbedable/src/Entity/Recipe.php rename to tests/fixtures/make-entity/regenerate-embeddable/attributes/src/Entity/Recipe.php diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateEmbeddableObject/src/Entity/Currency.php b/tests/fixtures/make-entity/regenerate-embedded/annotations/src/Entity/Currency.php similarity index 84% rename from tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateEmbeddableObject/src/Entity/Currency.php rename to tests/fixtures/make-entity/regenerate-embedded/annotations/src/Entity/Currency.php index b23d57c86..0638373d2 100644 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateEmbeddableObject/src/Entity/Currency.php +++ b/tests/fixtures/make-entity/regenerate-embedded/annotations/src/Entity/Currency.php @@ -5,14 +5,12 @@ use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Embeddable() + * @ORM\Embeddable */ class Currency { /** - * @var string - * - * @ORM\Column(name="currency", type="string") + * @ORM\Column(type="string", name="currency") */ private $currency; diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateEmbeddableObject/src/Entity/Invoice.php b/tests/fixtures/make-entity/regenerate-embedded/annotations/src/Entity/Invoice.php similarity index 60% rename from tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateEmbeddableObject/src/Entity/Invoice.php rename to tests/fixtures/make-entity/regenerate-embedded/annotations/src/Entity/Invoice.php index bce27420d..600307a78 100644 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateEmbeddableObject/src/Entity/Invoice.php +++ b/tests/fixtures/make-entity/regenerate-embedded/annotations/src/Entity/Invoice.php @@ -5,19 +5,19 @@ use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity() + * @ORM\Entity */ class Invoice { /** - * @ORM\Column(name="id", type="integer") * @ORM\Id - * @ORM\GeneratedValue(strategy="AUTO") + * @ORM\GeneratedValue + * @ORM\Column(type="integer") */ private $id; /** - * @ORM\Column(name="title", type="string", length=255) + * @ORM\Column(type="string", length=255, name="title") */ private $title; diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateEmbeddableObject/src/Entity/Money.php b/tests/fixtures/make-entity/regenerate-embedded/annotations/src/Entity/Money.php similarity index 89% rename from tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateEmbeddableObject/src/Entity/Money.php rename to tests/fixtures/make-entity/regenerate-embedded/annotations/src/Entity/Money.php index 484c9dd8d..932bfc54b 100644 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityRegenerateEmbeddableObject/src/Entity/Money.php +++ b/tests/fixtures/make-entity/regenerate-embedded/annotations/src/Entity/Money.php @@ -10,15 +10,11 @@ class Money { /** - * @var Currency - * * @ORM\Embedded(class=Currency::class) */ private $currency; /** - * @var int - * * @ORM\Column(name="amount", type="integer") */ private $amount; diff --git a/tests/fixtures/MakeEntityRegenerateEmbeddableObject/src/Entity/Currency.php b/tests/fixtures/make-entity/regenerate-embedded/attributes/src/Entity/Currency.php similarity index 100% rename from tests/fixtures/MakeEntityRegenerateEmbeddableObject/src/Entity/Currency.php rename to tests/fixtures/make-entity/regenerate-embedded/attributes/src/Entity/Currency.php diff --git a/tests/fixtures/MakeEntityRegenerateEmbeddableObject/src/Entity/Invoice.php b/tests/fixtures/make-entity/regenerate-embedded/attributes/src/Entity/Invoice.php similarity index 100% rename from tests/fixtures/MakeEntityRegenerateEmbeddableObject/src/Entity/Invoice.php rename to tests/fixtures/make-entity/regenerate-embedded/attributes/src/Entity/Invoice.php diff --git a/tests/fixtures/MakeEntityRegenerateEmbeddableObject/src/Entity/Money.php b/tests/fixtures/make-entity/regenerate-embedded/attributes/src/Entity/Money.php similarity index 100% rename from tests/fixtures/MakeEntityRegenerateEmbeddableObject/src/Entity/Money.php rename to tests/fixtures/make-entity/regenerate-embedded/attributes/src/Entity/Money.php diff --git a/tests/fixtures/MakeEntityRegenerateXml/config/doctrine/User.orm.xml b/tests/fixtures/make-entity/regenerate-xml/config/doctrine/User.orm.xml similarity index 100% rename from tests/fixtures/MakeEntityRegenerateXml/config/doctrine/User.orm.xml rename to tests/fixtures/make-entity/regenerate-xml/config/doctrine/User.orm.xml diff --git a/tests/fixtures/MakeEntityRegenerateXml/config/doctrine/UserAvatar.orm.xml b/tests/fixtures/make-entity/regenerate-xml/config/doctrine/UserAvatar.orm.xml similarity index 100% rename from tests/fixtures/MakeEntityRegenerateXml/config/doctrine/UserAvatar.orm.xml rename to tests/fixtures/make-entity/regenerate-xml/config/doctrine/UserAvatar.orm.xml diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityRegenerate/src/Entity/User.php b/tests/fixtures/make-entity/regenerate/annotations/src/Entity/User.php similarity index 97% rename from tests/fixtures/legacy/MakeEntity/MakeEntityRegenerate/src/Entity/User.php rename to tests/fixtures/make-entity/regenerate/annotations/src/Entity/User.php index c2023fb84..b2e420f2d 100644 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityRegenerate/src/Entity/User.php +++ b/tests/fixtures/make-entity/regenerate/annotations/src/Entity/User.php @@ -5,7 +5,7 @@ use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity() + * @ORM\Entity */ class User { diff --git a/tests/fixtures/legacy/MakeEntity/MakeEntityRegenerate/src/Entity/UserAvatar.php b/tests/fixtures/make-entity/regenerate/annotations/src/Entity/UserAvatar.php similarity index 96% rename from tests/fixtures/legacy/MakeEntity/MakeEntityRegenerate/src/Entity/UserAvatar.php rename to tests/fixtures/make-entity/regenerate/annotations/src/Entity/UserAvatar.php index a203156e9..a922a87ef 100644 --- a/tests/fixtures/legacy/MakeEntity/MakeEntityRegenerate/src/Entity/UserAvatar.php +++ b/tests/fixtures/make-entity/regenerate/annotations/src/Entity/UserAvatar.php @@ -5,7 +5,7 @@ use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity() + * @ORM\Entity */ class UserAvatar { diff --git a/tests/fixtures/MakeEntityRegenerate/src/Entity/User.php b/tests/fixtures/make-entity/regenerate/attributes/src/Entity/User.php similarity index 100% rename from tests/fixtures/MakeEntityRegenerate/src/Entity/User.php rename to tests/fixtures/make-entity/regenerate/attributes/src/Entity/User.php diff --git a/tests/fixtures/MakeEntityRegenerate/src/Entity/UserAvatar.php b/tests/fixtures/make-entity/regenerate/attributes/src/Entity/UserAvatar.php similarity index 100% rename from tests/fixtures/MakeEntityRegenerate/src/Entity/UserAvatar.php rename to tests/fixtures/make-entity/regenerate/attributes/src/Entity/UserAvatar.php diff --git a/tests/fixtures/MakeEntityManyToMany/tests/GeneratedEntityTest.php b/tests/fixtures/make-entity/tests/it_adds_many_to_many_simple.php similarity index 100% rename from tests/fixtures/MakeEntityManyToMany/tests/GeneratedEntityTest.php rename to tests/fixtures/make-entity/tests/it_adds_many_to_many_simple.php diff --git a/tests/fixtures/MakeEntityManyToManyInCustomNamespace/tests/GeneratedEntityTest.php b/tests/fixtures/make-entity/tests/it_adds_many_to_many_with_custom_root_namespace.php similarity index 100% rename from tests/fixtures/MakeEntityManyToManyInCustomNamespace/tests/GeneratedEntityTest.php rename to tests/fixtures/make-entity/tests/it_adds_many_to_many_with_custom_root_namespace.php diff --git a/tests/fixtures/MakeEntitySelfReferencing/tests/GeneratedEntityTest.php b/tests/fixtures/make-entity/tests/it_adds_many_to_one_self_referencing.php similarity index 100% rename from tests/fixtures/MakeEntitySelfReferencing/tests/GeneratedEntityTest.php rename to tests/fixtures/make-entity/tests/it_adds_many_to_one_self_referencing.php diff --git a/tests/fixtures/MakeEntityOneToMany/tests/GeneratedEntityTest.php b/tests/fixtures/make-entity/tests/it_adds_one_to_many_simple.php similarity index 100% rename from tests/fixtures/MakeEntityOneToMany/tests/GeneratedEntityTest.php rename to tests/fixtures/make-entity/tests/it_adds_one_to_many_simple.php diff --git a/tests/fixtures/MakeEntityOneToOne/tests/GeneratedEntityTest.php b/tests/fixtures/make-entity/tests/it_adds_one_to_one_simple.php similarity index 100% rename from tests/fixtures/MakeEntityOneToOne/tests/GeneratedEntityTest.php rename to tests/fixtures/make-entity/tests/it_adds_one_to_one_simple.php diff --git a/tests/fixtures/MakeEntitySubNamespaceMatchingEntity/tests/GeneratedEntityTest.php b/tests/fixtures/make-entity/tests/it_creates_class_that_matches_existing_namespace.php similarity index 86% rename from tests/fixtures/MakeEntitySubNamespaceMatchingEntity/tests/GeneratedEntityTest.php rename to tests/fixtures/make-entity/tests/it_creates_class_that_matches_existing_namespace.php index 38be62541..155690fb2 100644 --- a/tests/fixtures/MakeEntitySubNamespaceMatchingEntity/tests/GeneratedEntityTest.php +++ b/tests/fixtures/make-entity/tests/it_creates_class_that_matches_existing_namespace.php @@ -2,7 +2,7 @@ namespace App\Tests; -use App\Entity\Product\Category; +use App\Entity\User\Category; use Doctrine\ORM\EntityManager; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; @@ -16,7 +16,7 @@ public function testGeneratedEntity() ->get('doctrine') ->getManager(); - $em->createQuery('DELETE FROM App\\Entity\\Product\\Category c') + $em->createQuery('DELETE FROM App\\Entity\\User\\Category c') ->execute(); $category = new Category(); diff --git a/tests/fixtures/MakeEntityRegenerateEmbedable/tests/GeneratedEntityTest.php b/tests/fixtures/make-entity/tests/it_regenerates_embeddable_entity.php similarity index 100% rename from tests/fixtures/MakeEntityRegenerateEmbedable/tests/GeneratedEntityTest.php rename to tests/fixtures/make-entity/tests/it_regenerates_embeddable_entity.php diff --git a/tests/fixtures/MakeEntityRegenerateEmbeddableObject/tests/GeneratedEntityTest.php b/tests/fixtures/make-entity/tests/it_regenerates_embedded_entities.php similarity index 100% rename from tests/fixtures/MakeEntityRegenerateEmbeddableObject/tests/GeneratedEntityTest.php rename to tests/fixtures/make-entity/tests/it_regenerates_embedded_entities.php diff --git a/tests/fixtures/MakeEntityRegenerate/tests/GeneratedEntityTest.php b/tests/fixtures/make-entity/tests/it_regenerates_entities.php similarity index 100% rename from tests/fixtures/MakeEntityRegenerate/tests/GeneratedEntityTest.php rename to tests/fixtures/make-entity/tests/it_regenerates_entities.php diff --git a/tests/fixtures/MakeEntityRegenerateXml/tests/GeneratedEntityTest.php b/tests/fixtures/make-entity/tests/it_regenerates_from_xml.php similarity index 100% rename from tests/fixtures/MakeEntityRegenerateXml/tests/GeneratedEntityTest.php rename to tests/fixtures/make-entity/tests/it_regenerates_from_xml.php diff --git a/tests/fixtures/MakeEntityOverwrite/tests/GeneratedEntityTest.php b/tests/fixtures/make-entity/tests/it_regenerates_with_overwrite.php similarity index 100% rename from tests/fixtures/MakeEntityOverwrite/tests/GeneratedEntityTest.php rename to tests/fixtures/make-entity/tests/it_regenerates_with_overwrite.php diff --git a/tests/fixtures/MakeEntityManyToOneNoInverse/tests/GeneratedEntityTest.php b/tests/fixtures/make-entity/tests/it_updates_entity_many_to_one_no_inverse.php similarity index 100% rename from tests/fixtures/MakeEntityManyToOneNoInverse/tests/GeneratedEntityTest.php rename to tests/fixtures/make-entity/tests/it_updates_entity_many_to_one_no_inverse.php diff --git a/tests/fixtures/MakeEntityXmlMappingError/config/doctrine/User.orm.xml b/tests/fixtures/make-entity/xml-mapping/config/doctrine/User.orm.xml similarity index 100% rename from tests/fixtures/MakeEntityXmlMappingError/config/doctrine/User.orm.xml rename to tests/fixtures/make-entity/xml-mapping/config/doctrine/User.orm.xml diff --git a/tests/fixtures/MakeFormForEntity/src/Entity/Property.php b/tests/fixtures/make-form/Property.php similarity index 100% rename from tests/fixtures/MakeFormForEntity/src/Entity/Property.php rename to tests/fixtures/make-form/Property.php diff --git a/tests/fixtures/MakeFormForEntity/src/Entity/SourFood.php b/tests/fixtures/make-form/SourFood.php similarity index 100% rename from tests/fixtures/MakeFormForEntity/src/Entity/SourFood.php rename to tests/fixtures/make-form/SourFood.php diff --git a/tests/fixtures/MakeFormForNonEntityDto/src/Form/Data/TaskData.php b/tests/fixtures/make-form/TaskData.php similarity index 100% rename from tests/fixtures/MakeFormForNonEntityDto/src/Form/Data/TaskData.php rename to tests/fixtures/make-form/TaskData.php diff --git a/tests/fixtures/MakeFormEmbedableEntity/src/Entity/Food.php b/tests/fixtures/make-form/embeddable/Food.php similarity index 72% rename from tests/fixtures/MakeFormEmbedableEntity/src/Entity/Food.php rename to tests/fixtures/make-form/embeddable/Food.php index 8b4667dac..fd79b596f 100644 --- a/tests/fixtures/MakeFormEmbedableEntity/src/Entity/Food.php +++ b/tests/fixtures/make-form/embeddable/Food.php @@ -22,13 +22,13 @@ class Food private $title; /** - * @ORM\Embedded(class=Recept::class) + * @ORM\Embedded(class=Receipt::class) */ - private $recept; + private $receipt; public function __construct() { - $this->recept = new Recept(); + $this->receipt = new Receipt(); } /** @@ -56,18 +56,18 @@ public function setTitle($title) } /** - * @return Recept + * @return Receipt */ - public function getRecept() + public function getReceipt() { - return $this->recept; + return $this->receipt; } /** - * @param Recept $recept + * @param Receipt $receipt */ - public function setRecept(Recept $recept) + public function setRecept(Receipt $receipt) { - $this->recept = $recept; + $this->receipt = $receipt; } } diff --git a/tests/fixtures/MakeFormEmbedableEntity/src/Entity/Recept.php b/tests/fixtures/make-form/embeddable/Receipt.php similarity index 95% rename from tests/fixtures/MakeFormEmbedableEntity/src/Entity/Recept.php rename to tests/fixtures/make-form/embeddable/Receipt.php index 559f9c5bd..6d6b2d61d 100644 --- a/tests/fixtures/MakeFormEmbedableEntity/src/Entity/Recept.php +++ b/tests/fixtures/make-form/embeddable/Receipt.php @@ -7,7 +7,7 @@ /** * @ORM\Embeddable() */ -class Recept +class Receipt { /** * @ORM\Column(type="string", length=255) diff --git a/tests/fixtures/MakeFormSTIEntity/src/Entity/Food.php b/tests/fixtures/make-form/inheritance/Food.php similarity index 100% rename from tests/fixtures/MakeFormSTIEntity/src/Entity/Food.php rename to tests/fixtures/make-form/inheritance/Food.php diff --git a/tests/fixtures/MakeFormSTIEntity/src/Entity/SourFood.php b/tests/fixtures/make-form/inheritance/SourFood.php similarity index 100% rename from tests/fixtures/MakeFormSTIEntity/src/Entity/SourFood.php rename to tests/fixtures/make-form/inheritance/SourFood.php diff --git a/tests/fixtures/MakeForm/tests/GeneratedFormTest.php b/tests/fixtures/make-form/tests/it_generates_basic_form.php similarity index 100% rename from tests/fixtures/MakeForm/tests/GeneratedFormTest.php rename to tests/fixtures/make-form/tests/it_generates_basic_form.php diff --git a/tests/fixtures/MakeFormEmbedableEntity/tests/GeneratedFormTest.php b/tests/fixtures/make-form/tests/it_generates_form_with_embeddable_entity.php similarity index 100% rename from tests/fixtures/MakeFormEmbedableEntity/tests/GeneratedFormTest.php rename to tests/fixtures/make-form/tests/it_generates_form_with_embeddable_entity.php diff --git a/tests/fixtures/MakeFormForEntity/tests/GeneratedFormTest.php b/tests/fixtures/make-form/tests/it_generates_form_with_entity.php similarity index 100% rename from tests/fixtures/MakeFormForEntity/tests/GeneratedFormTest.php rename to tests/fixtures/make-form/tests/it_generates_form_with_entity.php diff --git a/tests/fixtures/MakeFormForNonEntityDto/tests/GeneratedFormTest.php b/tests/fixtures/make-form/tests/it_generates_form_with_non_entity_dto.php similarity index 100% rename from tests/fixtures/MakeFormForNonEntityDto/tests/GeneratedFormTest.php rename to tests/fixtures/make-form/tests/it_generates_form_with_non_entity_dto.php diff --git a/tests/fixtures/MakeFormSTIEntity/tests/GeneratedFormTest.php b/tests/fixtures/make-form/tests/it_generates_form_with_single_table_inheritance_entity.php similarity index 100% rename from tests/fixtures/MakeFormSTIEntity/tests/GeneratedFormTest.php rename to tests/fixtures/make-form/tests/it_generates_form_with_single_table_inheritance_entity.php diff --git a/tests/fixtures/MakeFunctional/src/Controller/MainController.php b/tests/fixtures/make-functional/MainController.php similarity index 100% rename from tests/fixtures/MakeFunctional/src/Controller/MainController.php rename to tests/fixtures/make-functional/MainController.php diff --git a/tests/fixtures/MakeFunctional/config/routes.yaml b/tests/fixtures/make-functional/routes.yaml similarity index 100% rename from tests/fixtures/MakeFunctional/config/routes.yaml rename to tests/fixtures/make-functional/routes.yaml diff --git a/tests/fixtures/MakeMessageBasic/tests/GeneratedMessageHandlerTest.php b/tests/fixtures/make-message/tests/it_generates_basic_message.php similarity index 100% rename from tests/fixtures/MakeMessageBasic/tests/GeneratedMessageHandlerTest.php rename to tests/fixtures/make-message/tests/it_generates_basic_message.php diff --git a/tests/fixtures/MakeMessageWithTransport/tests/GeneratedMessageHandlerTest.php b/tests/fixtures/make-message/tests/it_generates_message_with_transport.php similarity index 100% rename from tests/fixtures/MakeMessageWithTransport/tests/GeneratedMessageHandlerTest.php rename to tests/fixtures/make-message/tests/it_generates_message_with_transport.php diff --git a/tests/fixtures/MakeMigration/src/Entity/SpicyFood.php b/tests/fixtures/make-migration/SpicyFood.php similarity index 100% rename from tests/fixtures/MakeMigration/src/Entity/SpicyFood.php rename to tests/fixtures/make-migration/SpicyFood.php diff --git a/tests/fixtures/MakeRegistrationFormEntity/config/routes.yaml b/tests/fixtures/make-registration-form/standard_setup/config/routes.yaml similarity index 100% rename from tests/fixtures/MakeRegistrationFormEntity/config/routes.yaml rename to tests/fixtures/make-registration-form/standard_setup/config/routes.yaml diff --git a/tests/fixtures/MakeRegistrationFormEntity/src/Controller/TestingController.php b/tests/fixtures/make-registration-form/standard_setup/src/Controller/TestingController.php similarity index 100% rename from tests/fixtures/MakeRegistrationFormEntity/src/Controller/TestingController.php rename to tests/fixtures/make-registration-form/standard_setup/src/Controller/TestingController.php diff --git a/tests/fixtures/MakeRegistrationFormEntity/src/Security/StubAuthenticator.php b/tests/fixtures/make-registration-form/standard_setup/src/Security/LegacyGuardStubAuthenticator.php similarity index 95% rename from tests/fixtures/MakeRegistrationFormEntity/src/Security/StubAuthenticator.php rename to tests/fixtures/make-registration-form/standard_setup/src/Security/LegacyGuardStubAuthenticator.php index 616e5b828..8c82a388f 100644 --- a/tests/fixtures/MakeRegistrationFormEntity/src/Security/StubAuthenticator.php +++ b/tests/fixtures/make-registration-form/standard_setup/src/Security/LegacyGuardStubAuthenticator.php @@ -11,7 +11,7 @@ use Symfony\Component\Security\Core\User\UserProviderInterface; use Symfony\Component\Security\Guard\AbstractGuardAuthenticator; -class StubAuthenticator extends AbstractGuardAuthenticator +class LegacyGuardStubAuthenticator extends AbstractGuardAuthenticator { private $router; diff --git a/tests/fixtures/make-registration-form/standard_setup/src/Security/StubAuthenticator.php b/tests/fixtures/make-registration-form/standard_setup/src/Security/StubAuthenticator.php new file mode 100644 index 000000000..61d22863a --- /dev/null +++ b/tests/fixtures/make-registration-form/standard_setup/src/Security/StubAuthenticator.php @@ -0,0 +1,40 @@ +router = $router; + } + + public function supports(Request $request): ?bool + { + return false; + } + + public function authenticate(Request $request): Passport + { + } + + public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response + { + } + + public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response + { + return new RedirectResponse($this->router->generate('app_homepage')); + } +} diff --git a/tests/fixtures/MakeRegistrationFormVerifyEmailFunctionalTest/tests/VerifyEmailTest.php b/tests/fixtures/make-registration-form/tests/it_generates_registration_form_with_verification.php similarity index 96% rename from tests/fixtures/MakeRegistrationFormVerifyEmailFunctionalTest/tests/VerifyEmailTest.php rename to tests/fixtures/make-registration-form/tests/it_generates_registration_form_with_verification.php index 8fc8fbf50..fc40efc17 100644 --- a/tests/fixtures/MakeRegistrationFormVerifyEmailFunctionalTest/tests/VerifyEmailTest.php +++ b/tests/fixtures/make-registration-form/tests/it_generates_registration_form_with_verification.php @@ -5,7 +5,7 @@ use Doctrine\ORM\EntityManager; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; -class VerifyEmailTest extends WebTestCase +class RegistrationFormTest extends WebTestCase { public function testRegistrationSuccessful() { diff --git a/tests/fixtures/MakeRegistrationFormEntity/tests/RegistrationFormTest.php b/tests/fixtures/make-registration-form/tests/it_generates_registration_with_entity_and_authenticator.php similarity index 91% rename from tests/fixtures/MakeRegistrationFormEntity/tests/RegistrationFormTest.php rename to tests/fixtures/make-registration-form/tests/it_generates_registration_with_entity_and_authenticator.php index c2132bfda..f87e1aaf5 100644 --- a/tests/fixtures/MakeRegistrationFormEntity/tests/RegistrationFormTest.php +++ b/tests/fixtures/make-registration-form/tests/it_generates_registration_with_entity_and_authenticator.php @@ -68,4 +68,10 @@ public function testRegistrationValidationError() $client->getResponse()->getContent() ); } + + public function testVerifiedPropertyNotAddedToUserEntity(): void + { + self::assertFalse(method_exists(User::class, 'isVerified')); + self::assertFalse(property_exists(User::class, 'verified')); + } } diff --git a/tests/fixtures/MakeResetPasswordFunctionalTest/tests/ResetPasswordFunctionalTest.php b/tests/fixtures/make-reset-password/tests/it_generates_with_normal_setup.php similarity index 100% rename from tests/fixtures/MakeResetPasswordFunctionalTest/tests/ResetPasswordFunctionalTest.php rename to tests/fixtures/make-reset-password/tests/it_generates_with_normal_setup.php diff --git a/tests/fixtures/make-test/basic_setup/config/routes.yaml b/tests/fixtures/make-test/basic_setup/config/routes.yaml new file mode 100644 index 000000000..6d1778eb9 --- /dev/null +++ b/tests/fixtures/make-test/basic_setup/config/routes.yaml @@ -0,0 +1,3 @@ +homepage: + path: / + controller: App\Controller\MainController::homepage diff --git a/tests/fixtures/make-test/basic_setup/src/Controller/MainController.php b/tests/fixtures/make-test/basic_setup/src/Controller/MainController.php new file mode 100644 index 000000000..97f9928eb --- /dev/null +++ b/tests/fixtures/make-test/basic_setup/src/Controller/MainController.php @@ -0,0 +1,14 @@ +

Hello World

'); + } +} diff --git a/tests/fixtures/MakeUserEntityPassword/config/routes.yaml b/tests/fixtures/make-user/standard_setup/config/routes.yaml similarity index 100% rename from tests/fixtures/MakeUserEntityPassword/config/routes.yaml rename to tests/fixtures/make-user/standard_setup/config/routes.yaml diff --git a/tests/fixtures/MakeUserModelNoPassword/src/Controller/TestingController.php b/tests/fixtures/make-user/standard_setup/src/Controller/TestingController.php similarity index 91% rename from tests/fixtures/MakeUserModelNoPassword/src/Controller/TestingController.php rename to tests/fixtures/make-user/standard_setup/src/Controller/TestingController.php index c26e99884..38969b042 100644 --- a/tests/fixtures/MakeUserModelNoPassword/src/Controller/TestingController.php +++ b/tests/fixtures/make-user/standard_setup/src/Controller/TestingController.php @@ -11,6 +11,6 @@ public function homepage() { $this->denyAccessUnlessGranted('ROLE_USER'); - return new Response('Homepage Success. Hello: '.$this->getUser()->getUsername()); + return new Response('Homepage Success. Hello: '.$this->getUser()->getUserIdentifier()); } } diff --git a/tests/fixtures/make-user/standard_setup/src/Security/AutomaticAuthenticator.php b/tests/fixtures/make-user/standard_setup/src/Security/AutomaticAuthenticator.php new file mode 100644 index 000000000..28df7e3e4 --- /dev/null +++ b/tests/fixtures/make-user/standard_setup/src/Security/AutomaticAuthenticator.php @@ -0,0 +1,54 @@ +router = $router; + } + + public function supports(Request $request): ?bool + { + return $request->query->has('email') || $request->query->has('username'); + } + + public function authenticate(Request $request): Passport + { + // works for both email or username to satisfy 2 different tests + $identifier = $request->query->get('email'); + if (!$identifier) { + $identifier = $request->query->get('username'); + } + + return new Passport( + new UserBadge($identifier), + new CustomCredentials(function() { + return true; + }, 'password') + ); + } + + public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response + { + return new RedirectResponse($this->router->generate('app_homepage')); + } + + public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response + { + } +} diff --git a/tests/fixtures/MakeUserEntityPassword/tests/GeneratedEntityTest.php b/tests/fixtures/make-user/tests/it_generates_entity_with_password.php similarity index 55% rename from tests/fixtures/MakeUserEntityPassword/tests/GeneratedEntityTest.php rename to tests/fixtures/make-user/tests/it_generates_entity_with_password.php index b254603d3..23f04ca81 100644 --- a/tests/fixtures/MakeUserEntityPassword/tests/GeneratedEntityTest.php +++ b/tests/fixtures/make-user/tests/it_generates_entity_with_password.php @@ -5,9 +5,11 @@ use App\Entity\User; use Doctrine\ORM\EntityManager; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; use Symfony\Component\Security\Core\Encoder\UserPasswordEncoder; +use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; -class GeneratedEntityTest extends WebTestCase +class GeneratedUserTest extends WebTestCase { public function testGeneratedEntity() { @@ -17,16 +19,20 @@ public function testGeneratedEntity() $em = self::$kernel->getContainer() ->get('doctrine') ->getManager(); - /** @var UserPasswordEncoder $encoder */ - $encoder = self::$kernel->getContainer() - ->get('security.password_encoder'); + /** @var UserPasswordHasherInterface $hasher */ + $hasher = self::$kernel->getContainer() + ->get('test_password_hasher'); $em->createQuery('DELETE FROM App\\Entity\\User u') ->execute(); $user = new User(); $user->setEmail('foo@example.com'); - $user->setPassword($encoder->encodePassword($user, 'pa$$')); + $user->setPassword($hasher->hashPassword($user, 'pa$$')); + + $reflectedUser = new \ReflectionClass(User::class); + self::assertTrue($reflectedUser->implementsInterface(PasswordAuthenticatedUserInterface::class)); + self::assertTrue($reflectedUser->hasMethod('getPassword')); $em->persist($user); $em->flush(); @@ -37,6 +43,6 @@ public function testGeneratedEntity() $this->assertSame(302, $client->getResponse()->getStatusCode()); $client->followRedirect(); $this->assertSame(200, $client->getResponse()->getStatusCode()); - $this->assertSame('Homepage Success', $client->getResponse()->getContent()); + $this->assertSame('Homepage Success. Hello: foo@example.com', $client->getResponse()->getContent()); } } diff --git a/tests/fixtures/MakeUserModelNoPassword/tests/GeneratedEntityTest.php b/tests/fixtures/make-user/tests/it_generates_non_entity_no_password.php similarity index 92% rename from tests/fixtures/MakeUserModelNoPassword/tests/GeneratedEntityTest.php rename to tests/fixtures/make-user/tests/it_generates_non_entity_no_password.php index 9fd8cb3b9..139965450 100644 --- a/tests/fixtures/MakeUserModelNoPassword/tests/GeneratedEntityTest.php +++ b/tests/fixtures/make-user/tests/it_generates_non_entity_no_password.php @@ -4,7 +4,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; -class GeneratedEntityTest extends WebTestCase +class GeneratedUserTest extends WebTestCase { public function testGeneratedEntity() {