feat: assignable managers for accommodation bookings
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller\Admin\AccommodationBooking;
|
||||
|
||||
use App\Controller\Admin\AccommodationBooking\CreateController;
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Entity\User;
|
||||
use App\Service\AccommodationBookingService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
|
||||
/**
|
||||
* Covers the Betreuer default only — the form itself is exercised through
|
||||
* AccommodationBookingCreateType.
|
||||
*/
|
||||
class CreateControllerTest extends TestCase
|
||||
{
|
||||
public function testTheCreatingUserBecomesTheBetreuer(): void
|
||||
{
|
||||
$user = new User('[email protected]');
|
||||
|
||||
$controller = $this->buildController($user);
|
||||
$controller->index(Request::create('/admin/accommodation-booking/create'));
|
||||
|
||||
self::assertSame($user, $controller->capturedBooking?->getManagedBy());
|
||||
}
|
||||
|
||||
private function buildController(?UserInterface $user): TestableCreateController
|
||||
{
|
||||
$form = $this->createMock(FormInterface::class);
|
||||
$form->method('handleRequest')->willReturn($form);
|
||||
$form->method('isSubmitted')->willReturn(false);
|
||||
|
||||
return new TestableCreateController(
|
||||
$this->createMock(EntityManagerInterface::class),
|
||||
$this->createMock(LoggerInterface::class),
|
||||
$this->createMock(AccommodationBookingService::class),
|
||||
$form,
|
||||
$user,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final class TestableCreateController extends CreateController
|
||||
{
|
||||
public ?AccommodationBooking $capturedBooking = null;
|
||||
|
||||
public function __construct(
|
||||
EntityManagerInterface $entityManager,
|
||||
LoggerInterface $logger,
|
||||
AccommodationBookingService $bookingService,
|
||||
private readonly FormInterface $form,
|
||||
private readonly ?UserInterface $user,
|
||||
) {
|
||||
parent::__construct($entityManager, $logger, $bookingService);
|
||||
}
|
||||
|
||||
protected function createForm(string $type, mixed $data = null, array $options = []): FormInterface
|
||||
{
|
||||
if ($data instanceof AccommodationBooking) {
|
||||
$this->capturedBooking = $data;
|
||||
}
|
||||
|
||||
return $this->form;
|
||||
}
|
||||
|
||||
protected function getUser(): ?UserInterface
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $parameters
|
||||
*/
|
||||
protected function render(string $view, array $parameters = [], ?Response $response = null): Response
|
||||
{
|
||||
return new Response();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user