Files
myep-team/tests/Repository/AssignmentRepositoryTest.php
T

95 lines
3.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Repository;
use App\Entity\Assignment;
use App\Entity\Disposition;
use App\Model\AssignmentFilterDto;
use App\Model\TimelineFilterDto;
use App\Repository\AssignmentRepository;
use Carbon\CarbonPeriodImmutable;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
/**
* The slot counting behind every teamer facing assignment list lives in DQL, so the query is
* compiled here and the parts carrying the semantics are pinned.
*/
class AssignmentRepositoryTest extends KernelTestCase
{
public function testAvailableAssignmentsQueryIgnoresCalledOffDispositions(): void
{
$dql = $this->createAvailableAssignmentsIdsQuery()->getDQL();
// the exclusion has to live in the JOIN condition: moved into the WHERE clause it would
// drop assignments without any disposition at all
$this->assertStringContainsString(
'LEFT JOIN assignment.dispositions disposition WITH disposition.status <> :dispositionCalledOff',
$dql
);
$this->assertStringContainsString(
'HAVING assignment.availableDispositions > COUNT(disposition.id)',
$dql
);
}
public function testAvailableAssignmentsQueryBindsTheCalledOffStatuses(): void
{
$query = $this->createAvailableAssignmentsIdsQuery();
$this->assertSame(
Disposition::STATUS_CALLED_OFF,
$query->getParameter('dispositionCalledOff')->getValue()
);
$this->assertSame(
[Assignment::STATUS_DRAFT, Assignment::STATUS_CALLED_OFF],
$query->getParameter('status')->getValue()
);
}
/**
* The timeline keeps every trip touching its window, so a team on site stays visible when
* the window starts today.
*/
public function testTimelineDateFilterKeepsOverlappingTrips(): void
{
$filterDto = (new TimelineFilterDto())
->setPeriod(CarbonPeriodImmutable::create('2026-11-12', '2026-12-31'))
;
$dql = $this->getRepository()->getListQuery($filterDto)->getDQL();
$this->assertStringContainsString('destination.dateTo >= :dateFrom', $dql);
$this->assertStringContainsString('destination.dateFrom <= :dateTo', $dql);
}
public function testListDateFilterKeepsTripsInsideTheDates(): void
{
$filterDto = (new AssignmentFilterDto())
->setDateFrom(new \DateTimeImmutable('2026-11-12'))
->setDateTo(new \DateTimeImmutable('2026-12-31'))
;
$dql = $this->getRepository()->getListQuery($filterDto)->getDQL();
$this->assertStringContainsString('destination.dateFrom >= :dateFrom', $dql);
$this->assertStringContainsString('destination.dateTo <= :dateTo', $dql);
}
private function createAvailableAssignmentsIdsQuery(): Query
{
return $this->getRepository()->getAvailableAssignmentsIdsQuery();
}
private function getRepository(): AssignmentRepository
{
/** @var EntityManagerInterface $entityManager */
$entityManager = static::getContainer()->get(EntityManagerInterface::class);
return $entityManager->getRepository(Assignment::class);
}
}