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

Fix PSR errors

parent 94ba7dde
No related branches found
No related tags found
1 merge request!9Tuleap 43 validate my registration
Showing with 103 additions and 53 deletions
......@@ -22,8 +22,10 @@ class RegistrationController extends AbstractController
private EmailVerifier $emailVerifier;
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);
......@@ -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) {
......
......@@ -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.');
}
}
......@@ -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);
......
......@@ -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');
......@@ -91,26 +107,30 @@ class RegistrationControllerTest extends WebTestCase
/**
* @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();
......
<?php
namespace App\Tests;
/**
......
<?php
namespace App\Tests;
/**
......
<?php
namespace App\Tests\Helper;
// here you can define custom actions
......
<?php
namespace App\Tests\Helper;
// here you can define custom actions
......
<?php
namespace App\Tests\Helper;
// here you can define custom actions
......
<?php
namespace App\Tests;
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment