Skip to content
Snippets Groups Projects
Commit b01c94cb authored by Camille Simiand's avatar Camille Simiand
Browse files

Increase and fix errors phpstan level 8

parent 9bee2b63
Branches
Tags
1 merge request!27tuleap-108-add-stricter-code-quality-tools-configuration
Pipeline #668 passed
parameters: parameters:
level: 7 level: 8
paths: paths:
- tests/ - tests/
symfony: symfony:
......
parameters: parameters:
level: 7 level: 8
paths: paths:
- src/ - src/
symfony: symfony:
......
...@@ -103,6 +103,7 @@ class FallbackController extends AbstractController ...@@ -103,6 +103,7 @@ class FallbackController extends AbstractController
$url = preg_replace('(^https?:\/\/[^/]+(:\d+)?)', '', $url); $url = preg_replace('(^https?:\/\/[^/]+(:\d+)?)', '', $url);
$pattern = '/\/\//i'; $pattern = '/\/\//i';
/** @phpstan-ignore-next-line */
$url = preg_replace($pattern, '/', $url); $url = preg_replace($pattern, '/', $url);
return $this->render("project/edit.html.twig", [ return $this->render("project/edit.html.twig", [
......
...@@ -18,7 +18,17 @@ class CapsuleFixtures extends Fixture implements DependentFixtureInterface ...@@ -18,7 +18,17 @@ class CapsuleFixtures extends Fixture implements DependentFixtureInterface
$user_repository = $manager->getRepository(User::class); $user_repository = $manager->getRepository(User::class);
$verified_user1 = $user_repository->findOneBy(['email' => "defaultUser@localhost.com"]); $verified_user1 = $user_repository->findOneBy(['email' => "defaultUser@localhost.com"]);
if (! $verified_user1 instanceof User) {
throw new \Exception("User does not exist.");
}
$verified_user2 = $user_repository->findOneBy(['email' => "defaultUser2@localhost.com"]); $verified_user2 = $user_repository->findOneBy(['email' => "defaultUser2@localhost.com"]);
if (! $verified_user2 instanceof User) {
throw new \Exception("User does not exist.");
}
$new_date_time = new DateTime(); $new_date_time = new DateTime();
$uuid_first_capsule = Uuid::v4(); $uuid_first_capsule = Uuid::v4();
$uuid_second_capsule = Uuid::v4(); $uuid_second_capsule = Uuid::v4();
......
...@@ -136,7 +136,7 @@ class Capsule ...@@ -136,7 +136,7 @@ class Capsule
return $this; return $this;
} }
public function getUpdateAuthor(): User public function getUpdateAuthor(): ?User
{ {
return $this->update_author; return $this->update_author;
} }
......
...@@ -87,7 +87,7 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface ...@@ -87,7 +87,7 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface
return $this->id; return $this->id;
} }
public function getEmail(): ?string public function getEmail(): string
{ {
return $this->email; return $this->email;
} }
...@@ -116,7 +116,7 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface ...@@ -116,7 +116,7 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface
*/ */
public function getUsername(): string public function getUsername(): string
{ {
return (string) $this->email; return $this->email;
} }
/** /**
......
...@@ -35,7 +35,10 @@ class ProjectControllerTest extends WebTestCase ...@@ -35,7 +35,10 @@ class ProjectControllerTest extends WebTestCase
->getRepository(User::class) ->getRepository(User::class)
->findOneBy(['email' => 'defaultUser@localhost.com']) ->findOneBy(['email' => 'defaultUser@localhost.com'])
; ;
self::assertInstanceOf(User::class, $verified_user);
if (! $verified_user instanceof User) {
throw new \Exception("User does not exist.");
}
$this->client->loginUser($verified_user); $this->client->loginUser($verified_user);
...@@ -56,6 +59,11 @@ class ProjectControllerTest extends WebTestCase ...@@ -56,6 +59,11 @@ class ProjectControllerTest extends WebTestCase
$capsule_repository = $this->object_manager->getRepository(Capsule::class); $capsule_repository = $this->object_manager->getRepository(Capsule::class);
$last_capsule = $capsule_repository->findOneBy(['name' => self::CAPSULE_NAME]); $last_capsule = $capsule_repository->findOneBy(['name' => self::CAPSULE_NAME]);
if (! $last_capsule instanceof Capsule) {
throw new \Exception("Capsule does not exist.");
}
$this->object_manager->remove($last_capsule); $this->object_manager->remove($last_capsule);
$this->object_manager->flush(); $this->object_manager->flush();
} }
...@@ -89,12 +97,21 @@ class ProjectControllerTest extends WebTestCase ...@@ -89,12 +97,21 @@ class ProjectControllerTest extends WebTestCase
$capsule_repository = $this->object_manager->getRepository(Capsule::class); $capsule_repository = $this->object_manager->getRepository(Capsule::class);
$capsule_in_db = $capsule_repository->findOneBy(['name' => self::CAPSULE_NAME]); $capsule_in_db = $capsule_repository->findOneBy(['name' => self::CAPSULE_NAME]);
if (! $capsule_in_db instanceof Capsule) {
throw new \Exception("Capsule does not exist.");
}
self::assertInstanceOf(Capsule::class, $capsule_in_db); self::assertInstanceOf(Capsule::class, $capsule_in_db);
$capsule_name_in_db = $capsule_in_db->getName(); $capsule_name_in_db = $capsule_in_db->getName();
$dom_xml = $this->getDomDocument(); $dom_xml = $this->getDomDocument();
$video_node = $dom_xml->getElementsByTagName('video')->item(0); $video_node = $dom_xml->getElementsByTagName('video')->item(0);
if ($video_node === null) {
throw new \Exception("Video node could not be found in XML project file");
}
$video_url_in_xml_file = $video_node->getAttribute('url'); $video_url_in_xml_file = $video_node->getAttribute('url');
$this->assertResponseIsSuccessful('/my_capsules'); $this->assertResponseIsSuccessful('/my_capsules');
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace App\Tests\functional; namespace App\Tests\functional;
use App\Entity\Capsule;
use App\Entity\User; use App\Entity\User;
use App\Repository\UserRepository; use App\Repository\UserRepository;
use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\KernelBrowser;
...@@ -83,8 +84,7 @@ class RegistrationControllerTest extends WebTestCase ...@@ -83,8 +84,7 @@ class RegistrationControllerTest extends WebTestCase
public function testAnAuthenticatedUserShouldNotBeAbleToAccessTheRegisterPage(): void public function testAnAuthenticatedUserShouldNotBeAbleToAccessTheRegisterPage(): void
{ {
$userRepository = static::getContainer()->get(UserRepository::class); $testUser = $this->getUserByEmail('defaultUser@localhost.com');
$testUser = $userRepository->findOneByEmail('defaultUser@localhost.com');
$this->client->loginUser($testUser); $this->client->loginUser($testUser);
$this->client->request('GET', '/register'); $this->client->request('GET', '/register');
...@@ -94,8 +94,7 @@ class RegistrationControllerTest extends WebTestCase ...@@ -94,8 +94,7 @@ class RegistrationControllerTest extends WebTestCase
public function testAnAuthenticatedUserShouldNotBeAbleToAccessTheLoginPage(): void public function testAnAuthenticatedUserShouldNotBeAbleToAccessTheLoginPage(): void
{ {
$userRepository = static::getContainer()->get(UserRepository::class); $testUser = $this->getUserByEmail('defaultUser@localhost.com');
$testUser = $userRepository->findOneByEmail('defaultUser@localhost.com');
$this->client->loginUser($testUser); $this->client->loginUser($testUser);
$this->client->request('GET', '/login'); $this->client->request('GET', '/login');
...@@ -125,6 +124,11 @@ class RegistrationControllerTest extends WebTestCase ...@@ -125,6 +124,11 @@ class RegistrationControllerTest extends WebTestCase
'Once the user has been registered, the system should send an email to this user' 'Once the user has been registered, the system should send an email to this user'
); );
$emailMessage = $this->getMailerMessage(0); $emailMessage = $this->getMailerMessage(0);
if (null === $emailMessage) {
throw new \Exception("Email message could not be found");
}
$this->assertEmailAddressContains( $this->assertEmailAddressContains(
$emailMessage, $emailMessage,
'To', 'To',
...@@ -180,6 +184,12 @@ class RegistrationControllerTest extends WebTestCase ...@@ -180,6 +184,12 @@ class RegistrationControllerTest extends WebTestCase
private function getUserByEmail(string $userEmail): User private function getUserByEmail(string $userEmail): User
{ {
$userRepository = static::getContainer()->get(UserRepository::class); $userRepository = static::getContainer()->get(UserRepository::class);
return $userRepository->findOneByEmail($userEmail); $user = $userRepository->findOneByEmail($userEmail);
if (! $user instanceof User) {
throw new \Exception("User does not exist.");
}
return $user;
} }
} }
...@@ -61,7 +61,7 @@ class ResetPasswordControllerTest extends WebTestCase ...@@ -61,7 +61,7 @@ class ResetPasswordControllerTest extends WebTestCase
$this->testRegisteredUserWithEnabledAccountIsRedirectedToCapsulesPageWhenSubmittingLoginForm(); $this->testRegisteredUserWithEnabledAccountIsRedirectedToCapsulesPageWhenSubmittingLoginForm();
} }
private function getEmailMessageWithResetPasswordLinkForVerifiedUser(): ?RawMessage private function getEmailMessageWithResetPasswordLinkForVerifiedUser(): RawMessage
{ {
$crawler = $this->client->request('GET', '/reset-password'); $crawler = $this->client->request('GET', '/reset-password');
$this->assertResponseIsSuccessful(); $this->assertResponseIsSuccessful();
...@@ -72,7 +72,13 @@ class ResetPasswordControllerTest extends WebTestCase ...@@ -72,7 +72,13 @@ class ResetPasswordControllerTest extends WebTestCase
$form['reset_password_request_form[email]'] = self::VERIFIED_USER_EMAIL; $form['reset_password_request_form[email]'] = self::VERIFIED_USER_EMAIL;
$this->client->submit($form); $this->client->submit($form);
return $this->getMailerMessage(0); $email_message = $this->getMailerMessage(0);
if (null === $email_message) {
throw new \Exception("Email message could not be found");
}
return $email_message;
} }
private function submitResetPasswordFormWithAnUnverifiedEmailAddress(): void private function submitResetPasswordFormWithAnUnverifiedEmailAddress(): void
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment