feat: groups price calculator admin crud, booking/offer flow and api
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller\Accommodation;
|
||||
|
||||
use App\Controller\Groups\IndexController;
|
||||
use App\Service\AccommodationBookingService;
|
||||
use App\Service\AccommodationSessionManager;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
|
||||
class IndexControllerTest extends TestCase
|
||||
{
|
||||
public function testSuccessRendersAndConsumesFlashOnFirstLoad(): void
|
||||
{
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$session->getFlashBag()->add('groups_booking_result', 'booking');
|
||||
|
||||
$request = Request::create('/groups/booking/success', 'GET');
|
||||
$request->setSession($session);
|
||||
|
||||
$controller = $this->makeController();
|
||||
|
||||
$response = $controller->success($request);
|
||||
|
||||
self::assertSame(200, $response->getStatusCode());
|
||||
self::assertSame('groups/booking/success.html.twig', $controller->renderedView);
|
||||
self::assertSame('booking', $controller->renderedParameters['resultType']);
|
||||
// The flash is read-once: a second read on the same request returns nothing.
|
||||
self::assertSame([], $session->getFlashBag()->get('groups_booking_result'));
|
||||
}
|
||||
|
||||
public function testSuccessRedirectsToLoginWhenFlashIsMissing(): void
|
||||
{
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
|
||||
$request = Request::create('/groups/booking/success', 'GET');
|
||||
$request->setSession($session);
|
||||
|
||||
$controller = $this->makeController();
|
||||
|
||||
$response = $controller->success($request);
|
||||
|
||||
self::assertInstanceOf(RedirectResponse::class, $response);
|
||||
self::assertSame('/app_login', $response->headers->get('Location'));
|
||||
}
|
||||
|
||||
private function makeController(): TestableAccommodationIndexController
|
||||
{
|
||||
return new TestableAccommodationIndexController(
|
||||
$this->createMock(AccommodationBookingService::class),
|
||||
$this->createMock(AccommodationSessionManager::class),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final class TestableAccommodationIndexController extends IndexController
|
||||
{
|
||||
/**
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
public array $renderedParameters = [];
|
||||
|
||||
public string $renderedView = '';
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $parameters
|
||||
*/
|
||||
protected function redirectToRoute(string $route, array $parameters = [], int $status = 302): RedirectResponse
|
||||
{
|
||||
return new RedirectResponse('/'.$route, $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $parameters
|
||||
*/
|
||||
protected function render(string $view, array $parameters = [], ?Response $response = null): Response
|
||||
{
|
||||
$this->renderedView = $view;
|
||||
$this->renderedParameters = $parameters;
|
||||
|
||||
return new Response('ok');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user