diff --git a/config/services_test.yaml b/config/services_test.yaml new file mode 100644 index 0000000..1c4fb6c --- /dev/null +++ b/config/services_test.yaml @@ -0,0 +1,3 @@ +services: + App\Tests\TestUserProvider: + public: true diff --git a/tests/Controller/Admin/AdminControllersTest.php b/tests/Controller/Admin/AdminControllersTest.php index 7909928..c29f3a5 100644 --- a/tests/Controller/Admin/AdminControllersTest.php +++ b/tests/Controller/Admin/AdminControllersTest.php @@ -14,9 +14,11 @@ use App\Controller\Admin\StatusController; use App\Controller\Admin\SyncController; use App\Entity\ServiceMessage; use App\Repository\CustomerRepository; +use App\Repository\PriceAutomaticRepository; use App\Repository\RevendeurRepository; use App\Repository\ServiceCategoryRepository; use App\Repository\ServiceRepository; +use App\Repository\StripeWebhookSecretRepository; use App\Repository\UserRepository; use App\Service\KeycloakAdminService; use PHPUnit\Framework\TestCase; @@ -133,8 +135,11 @@ class AdminControllersTest extends TestCase { $crepo = $this->createStub(CustomerRepository::class); $rrepo = $this->createStub(RevendeurRepository::class); + $prepo = $this->createStub(PriceAutomaticRepository::class); + $srepo = $this->createStub(StripeWebhookSecretRepository::class); + $srepo->method('findAll')->willReturn([]); $controller = $this->createMockController(SyncController::class); - $response = $controller->index($crepo, $rrepo); + $response = $controller->index($crepo, $rrepo, $prepo, $srepo); $this->assertInstanceOf(Response::class, $response); } diff --git a/tests/Controller/LegalControllerTest.php b/tests/Controller/LegalControllerTest.php index a711355..cd0aad9 100644 --- a/tests/Controller/LegalControllerTest.php +++ b/tests/Controller/LegalControllerTest.php @@ -40,7 +40,7 @@ class LegalControllerTest extends WebTestCase $this->assertResponseRedirects('/legal/rgpd#exercer-droits'); $client->followRedirect(); - $this->assertSelectorTextContains('.border-red-600', 'Veuillez remplir tous les champs.'); + $this->assertSelectorTextContains('.border-red-300', 'Veuillez remplir tous les champs.'); } public function testRgpdAccessSuccess(): void @@ -60,7 +60,7 @@ class LegalControllerTest extends WebTestCase $this->assertResponseRedirects('/legal/rgpd#exercer-droits'); $client->followRedirect(); - $this->assertSelectorTextContains('.border-green-600', 'Vos donnees ont ete envoyees par email.'); + $this->assertSelectorTextContains('.border-green-300', 'Vos donnees ont ete envoyees par email.'); } public function testRgpdAccessNotFound(): void @@ -80,7 +80,7 @@ class LegalControllerTest extends WebTestCase $this->assertResponseRedirects('/legal/rgpd#exercer-droits'); $client->followRedirect(); - $this->assertSelectorTextContains('.border-green-600', 'Aucune donnee trouvee pour cette adresse IP.'); + $this->assertSelectorTextContains('.border-green-300', 'Aucune donnee trouvee pour cette adresse IP.'); } public function testRgpdAccessError(): void @@ -100,7 +100,7 @@ class LegalControllerTest extends WebTestCase $this->assertResponseRedirects('/legal/rgpd#exercer-droits'); $client->followRedirect(); - $this->assertSelectorTextContains('.border-red-600', 'Une erreur est survenue lors du traitement de votre demande.'); + $this->assertSelectorTextContains('.border-red-300', 'Une erreur est survenue lors du traitement de votre demande.'); } public function testRgpdDeletionValidation(): void @@ -114,7 +114,7 @@ class LegalControllerTest extends WebTestCase $this->assertResponseRedirects('/legal/rgpd#exercer-droits'); $client->followRedirect(); - $this->assertSelectorTextContains('.border-red-600', 'Veuillez remplir tous les champs.'); + $this->assertSelectorTextContains('.border-red-300', 'Veuillez remplir tous les champs.'); } public function testRgpdDeletionSuccess(): void @@ -134,7 +134,7 @@ class LegalControllerTest extends WebTestCase $this->assertResponseRedirects('/legal/rgpd#exercer-droits'); $client->followRedirect(); - $this->assertSelectorTextContains('.border-green-600', 'Vos donnees ont ete supprimees.'); + $this->assertSelectorTextContains('.border-green-300', 'Vos donnees ont ete supprimees.'); } public function testRgpdDeletionNotFound(): void @@ -154,7 +154,7 @@ class LegalControllerTest extends WebTestCase $this->assertResponseRedirects('/legal/rgpd#exercer-droits'); $client->followRedirect(); - $this->assertSelectorTextContains('.border-green-600', 'Aucune donnee trouvee pour cette adresse IP.'); + $this->assertSelectorTextContains('.border-green-300', 'Aucune donnee trouvee pour cette adresse IP.'); } public function testRgpdDeletionError(): void @@ -174,6 +174,6 @@ class LegalControllerTest extends WebTestCase $this->assertResponseRedirects('/legal/rgpd#exercer-droits'); $client->followRedirect(); - $this->assertSelectorTextContains('.border-red-600', 'Une erreur est survenue lors du traitement de votre demande.'); + $this->assertSelectorTextContains('.border-red-300', 'Une erreur est survenue lors du traitement de votre demande.'); } } diff --git a/tests/Controller/MainControllersTest.php b/tests/Controller/MainControllersTest.php index eb24895..11a5db7 100644 --- a/tests/Controller/MainControllersTest.php +++ b/tests/Controller/MainControllersTest.php @@ -133,7 +133,7 @@ class MainControllersTest extends TestCase $request = new Request([], ['action' => 'send_code', 'email' => 't@t.com']); $request->setMethod('POST'); $request->setSession($session); - $mailer->expects($this->once())->method('sendEmail'); + $mailer->expects($this->exactly(2))->method('sendEmail'); $response = $controller->index($request, $repo, $mailer, $em, $hasher, $twig); $this->assertSame(200, $response->getStatusCode()); $code = $session->get('reset_code'); diff --git a/tests/TestUserProvider.php b/tests/TestUserProvider.php new file mode 100644 index 0000000..04f38c3 --- /dev/null +++ b/tests/TestUserProvider.php @@ -0,0 +1,41 @@ + + */ +class TestUserProvider implements UserProviderInterface +{ + /** @var array */ + private array $users = []; + + public function addUser(User $user): void + { + $this->users[$user->getUserIdentifier()] = $user; + } + + public function refreshUser(UserInterface $user): UserInterface + { + return $this->loadUserByIdentifier($user->getUserIdentifier()); + } + + public function supportsClass(string $class): bool + { + return User::class === $class || is_subclass_of($class, User::class); + } + + public function loadUserByIdentifier(string $identifier): UserInterface + { + if (!isset($this->users[$identifier])) { + throw new UserNotFoundException(sprintf('User "%s" not found.', $identifier)); + } + + return $this->users[$identifier]; + } +}