100 lines
3.5 KiB
PHP
100 lines
3.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Repository;
|
|
|
|
use App\Config\QuestionnaireCatalog;
|
|
use App\Entity\QuestionnaireResponse;
|
|
use App\Entity\Teamer;
|
|
use App\Model\QuestionnaireResponseFilterDto;
|
|
use App\Repository\QuestionnaireResponseRepository;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
|
|
|
/**
|
|
* The office's list of submitted questionnaires, run against db_test inside a rolled-back
|
|
* transaction. A draft is still the teamer's and must never show up there.
|
|
*/
|
|
class QuestionnaireResponseRepositoryTest extends KernelTestCase
|
|
{
|
|
use QuestionnaireFixturesTrait;
|
|
|
|
private EntityManagerInterface $entityManager;
|
|
|
|
private QuestionnaireResponseRepository $repository;
|
|
|
|
private Teamer $teamer;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
self::bootKernel();
|
|
$this->entityManager = self::getContainer()->get(EntityManagerInterface::class);
|
|
$this->repository = $this->entityManager->getRepository(QuestionnaireResponse::class);
|
|
$this->entityManager->getConnection()->beginTransaction();
|
|
|
|
$this->teamer = (new Teamer())->setFirstName('Kim')->setLastName('Muster')->setGender('d');
|
|
$this->entityManager->persist($this->teamer);
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
$this->entityManager->getConnection()->rollBack();
|
|
parent::tearDown();
|
|
}
|
|
|
|
public function testOnlySubmittedResponsesToThisQuestionnaireAreListed(): void
|
|
{
|
|
$submitted = $this->respond($this->escort(), submit: true);
|
|
$this->respond($this->escort(), submit: false);
|
|
$this->respond($this->escort(), submit: true, questionnaire: 'other');
|
|
|
|
$this->assertSame([$submitted], $this->list(new QuestionnaireResponseFilterDto()));
|
|
}
|
|
|
|
public function testFilterByTeamer(): void
|
|
{
|
|
$other = (new Teamer())->setFirstName('Alex')->setLastName('Beispiel')->setGender('d');
|
|
$this->entityManager->persist($other);
|
|
$this->respond($this->escort(teamer: $other), submit: true);
|
|
$mine = $this->respond($this->escort(), submit: true);
|
|
|
|
$this->assertSame([$mine], $this->list((new QuestionnaireResponseFilterDto())->setTeamer($this->teamer)));
|
|
}
|
|
|
|
/**
|
|
* Matched as a substring, and a % typed into the filter is a literal, not a wildcard.
|
|
*/
|
|
public function testFilterByHotel(): void
|
|
{
|
|
$ranalt = $this->respond($this->escort(hotel: 'Gasthof Ranalt'), submit: true);
|
|
$this->respond($this->escort(hotel: 'Schwendi'), submit: true);
|
|
|
|
$this->assertSame([$ranalt], $this->list((new QuestionnaireResponseFilterDto())->setHotel('ranalt')));
|
|
$this->assertSame([], $this->list((new QuestionnaireResponseFilterDto())->setHotel('%')));
|
|
}
|
|
|
|
public function testFilterByEndOfAssignment(): void
|
|
{
|
|
$recent = $this->respond($this->escort(dateTo: '2026-03-14'), submit: true);
|
|
$this->respond($this->escort(dateTo: '2026-01-10'), submit: true);
|
|
|
|
$filter = (new QuestionnaireResponseFilterDto())
|
|
->setDateFrom(new \DateTimeImmutable('2026-03-01'))
|
|
->setDateTo(new \DateTimeImmutable('2026-03-14'))
|
|
;
|
|
|
|
$this->assertSame([$recent], $this->list($filter));
|
|
}
|
|
|
|
/**
|
|
* @return list<QuestionnaireResponse>
|
|
*/
|
|
private function list(QuestionnaireResponseFilterDto $filter): array
|
|
{
|
|
$this->entityManager->flush();
|
|
|
|
return $this->repository->getListQuery(QuestionnaireCatalog::TEAMER_FEEDBACK, $filter)->getResult();
|
|
}
|
|
}
|