fix: called-off dispositions no longer block teamers

This commit is contained in:
Björn Fromme
2026-08-26 09:11:27 +02:00
committed by fromme
parent cc280907e5
commit f3eae5462d
8 changed files with 186 additions and 20 deletions
+75
View File
@@ -0,0 +1,75 @@
<?php
declare(strict_types=1);
namespace App\Tests\Entity;
use App\Entity\Application;
use App\Entity\Assignment;
use App\Entity\Disposition;
use App\Entity\Teamer;
use PHPUnit\Framework\TestCase;
/**
* A called-off teamer is free again: the teamer views ask the assignment for the teamer's
* disposition to decide between "eingeteilt" and the application button, so a called-off
* disposition must not be handed out there.
*/
class AssignmentTest extends TestCase
{
public function testTheActiveDispositionOfATeamerIsReturned(): void
{
$assignment = new Assignment();
$teamer = new Teamer();
$disposition = $this->createDisposition($assignment, $teamer);
$this->assertSame($disposition, $assignment->getActiveDispositionByTeamer($teamer));
}
public function testACalledOffDispositionIsNotReturned(): void
{
$assignment = new Assignment();
$teamer = new Teamer();
$this
->createDisposition($assignment, $teamer)
->setStatus(Disposition::STATUS_CALLED_OFF)
;
$this->assertNull($assignment->getActiveDispositionByTeamer($teamer));
}
public function testTheDispositionOfAnotherTeamerIsNotReturned(): void
{
$assignment = new Assignment();
$this->createDisposition($assignment, new Teamer());
$this->assertNull($assignment->getActiveDispositionByTeamer(new Teamer()));
}
/**
* A teamer can be called off and disposed again on the same assignment, so both dispositions
* live side by side - the active one has to win.
*/
public function testTheActiveDispositionWinsOverACalledOffOne(): void
{
$assignment = new Assignment();
$teamer = new Teamer();
$this
->createDisposition($assignment, $teamer)
->setStatus(Disposition::STATUS_CALLED_OFF)
;
$disposition = $this->createDisposition($assignment, $teamer);
$this->assertSame($disposition, $assignment->getActiveDispositionByTeamer($teamer));
}
private function createDisposition(Assignment $assignment, Teamer $teamer): Disposition
{
$disposition = new Disposition(new Application($assignment, $teamer));
$assignment->addDisposition($disposition);
return $disposition;
}
}
@@ -0,0 +1,60 @@
<?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();
}
}