feat: additional functionality and layout adjustments for season teamers
This commit is contained in:
1 parent
80c6016da3
commit
4cab57d136
30 files changed
+916
-192
No files matched your search
@@ -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[]
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user