diff --git a/phpstan-tests.neon b/phpstan-tests.neon index 64e8c887853a551bfe64d7193d4c14c0200336b0..296aee80dd57d89fe7bfa759f4cf4c00f24bad25 100644 --- a/phpstan-tests.neon +++ b/phpstan-tests.neon @@ -1,5 +1,5 @@ parameters: - level: 7 + level: 8 paths: - tests/ symfony: diff --git a/phpstan.neon b/phpstan.neon index a703b75b75873eaffccd5860461d71953fb62d94..090087ea121869c5e111f207b99c41995209b4c5 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 7 + level: 8 paths: - src/ symfony: diff --git a/src/Controller/FallbackController.php b/src/Controller/FallbackController.php index dfa97390c5366244dfda1ba63fae4f38fd262fdd..181aca603489a6709ed42279bf356da788b43887 100644 --- a/src/Controller/FallbackController.php +++ b/src/Controller/FallbackController.php @@ -103,6 +103,7 @@ class FallbackController extends AbstractController $url = preg_replace('(^https?:\/\/[^/]+(:\d+)?)', '', $url); $pattern = '/\/\//i'; + /** @phpstan-ignore-next-line */ $url = preg_replace($pattern, '/', $url); return $this->render("project/edit.html.twig", [ diff --git a/src/DataFixtures/CapsuleFixtures.php b/src/DataFixtures/CapsuleFixtures.php index 43f6ea2ae6a72da3845ec8a33e223cee4fc37644..18f54605ecc51c89d40f40b015aef2bdb98d73a0 100644 --- a/src/DataFixtures/CapsuleFixtures.php +++ b/src/DataFixtures/CapsuleFixtures.php @@ -18,7 +18,17 @@ class CapsuleFixtures extends Fixture implements DependentFixtureInterface $user_repository = $manager->getRepository(User::class); $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"]); + + if (! $verified_user2 instanceof User) { + throw new \Exception("User does not exist."); + } + $new_date_time = new DateTime(); $uuid_first_capsule = Uuid::v4(); $uuid_second_capsule = Uuid::v4(); diff --git a/src/Entity/Capsule.php b/src/Entity/Capsule.php index b3dc11d557077f226b0d94ae47a59b48a78c9910..ef40356cb52556d41817803303b43d49a046f3cd 100644 --- a/src/Entity/Capsule.php +++ b/src/Entity/Capsule.php @@ -136,7 +136,7 @@ class Capsule return $this; } - public function getUpdateAuthor(): User + public function getUpdateAuthor(): ?User { return $this->update_author; } diff --git a/src/Entity/User.php b/src/Entity/User.php index 1bbf9a3d02bbd347fa8df485b52c229ed05a85a2..d95519f0a238dd12b15888f03f9b5edab08df193 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -87,7 +87,7 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface return $this->id; } - public function getEmail(): ?string + public function getEmail(): string { return $this->email; } @@ -116,7 +116,7 @@ class User implements UserInterface, LegacyPasswordAuthenticatedUserInterface */ public function getUsername(): string { - return (string) $this->email; + return $this->email; } /** diff --git a/tests/functional/ProjectControllerTest.php b/tests/functional/ProjectControllerTest.php index c144d7f8ee1a896865baae0a7cf62d0eca25c81b..efc78910b2c68749ceb18b470c2b4d71de3cd223 100644 --- a/tests/functional/ProjectControllerTest.php +++ b/tests/functional/ProjectControllerTest.php @@ -35,7 +35,10 @@ class ProjectControllerTest extends WebTestCase ->getRepository(User::class) ->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); @@ -56,6 +59,11 @@ class ProjectControllerTest extends WebTestCase $capsule_repository = $this->object_manager->getRepository(Capsule::class); $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->flush(); } @@ -89,12 +97,21 @@ class ProjectControllerTest extends WebTestCase $capsule_repository = $this->object_manager->getRepository(Capsule::class); $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); $capsule_name_in_db = $capsule_in_db->getName(); $dom_xml = $this->getDomDocument(); $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'); $this->assertResponseIsSuccessful('/my_capsules'); diff --git a/tests/functional/RegistrationControllerTest.php b/tests/functional/RegistrationControllerTest.php index 39eca6b9cb5fe25fd161daf9640d2d16cd9e167c..85fca77d802f0729048916e3c1d27df5cd20d2a5 100644 --- a/tests/functional/RegistrationControllerTest.php +++ b/tests/functional/RegistrationControllerTest.php @@ -2,6 +2,7 @@ namespace App\Tests\functional; +use App\Entity\Capsule; use App\Entity\User; use App\Repository\UserRepository; use Symfony\Bundle\FrameworkBundle\KernelBrowser; @@ -83,8 +84,7 @@ class RegistrationControllerTest extends WebTestCase public function testAnAuthenticatedUserShouldNotBeAbleToAccessTheRegisterPage(): void { - $userRepository = static::getContainer()->get(UserRepository::class); - $testUser = $userRepository->findOneByEmail('defaultUser@localhost.com'); + $testUser = $this->getUserByEmail('defaultUser@localhost.com'); $this->client->loginUser($testUser); $this->client->request('GET', '/register'); @@ -94,8 +94,7 @@ class RegistrationControllerTest extends WebTestCase public function testAnAuthenticatedUserShouldNotBeAbleToAccessTheLoginPage(): void { - $userRepository = static::getContainer()->get(UserRepository::class); - $testUser = $userRepository->findOneByEmail('defaultUser@localhost.com'); + $testUser = $this->getUserByEmail('defaultUser@localhost.com'); $this->client->loginUser($testUser); $this->client->request('GET', '/login'); @@ -125,6 +124,11 @@ class RegistrationControllerTest extends WebTestCase 'Once the user has been registered, the system should send an email to this user' ); $emailMessage = $this->getMailerMessage(0); + + if (null === $emailMessage) { + throw new \Exception("Email message could not be found"); + } + $this->assertEmailAddressContains( $emailMessage, 'To', @@ -180,6 +184,12 @@ class RegistrationControllerTest extends WebTestCase private function getUserByEmail(string $userEmail): User { $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; } } diff --git a/tests/functional/ResetPasswordControllerTest.php b/tests/functional/ResetPasswordControllerTest.php index 9fc7b8dd0f7578e83993fbdd7f20ae817a88fda1..0e7e57cb82b7c0a07c6c1194e9b98e890217615d 100644 --- a/tests/functional/ResetPasswordControllerTest.php +++ b/tests/functional/ResetPasswordControllerTest.php @@ -61,7 +61,7 @@ class ResetPasswordControllerTest extends WebTestCase $this->testRegisteredUserWithEnabledAccountIsRedirectedToCapsulesPageWhenSubmittingLoginForm(); } - private function getEmailMessageWithResetPasswordLinkForVerifiedUser(): ?RawMessage + private function getEmailMessageWithResetPasswordLinkForVerifiedUser(): RawMessage { $crawler = $this->client->request('GET', '/reset-password'); $this->assertResponseIsSuccessful(); @@ -72,7 +72,13 @@ class ResetPasswordControllerTest extends WebTestCase $form['reset_password_request_form[email]'] = self::VERIFIED_USER_EMAIL; $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