Skip to content
Snippets Groups Projects
Commit 1c427f40 authored by Sebastien Curt's avatar Sebastien Curt
Browse files

Fix PSR errors

parent 94ba7dde
Branches
Tags
1 merge request!9Tuleap 43 validate my registration
Showing with 103 additions and 53 deletions
...@@ -22,8 +22,10 @@ class RegistrationController extends AbstractController ...@@ -22,8 +22,10 @@ class RegistrationController extends AbstractController
private EmailVerifier $emailVerifier; 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->emailVerifier = $emailVerifier;
$this->requestStack = $requestStack; $this->requestStack = $requestStack;
} }
...@@ -31,8 +33,11 @@ class RegistrationController extends AbstractController ...@@ -31,8 +33,11 @@ class RegistrationController extends AbstractController
/** /**
* @Route("/register", name="app_register") * @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(); $user = new User();
$form = $this->createForm(RegistrationFormType::class, $user); $form = $this->createForm(RegistrationFormType::class, $user);
$form->handleRequest($request); $form->handleRequest($request);
...@@ -76,8 +81,10 @@ class RegistrationController extends AbstractController ...@@ -76,8 +81,10 @@ class RegistrationController extends AbstractController
/** /**
* @Route("/verify/email", name="app_verify_email") * @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'); $id = $request->get('id');
if (null === $id) { if (null === $id) {
......
...@@ -31,6 +31,7 @@ class SecurityController extends AbstractController ...@@ -31,6 +31,7 @@ class SecurityController extends AbstractController
*/ */
public function logout(): void 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.');
} }
} }
...@@ -16,15 +16,21 @@ class EmailVerifier ...@@ -16,15 +16,21 @@ class EmailVerifier
private $mailer; private $mailer;
private $entityManager; private $entityManager;
public function __construct(VerifyEmailHelperInterface $helper, MailerInterface $mailer, EntityManagerInterface $manager) public function __construct(
{ VerifyEmailHelperInterface $helper,
MailerInterface $mailer,
EntityManagerInterface $manager
) {
$this->verifyEmailHelper = $helper; $this->verifyEmailHelper = $helper;
$this->mailer = $mailer; $this->mailer = $mailer;
$this->entityManager = $manager; $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( $signatureComponents = $this->verifyEmailHelper->generateSignature(
$verifyEmailRouteName, $verifyEmailRouteName,
$user->getId(), $user->getId(),
...@@ -45,8 +51,10 @@ class EmailVerifier ...@@ -45,8 +51,10 @@ class EmailVerifier
/** /**
* @throws VerifyEmailExceptionInterface * @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()); $this->verifyEmailHelper->validateEmailConfirmation($request->getUri(), $user->getId(), $user->getEmail());
$user->setIsVerified(true); $user->setIsVerified(true);
......
...@@ -17,40 +17,56 @@ class RegistrationControllerTest extends WebTestCase ...@@ -17,40 +17,56 @@ class RegistrationControllerTest extends WebTestCase
$userEmail = 'newUser@localhost.com'; $userEmail = 'newUser@localhost.com';
$client = static::createClient(); $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'; $userEmail = 'newUser@localhost.com';
$client = static::createClient(); $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 * @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->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 * @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(); $client->followRedirect();
$this->assertResponseIsSuccessful('/register_mail_sent'); $this->assertResponseIsSuccessful('/register_mail_sent');
} }
...@@ -59,7 +75,7 @@ class RegistrationControllerTest extends WebTestCase ...@@ -59,7 +75,7 @@ class RegistrationControllerTest extends WebTestCase
* @param string $userEmail * @param string $userEmail
* @param $client * @param $client
*/ */
private function RegisterUser(string $userEmail, &$client): void private function registerUser(string $userEmail, &$client): void
{ {
$crawler = $client->request('GET', '/register'); $crawler = $client->request('GET', '/register');
...@@ -91,26 +107,30 @@ class RegistrationControllerTest extends WebTestCase ...@@ -91,26 +107,30 @@ class RegistrationControllerTest extends WebTestCase
/** /**
* @param string $userEmail * @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 string $userEmail
* @param KernelBrowser $client * @param KernelBrowser $client
*/ */
private function CheckUserRegistrationPostConditions(string $userEmail, KernelBrowser $client): void private function checkUserRegistrationPostConditions(string $userEmail, KernelBrowser $client): void
{ {
$this->CheckUseIsNotAbleToLogIn($userEmail); $this->checkUseIsNotAbleToLogIn($userEmail);
$this->CheckMailHasBeenSent($userEmail); $this->checkMailHasBeenSent($userEmail);
$this->CheckUserHasMailNotification($client); $this->checkUserHasMailNotification($client);
} }
/** /**
* @param KernelBrowser $client * @param KernelBrowser $client
*/ */
private function ClickOnMailValidationLink(KernelBrowser $client): void private function clickOnMailValidationLink(KernelBrowser $client): void
{ {
$crawler = new Crawler($this->emailMessage->getHtmlBody()); $crawler = new Crawler($this->emailMessage->getHtmlBody());
$crawlerLink = $crawler->selectLink('Confirm my Email')->link(); $crawlerLink = $crawler->selectLink('Confirm my Email')->link();
...@@ -121,13 +141,21 @@ class RegistrationControllerTest extends WebTestCase ...@@ -121,13 +141,21 @@ class RegistrationControllerTest extends WebTestCase
* @param string $userEmail * @param string $userEmail
* @param KernelBrowser $client * @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 // 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 // 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 // Chedk the redirection is succesfull
$client->followRedirect(); $client->followRedirect();
......
<?php <?php
namespace App\Tests; namespace App\Tests;
/** /**
......
<?php <?php
namespace App\Tests; namespace App\Tests;
/** /**
......
<?php <?php
namespace App\Tests\Helper; namespace App\Tests\Helper;
// here you can define custom actions // here you can define custom actions
......
<?php <?php
namespace App\Tests\Helper; namespace App\Tests\Helper;
// here you can define custom actions // here you can define custom actions
......
<?php <?php
namespace App\Tests\Helper; namespace App\Tests\Helper;
// here you can define custom actions // here you can define custom actions
......
<?php <?php
namespace App\Tests; namespace App\Tests;
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment