feat: additional functionality and layout adjustments for season teamers

This commit is contained in:
fromme committed 2026-09-26 12:13:16 +02:00
1 parent 80c6016da3
commit 4cab57d136
30 files changed
+916 -192

No files matched your search

@@ -57,6 +57,30 @@ class SeasonAssignmentTaskRepositoryTest extends KernelTestCase
$this->assertStringContainsString('season_assignment.dateFrom <= :windowEnd', $scoped);
}
/**
* What the propagate action may still rewrite: an entry that is not ticked off, on an
* assignment that has not ended. A finished entry keeps the document it handed out.
*/
public function testPropagationSkipsTickedEntriesAndEndedAssignments(): void
{
/** @var EntityManagerInterface $entityManager */
$entityManager = static::getContainer()->get(EntityManagerInterface::class);
/** @var SeasonAssignmentTaskRepository $repository */
$repository = $entityManager->getRepository(SeasonAssignmentTask::class);
$dql = $repository
->createOpenForTaskQueryBuilder('contract', new \DateTimeImmutable('2026-11-01'))
->getQuery()
->getDQL()
;
$this->assertStringContainsString('task.taskKey = :taskKey', $dql);
$this->assertStringContainsString('task.done = :done', $dql);
$this->assertStringContainsString('season_assignment.dateTo >= :today', $dql);
$this->assertStringContainsString('season_assignment.deletedAt IS NULL', $dql);
}
private function createOpenQueryBuilder(
?\DateTimeImmutable $windowStart = null,
?\DateTimeImmutable $windowEnd = null,
@@ -185,21 +185,6 @@ class SeasonTaskReminderServiceTest extends TestCase
$this->service->sendTeamerDigest($this->monday());
}
/**
* The flag is the office's own note and silences nothing: only ticking the entry off does.
*/
public function testDoneTeamerDoesNotSuppressTheDigest(): void
{
$task = $this->task('2026-11-01');
$task->getSeasonAssignment()->setDoneTeamer(true);
$this->repository->method('findOpen')->willReturn([$task]);
$this->mailer->expects($this->once())->method('createAndSendText');
$this->service->sendTeamerDigest($this->monday());
}
private function monday(): \DateTimeImmutable
{
// 2026-10-05 is a monday, and inside the season the digest is scoped to
@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
namespace App\Tests\Service\Season;
use App\Config\SeasonTask;
use App\Entity\SeasonAssignment;
use App\Entity\SeasonAssignmentTask;
use App\Entity\Upload;
use App\Service\Season\SeasonChecklistBuilder;
use App\Service\Season\SeasonTaskDeadlineResolver;
use PHPUnit\Framework\TestCase;
/**
* The row hands out what it was given, not what the library holds right now - that is what keeps
* a finished assignment from being rewritten when next season's file is deposited.
*/
class SeasonChecklistBuilderTest extends TestCase
{
public function testTheRowHandsOutItsOwnDocument(): void
{
$document = new Upload();
$seasonAssignment = new SeasonAssignment();
$seasonAssignment->addTask(
(new SeasonAssignmentTask())
->setTaskKey(SeasonTask::MASTER_DATA->value)
->setDocument($document)
);
$builder = new SeasonChecklistBuilder($this->createMock(SeasonTaskDeadlineResolver::class));
$rows = $builder->build($seasonAssignment);
$this->assertCount(1, $rows);
$this->assertSame($document, $rows[0]['document']);
}
public function testARowWithoutADocumentIsBuiltAllTheSame(): void
{
$seasonAssignment = new SeasonAssignment();
$seasonAssignment->addTask(
(new SeasonAssignmentTask())->setTaskKey(SeasonTask::MASTER_DATA->value)
);
$builder = new SeasonChecklistBuilder($this->createMock(SeasonTaskDeadlineResolver::class));
$rows = $builder->build($seasonAssignment);
$this->assertCount(1, $rows);
$this->assertNull($rows[0]['document']);
}
}
@@ -0,0 +1,99 @@
<?php
declare(strict_types=1);
namespace App\Tests\Service\Season;
use App\Config\SeasonChecklistStatus;
use App\Config\SeasonTask;
use App\Entity\SeasonAssignment;
use App\Entity\SeasonAssignmentTask;
use App\Service\Season\SeasonChecklistBuilder;
use App\Service\Season\SeasonTaskDeadlineResolver;
use PHPUnit\Framework\TestCase;
/**
* The status the detail page shows instead of the removed done_teamer flag. It is derived, so
* the whole point is which combination of rows produces which stage - no database needed.
*/
class SeasonChecklistStatusTest extends TestCase
{
private SeasonChecklistBuilder $builder;
protected function setUp(): void
{
$this->builder = new SeasonChecklistBuilder($this->createMock(SeasonTaskDeadlineResolver::class));
}
public function testItIsOpenWhileAnEntryRequiringAReturnIsOpen(): void
{
$seasonAssignment = $this->assignmentWithAllTasks();
$this->assertSame(SeasonChecklistStatus::OPEN, $this->builder->status($seasonAssignment));
}
public function testItIsOpenWhenOnlyOfficeInternalEntriesAreDone(): void
{
$seasonAssignment = $this->assignmentWithAllTasks();
$this->markDone($seasonAssignment, static fn (SeasonTask $task): bool => false === $task->requiresReturn());
$this->assertSame(SeasonChecklistStatus::OPEN, $this->builder->status($seasonAssignment));
}
public function testReturnsAreCompleteWhileAnOfficeInternalEntryIsOpen(): void
{
$seasonAssignment = $this->assignmentWithAllTasks();
$this->markDone($seasonAssignment, static fn (SeasonTask $task): bool => $task->requiresReturn());
$this->assertSame(SeasonChecklistStatus::RETURNS_COMPLETE, $this->builder->status($seasonAssignment));
}
public function testItIsCompleteOnceEveryEntryIsDone(): void
{
$seasonAssignment = $this->assignmentWithAllTasks();
$this->markDone($seasonAssignment, static fn (SeasonTask $task): bool => true);
$this->assertSame(SeasonChecklistStatus::COMPLETE, $this->builder->status($seasonAssignment));
}
/**
* A row of an entry that was removed from the enum would otherwise keep the assignment
* unfinished forever, so it is skipped here just like everywhere else.
*/
public function testItIgnoresRowsWhoseEntryNoLongerExists(): void
{
$seasonAssignment = $this->assignmentWithAllTasks();
$this->markDone($seasonAssignment, static fn (SeasonTask $task): bool => true);
$seasonAssignment->addTask((new SeasonAssignmentTask())->setTaskKey('removed_entry'));
$this->assertSame(SeasonChecklistStatus::COMPLETE, $this->builder->status($seasonAssignment));
}
private function assignmentWithAllTasks(): SeasonAssignment
{
$seasonAssignment = new SeasonAssignment();
foreach (SeasonTask::cases() as $case) {
$seasonAssignment->addTask((new SeasonAssignmentTask())->setTaskKey($case->value));
}
return $seasonAssignment;
}
/**
* @param callable(SeasonTask): bool $matches
*/
private function markDone(SeasonAssignment $seasonAssignment, callable $matches): void
{
foreach ($seasonAssignment->getTasks() as $task) {
if (null !== $definition = $task->getTask()) {
$task->setDone($matches($definition));
}
}
}
}
@@ -7,6 +7,9 @@ namespace App\Tests\Service\Season;
use App\Config\SeasonTask;
use App\Entity\SeasonAssignment;
use App\Entity\SeasonAssignmentTask;
use App\Entity\SeasonTaskDocument;
use App\Entity\Upload;
use App\Repository\SeasonTaskDocumentRepository;
use App\Service\Season\SeasonTaskSynchronizer;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\MockObject\MockObject;
@@ -20,12 +23,18 @@ use PHPUnit\Framework\TestCase;
class SeasonTaskSynchronizerTest extends TestCase
{
private EntityManagerInterface&MockObject $entityManager;
private SeasonTaskDocumentRepository&MockObject $seasonTaskDocumentRepository;
private SeasonTaskSynchronizer $synchronizer;
protected function setUp(): void
{
$this->entityManager = $this->createMock(EntityManagerInterface::class);
$this->synchronizer = new SeasonTaskSynchronizer($this->entityManager);
$this->seasonTaskDocumentRepository = $this->createMock(SeasonTaskDocumentRepository::class);
$this->synchronizer = new SeasonTaskSynchronizer(
$this->entityManager,
$this->seasonTaskDocumentRepository
);
}
public function testItCreatesOneRowPerEntryInEnumOrder(): void
@@ -89,6 +98,109 @@ class SeasonTaskSynchronizerTest extends TestCase
$this->assertContains('entry_removed_from_the_enum', $this->keysOf($seasonAssignment));
}
public function testAnEntryHandingOutADepositedDocumentStartsTickedForTheOffice(): void
{
$this->depositDocumentsFor(SeasonTask::MASTER_DATA);
$seasonAssignment = new SeasonAssignment();
$this->synchronizer->sync($seasonAssignment);
$this->assertSame([SeasonTask::MASTER_DATA->value], $this->officeDoneKeysOf($seasonAssignment));
}
/**
* The row keeps the file it was given. Replacing the library document later is what the next
* season gets, and what the propagate action carries over by hand - never a read of this row.
*/
public function testTheDocumentIsCopiedOntoTheRow(): void
{
$document = new Upload();
$this->depositDocuments([SeasonTask::MASTER_DATA], $document);
$seasonAssignment = new SeasonAssignment();
$this->synchronizer->sync($seasonAssignment);
foreach ($seasonAssignment->getTasks() as $task) {
$this->assertSame(
SeasonTask::MASTER_DATA->value === $task->getTaskKey() ? $document : null,
$task->getDocument(),
sprintf('Entry "%s" was given the wrong document.', $task->getTaskKey())
);
}
}
/**
* The entry hands a document out, it is just not deposited yet - so the office still has to
* put it together and the row starts open.
*/
public function testAnEntryWithoutADepositedDocumentStartsOpen(): void
{
$this->depositDocumentsFor();
$seasonAssignment = new SeasonAssignment();
$this->synchronizer->sync($seasonAssignment);
$this->assertSame([], $this->officeDoneKeysOf($seasonAssignment));
}
public function testThePreTickNeverOverwritesAnExistingRow(): void
{
$this->depositDocumentsFor(SeasonTask::MASTER_DATA);
$seasonAssignment = new SeasonAssignment();
$seasonAssignment->addTask(
(new SeasonAssignmentTask())->setTaskKey(SeasonTask::MASTER_DATA->value)
);
$this->synchronizer->sync($seasonAssignment);
$this->assertSame(
[],
$this->officeDoneKeysOf($seasonAssignment),
'The office unticked this row, and the next sync has to leave it alone.'
);
}
private function depositDocumentsFor(SeasonTask ...$tasks): void
{
$this->depositDocuments($tasks, new Upload());
}
/**
* @param SeasonTask[] $tasks
*/
private function depositDocuments(array $tasks, Upload $document): void
{
$documents = [];
foreach ($tasks as $task) {
$documents[$task->value] = (new SeasonTaskDocument())
->setTaskKey($task->value)
->setDocument($document)
;
}
$this->seasonTaskDocumentRepository->method('findIndexedByTaskKey')->willReturn($documents);
}
/**
* @return string[]
*/
private function officeDoneKeysOf(SeasonAssignment $seasonAssignment): array
{
return array_values(array_map(
static fn (SeasonAssignmentTask $task): string => $task->getTaskKey(),
array_filter(
$seasonAssignment->getTasks()->toArray(),
static fn (SeasonAssignmentTask $task): bool => $task->isOfficeDone()
)
));
}
/**
* @return string[]
*/