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
No related branches found
No related tags found
1 merge request!27tuleap-108-add-stricter-code-quality-tools-configuration
Pipeline #668 passed
parameters:
level: 7
level: 8
paths:
- tests/
symfony:
......
parameters:
level: 7
level: 8
paths:
- src/
symfony:
......
......@@ -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", [
......
......@@ -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();
......
......@@ -136,7 +136,7 @@ class Capsule
return $this;
}
public function getUpdateAuthor(): User
public function getUpdateAuthor(): ?User
{
return $this->update_author;
}
......
......@@ -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;
}
/**
......
......@@ -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');
......
......@@ -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;
}
}
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment