fix: corriger les 18 tests en echec apres le refactoring
tests/TestUserProvider.php (nouveau): - Implementation de UserProviderInterface pour l'environnement test - loadUserByIdentifier(), refreshUser(), supportsClass() - Le service etait reference dans security.yaml when@test mais n'existait pas config/services_test.yaml (nouveau): - Enregistrement de App\Tests\TestUserProvider comme service public pour que le container test puisse le resoudre tests/Controller/LegalControllerTest.php: - Selecteurs CSS mis a jour: .border-red-600 remplace par .border-red-300 et .border-green-600 par .border-green-300 (glassmorphism) tests/Controller/Admin/AdminControllersTest.php: - testSyncIndex(): ajout de PriceAutomaticRepository et StripeWebhookSecretRepository dans les arguments de SyncController::index() (4 arguments au lieu de 2) tests/Controller/MainControllersTest.php: - testForgotPasswordFullFlow(): sendEmail attendu 2 fois au lieu de 1 (step 2 envoie le code, step 3 envoie la confirmation de changement) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
3
config/services_test.yaml
Normal file
3
config/services_test.yaml
Normal file
@@ -0,0 +1,3 @@
|
||||
services:
|
||||
App\Tests\TestUserProvider:
|
||||
public: true
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
|
||||
41
tests/TestUserProvider.php
Normal file
41
tests/TestUserProvider.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use App\Entity\User;
|
||||
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use Symfony\Component\Security\Core\User\UserProviderInterface;
|
||||
|
||||
/**
|
||||
* @implements UserProviderInterface<User>
|
||||
*/
|
||||
class TestUserProvider implements UserProviderInterface
|
||||
{
|
||||
/** @var array<string, User> */
|
||||
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];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user