diff --git a/public/index.php b/public/index.php index 9982c218d6969c72d4c91e3834e3f535e2dfe68b..7fbc8cf61a582e8856f76a2b26d816be8ab69897 100644 --- a/public/index.php +++ b/public/index.php @@ -2,7 +2,7 @@ use App\Kernel; -require_once dirname(__DIR__).'/vendor/autoload_runtime.php'; +require_once dirname(__DIR__) . '/vendor/autoload_runtime.php'; return function (array $context) { return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']); diff --git a/src/Controller/RegistrationController.php b/src/Controller/RegistrationController.php index 4c1b59ba3ae116c3ef2b72d8130d3d076c854334..02abd8981f63e58d7b4588ef5c5675c6d45725b5 100644 --- a/src/Controller/RegistrationController.php +++ b/src/Controller/RegistrationController.php @@ -20,10 +20,12 @@ use SymfonyCasts\Bundle\VerifyEmail\Exception\VerifyEmailExceptionInterface; class RegistrationController extends AbstractController { private EmailVerifier $emailVerifier; - private RequestStack $requestStack; + private RequestStack $requestStack; - public function __construct(EmailVerifier $emailVerifier, RequestStack $requestStack) - { + public function __construct( + EmailVerifier $emailVerifier, + RequestStack $requestStack + ) { $this->emailVerifier = $emailVerifier; $this->requestStack = $requestStack; } @@ -31,8 +33,11 @@ class RegistrationController extends AbstractController /** * @Route("/register", name="app_register") */ - public function register(Request $request, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager): Response - { + public function register( + Request $request, + UserPasswordHasherInterface $userPasswordHasher, + EntityManagerInterface $entityManager + ): Response { $user = new User(); $form = $this->createForm(RegistrationFormType::class, $user); $form->handleRequest($request); @@ -43,9 +48,9 @@ class RegistrationController extends AbstractController // encode the plain password $user->setPassword( $userPasswordHasher->hashPassword( - $user, - $form->get('plainPassword')->getData() - ) + $user, + $form->get('plainPassword')->getData() + ) ); $entityManager->persist($user); @@ -76,8 +81,10 @@ class RegistrationController extends AbstractController /** * @Route("/verify/email", name="app_verify_email") */ - public function verifyUserEmail(Request $request, UserRepository $userRepository): Response - { + public function verifyUserEmail( + Request $request, + UserRepository $userRepository + ): Response { $id = $request->get('id'); if (null === $id) { diff --git a/src/Controller/SecurityController.php b/src/Controller/SecurityController.php index 65c096f8f0eb7a9622e01a3eefa3f6a27ab05f42..01cab2a9cfc619ca628a04df682dd45bfdc297e8 100644 --- a/src/Controller/SecurityController.php +++ b/src/Controller/SecurityController.php @@ -31,6 +31,7 @@ class SecurityController extends AbstractController */ public function logout(): void { - throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.'); + throw new \LogicException('This method can be blank ' . + '- it will be intercepted by the logout key on your firewall.'); } } diff --git a/src/Form/RegistrationFormType.php b/src/Form/RegistrationFormType.php index df9227bd9e29728f90dfe4b2503e17148ce2991d..c66223fe2b5d4b05194b0deeaa3a6c7f9f9f21ec 100644 --- a/src/Form/RegistrationFormType.php +++ b/src/Form/RegistrationFormType.php @@ -61,7 +61,7 @@ class RegistrationFormType extends AbstractType 'firstName', TextType::class, ['constraints' => [new NotBlank(['message' => 'Please enter your first name'])], - ] + ] ) ->add( 'lastName', diff --git a/src/Kernel.php b/src/Kernel.php index 8e96873a2602425867e08b7c3602a0e5d2e5b2d3..cf4518d1a43ef295b08c49d1ebc8b1549b709f43 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -14,11 +14,11 @@ class Kernel extends BaseKernel protected function configureContainer(ContainerConfigurator $container): void { $container->import('../config/{packages}/*.yaml'); - $container->import('../config/{packages}/'.$this->environment.'/*.yaml'); + $container->import('../config/{packages}/' . $this->environment . '/*.yaml'); - if (is_file(\dirname(__DIR__).'/config/services.yaml')) { + if (is_file(\dirname(__DIR__) . '/config/services.yaml')) { $container->import('../config/services.yaml'); - $container->import('../config/{services}_'.$this->environment.'.yaml'); + $container->import('../config/{services}_' . $this->environment . '.yaml'); } else { $container->import('../config/{services}.php'); } @@ -26,10 +26,10 @@ class Kernel extends BaseKernel protected function configureRoutes(RoutingConfigurator $routes): void { - $routes->import('../config/{routes}/'.$this->environment.'/*.yaml'); + $routes->import('../config/{routes}/' . $this->environment . '/*.yaml'); $routes->import('../config/{routes}/*.yaml'); - if (is_file(\dirname(__DIR__).'/config/routes.yaml')) { + if (is_file(\dirname(__DIR__) . '/config/routes.yaml')) { $routes->import('../config/routes.yaml'); } else { $routes->import('../config/{routes}.php'); diff --git a/src/Security/AppCustomAuthenticator.php b/src/Security/AppCustomAuthenticator.php index 818ef11090da39b8c200e4707b749bd7238f124e..5d2f3059dcf588ec11a4dda65963b1f8a70744e1 100644 --- a/src/Security/AppCustomAuthenticator.php +++ b/src/Security/AppCustomAuthenticator.php @@ -52,7 +52,7 @@ class AppCustomAuthenticator extends AbstractLoginFormAuthenticator // For example: //return new RedirectResponse($this->urlGenerator->generate('some_route')); - throw new \Exception('TODO: provide a valid redirect inside '.__FILE__); + throw new \Exception('TODO: provide a valid redirect inside ' . __FILE__); } protected function getLoginUrl(Request $request): string diff --git a/src/Security/EmailVerifier.php b/src/Security/EmailVerifier.php index d5a75088f170b2a019aae5944fd62a40027c39ec..c23246ee4e79c36f16488ae19b69f9c8d35b8e01 100644 --- a/src/Security/EmailVerifier.php +++ b/src/Security/EmailVerifier.php @@ -16,15 +16,21 @@ class EmailVerifier private $mailer; private $entityManager; - public function __construct(VerifyEmailHelperInterface $helper, MailerInterface $mailer, EntityManagerInterface $manager) - { + public function __construct( + VerifyEmailHelperInterface $helper, + MailerInterface $mailer, + EntityManagerInterface $manager + ) { $this->verifyEmailHelper = $helper; $this->mailer = $mailer; $this->entityManager = $manager; } - public function sendEmailConfirmation(string $verifyEmailRouteName, UserInterface $user, TemplatedEmail $email): void - { + public function sendEmailConfirmation( + string $verifyEmailRouteName, + UserInterface $user, + TemplatedEmail $email + ): void { $signatureComponents = $this->verifyEmailHelper->generateSignature( $verifyEmailRouteName, $user->getId(), @@ -45,8 +51,10 @@ class EmailVerifier /** * @throws VerifyEmailExceptionInterface */ - public function handleEmailConfirmation(Request $request, UserInterface $user): void - { + public function handleEmailConfirmation( + Request $request, + UserInterface $user + ): void { $this->verifyEmailHelper->validateEmailConfirmation($request->getUri(), $user->getId(), $user->getEmail()); $user->setIsVerified(true); diff --git a/tests/Controller/RegistrationControllerTest.php b/tests/Controller/RegistrationControllerTest.php index 44c3a99e40677b7b091d02c37f20fc4aeb1fa2e8..1520b31104aa00bed2925e99b4f24973d0ce66ec 100644 --- a/tests/Controller/RegistrationControllerTest.php +++ b/tests/Controller/RegistrationControllerTest.php @@ -17,40 +17,56 @@ class RegistrationControllerTest extends WebTestCase $userEmail = 'newUser@localhost.com'; $client = static::createClient(); - $this->RegisterUser($userEmail, $client); + $this->registerUser($userEmail, $client); - $this->CheckUserRegistrationPostConditions($userEmail, $client); + $this->checkUserRegistrationPostConditions($userEmail, $client); } - public function testEmailValidationRegistrationShouldEnableUser(){ + public function testEmailValidationRegistrationShouldEnableUser() + { $userEmail = 'newUser@localhost.com'; $client = static::createClient(); - $this->RegisterUser($userEmail, $client); + $this->registerUser($userEmail, $client); - $this->CheckUserRegistrationPostConditions($userEmail, $client); + $this->checkUserRegistrationPostConditions($userEmail, $client); - $this->ClickOnMailValidationLink($client); + $this->clickOnMailValidationLink($client); - $this->CheckUserEmailValidationPostConditions($userEmail, $client); + $this->checkUserEmailValidationPostConditions($userEmail, $client); } /** * @param string $userEmail */ - private function CheckMailHasBeenSent(string $userEmail) : void + private function checkMailHasBeenSent(string $userEmail): void { - $this->assertEmailCount(1, null, 'Once the user has been registered, the system should sent a mail to this user'); + $this->assertEmailCount( + 1, + null, + 'Once the user has been registered, the system should sent a mail to this user' + ); $this->emailMessage = $this->getMailerMessage(0); - $this->assertEmailAddressContains($this->emailMessage, 'To', $userEmail, 'Once the user has been registered, the system should sent a mail to this user'); + $this->assertEmailAddressContains( + $this->emailMessage, + 'To', + $userEmail, + 'Once the user has been registered, the system should sent a mail to this user' + ); } /** * @param KernelBrowser $client */ - private function CheckUserHasMailNotification(KernelBrowser $client): void + private function checkUserHasMailNotification(KernelBrowser $client): void { - $this->assertResponseRedirects('/register_mail_sent', 302, 'Once the user has been registered, he should be redirected to a webpage noticing an email has been sent for account validation'); + $this->assertResponseRedirects( + '/register_mail_sent', + 302, + 'Once the user has been registered,' . + ' he should be redirected to a webpage noticing' . + ' an email has been sent for account validation' + ); $client->followRedirect(); $this->assertResponseIsSuccessful('/register_mail_sent'); } @@ -59,7 +75,7 @@ class RegistrationControllerTest extends WebTestCase * @param string $userEmail * @param $client */ - private function RegisterUser(string $userEmail, &$client): void + private function registerUser(string $userEmail, &$client): void { $crawler = $client->request('GET', '/register'); @@ -85,32 +101,36 @@ class RegistrationControllerTest extends WebTestCase { $userRepository = static::getContainer()->get(UserRepository::class); $user = $userRepository->findOneByEmail($userEmail); - $this->assertEquals($expectedValidation, $user->isVerified(), $message); + $this->assertEquals($expectedValidation, $user->isVerified(), $message); } /** * @param string $userEmail */ - private function CheckUseIsNotAbleToLogIn(string $userEmail): void + private function checkUseIsNotAbleToLogIn(string $userEmail): void { - $this->checkUserValidation($userEmail, false, 'The user should not be able to log in, until he validates his email.'); + $this->checkUserValidation( + $userEmail, + false, + 'The user should not be able to log in, until he validates his email.' + ); } /** * @param string $userEmail * @param KernelBrowser $client */ - private function CheckUserRegistrationPostConditions(string $userEmail, KernelBrowser $client): void + private function checkUserRegistrationPostConditions(string $userEmail, KernelBrowser $client): void { - $this->CheckUseIsNotAbleToLogIn($userEmail); - $this->CheckMailHasBeenSent($userEmail); - $this->CheckUserHasMailNotification($client); + $this->checkUseIsNotAbleToLogIn($userEmail); + $this->checkMailHasBeenSent($userEmail); + $this->checkUserHasMailNotification($client); } /** * @param KernelBrowser $client */ - private function ClickOnMailValidationLink(KernelBrowser $client): void + private function clickOnMailValidationLink(KernelBrowser $client): void { $crawler = new Crawler($this->emailMessage->getHtmlBody()); $crawlerLink = $crawler->selectLink('Confirm my Email')->link(); @@ -121,13 +141,21 @@ class RegistrationControllerTest extends WebTestCase * @param string $userEmail * @param KernelBrowser $client */ - private function CheckUserEmailValidationPostConditions(string $userEmail, KernelBrowser $client): void + private function checkUserEmailValidationPostConditions(string $userEmail, KernelBrowser $client): void { // Check the user has been redirected on login page - $this->assertResponseRedirects('/login', 302, 'Once the user email is validated, memorekall should redirect the user to the login page'); + $this->assertResponseRedirects( + '/login', + 302, + 'Once the user email is validated, memorekall should redirect the user to the login page' + ); // Check the user is now able to login - $this->checkUserValidation($userEmail, true, 'Once the user email is validated, he should be able to login'); + $this->checkUserValidation( + $userEmail, + true, + 'Once the user email is validated, he should be able to login' + ); // Chedk the redirection is succesfull $client->followRedirect(); diff --git a/tests/_support/AcceptanceTester.php b/tests/_support/AcceptanceTester.php index e0b036bc725fc3f6a9326da4b73d266c9f4559dd..322ea12605e9abd3036cd047a9baa99db5de9138 100644 --- a/tests/_support/AcceptanceTester.php +++ b/tests/_support/AcceptanceTester.php @@ -1,4 +1,5 @@ <?php + namespace App\Tests; /** diff --git a/tests/_support/FunctionalTester.php b/tests/_support/FunctionalTester.php index 48eaea9195a0c60796f066b1916f7795655f15fd..0846edd6a83f12c42e395624bc908d04c0359644 100644 --- a/tests/_support/FunctionalTester.php +++ b/tests/_support/FunctionalTester.php @@ -1,4 +1,5 @@ <?php + namespace App\Tests; /** diff --git a/tests/_support/Helper/Acceptance.php b/tests/_support/Helper/Acceptance.php index 429488fa1fcb39c6301feeafeda90e377f0408e4..ca88b8464c9c4119a0874319a45ad88303f3a830 100644 --- a/tests/_support/Helper/Acceptance.php +++ b/tests/_support/Helper/Acceptance.php @@ -1,4 +1,5 @@ <?php + namespace App\Tests\Helper; // here you can define custom actions diff --git a/tests/_support/Helper/Functional.php b/tests/_support/Helper/Functional.php index 4b6053224aac59e0327202795986f161816ad78c..df548c8838ea9b2b9f44997137ed01fa2332b688 100644 --- a/tests/_support/Helper/Functional.php +++ b/tests/_support/Helper/Functional.php @@ -1,4 +1,5 @@ <?php + namespace App\Tests\Helper; // here you can define custom actions diff --git a/tests/_support/Helper/Unit.php b/tests/_support/Helper/Unit.php index 2038c094cd12504b8bf7345f912e918d5d90843a..d00d8698b070e6ea4294dd8641df69ee789d808b 100644 --- a/tests/_support/Helper/Unit.php +++ b/tests/_support/Helper/Unit.php @@ -1,4 +1,5 @@ <?php + namespace App\Tests\Helper; // here you can define custom actions diff --git a/tests/_support/UnitTester.php b/tests/_support/UnitTester.php index 27870a8652eb09eec98ebaa728e9c0df1655d16d..936bc8cf124c56d5d736a9ac798edfc9d48eb72b 100644 --- a/tests/_support/UnitTester.php +++ b/tests/_support/UnitTester.php @@ -1,4 +1,5 @@ <?php + namespace App\Tests; /** diff --git a/tests/bootstrap.php b/tests/bootstrap.php index a7bcaf9b7971131156b99f5316905bc8b850b8e3..870c83955e902c46010b0d3e588a561eb9bb836c 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -2,10 +2,10 @@ use Symfony\Component\Dotenv\Dotenv; -require dirname(__DIR__).'/vendor/autoload.php'; +require dirname(__DIR__) . '/vendor/autoload.php'; -if (file_exists(dirname(__DIR__).'/config/bootstrap.php')) { - require dirname(__DIR__).'/config/bootstrap.php'; +if (file_exists(dirname(__DIR__) . '/config/bootstrap.php')) { + require dirname(__DIR__) . '/config/bootstrap.php'; } elseif (method_exists(Dotenv::class, 'bootEnv')) { - (new Dotenv())->usePutenv(true)->bootEnv(dirname(__DIR__).'/.env'); + (new Dotenv())->usePutenv(true)->bootEnv(dirname(__DIR__) . '/.env'); }