feat(revervation): [Ajoute la création de session de réservation et le flow]
🐛 fix(PurgeCommandTest): [Utilise addCommand au lieu de add pour les commandes]
📝 chore(deps): [Mise à jour des dépendances Composer et corrections]
🐛 fix(KeycloakAuthenticator): [Corrige le type nullable de l'exception start]
 feat(Customer): [Ajoute les sessions de commandes aux entités Customer]
♻️ refactor(AppLogger): [Refactorise l'AppLogger pour obtenir l'UserAgent]
 feat(FlowReserve): [Ajoute une action de validation du panier]
```
This commit is contained in:
Serreau Jovann
2026-01-31 13:49:25 +01:00
parent 4227c3d3b0
commit 0be752c145
117 changed files with 8798 additions and 2645 deletions

View File

@@ -0,0 +1,92 @@
<?php
namespace App\Tests\Security;
use App\Entity\Customer;
use App\Entity\OrderSession;
use App\Security\FlowAuthenticator;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\CsrfTokenBadge;
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
#[AllowMockObjectsWithoutExpectations]
class FlowAuthenticatorTest extends TestCase
{
private $urlGenerator;
private $entityManager;
private $authenticator;
protected function setUp(): void
{
$this->urlGenerator = $this->createMock(UrlGeneratorInterface::class);
$this->entityManager = $this->createMock(EntityManagerInterface::class);
$this->authenticator = new FlowAuthenticator($this->urlGenerator, $this->entityManager);
}
public function testSupports()
{
$request = Request::create('/reservation/flow', 'POST');
$request->attributes->set('_route', 'reservation_flow');
$this->assertTrue($this->authenticator->supports($request));
}
public function testAuthenticate()
{
$request = Request::create('/reservation/flow', 'POST', [
'_username' => 'test@test.com',
'_password' => 'password',
'_csrf_token' => 'token'
]);
$session = $this->createMock(SessionInterface::class);
$request->setSession($session);
$repository = $this->createMock(EntityRepository::class);
$this->entityManager->method('getRepository')->with(Customer::class)->willReturn($repository);
$repository->method('findOneBy')->with(['email' => 'test@test.com'])->willReturn(new Customer());
$passport = $this->authenticator->authenticate($request);
$this->assertInstanceOf(Passport::class, $passport);
$this->assertTrue($passport->hasBadge(UserBadge::class));
}
public function testOnAuthenticationSuccess()
{
$request = Request::create('/reservation/flow');
$request->attributes->set('sessionId', 'session-123');
$token = $this->createMock(TokenInterface::class);
$customer = new Customer();
$token->method('getUser')->willReturn($customer);
$sessionRepo = $this->createMock(EntityRepository::class);
$orderSession = $this->createMock(OrderSession::class);
$this->entityManager->method('getRepository')->with(OrderSession::class)->willReturn($sessionRepo);
$sessionRepo->method('findOneBy')->with(['uuid' => 'session-123'])->willReturn($orderSession);
$orderSession->expects($this->once())->method('setCustomer')->with($customer);
$this->entityManager->expects($this->once())->method('flush');
$this->urlGenerator->expects($this->once())
->method('generate')
->with('reservation_flow', ['sessionId' => 'session-123'])
->willReturn('/reservation/flow/session-123');
$response = $this->authenticator->onAuthenticationSuccess($request, $token, 'main');
$this->assertInstanceOf(RedirectResponse::class, $response);
$this->assertEquals('/reservation/flow/session-123', $response->getTargetUrl());
}
}