61 lines
2.0 KiB
PHP
61 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Repository;
|
|
|
|
use App\Entity\Assignment;
|
|
use App\Entity\Disposition;
|
|
use App\Repository\AssignmentRepository;
|
|
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()
|
|
);
|
|
}
|
|
|
|
private function createAvailableAssignmentsIdsQuery(): Query
|
|
{
|
|
/** @var EntityManagerInterface $entityManager */
|
|
$entityManager = static::getContainer()->get(EntityManagerInterface::class);
|
|
|
|
/** @var AssignmentRepository $repository */
|
|
$repository = $entityManager->getRepository(Assignment::class);
|
|
|
|
return $repository->getAvailableAssignmentsIdsQuery();
|
|
}
|
|
}
|