100 lines
3.2 KiB
PHP
100 lines
3.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Service\Cron;
|
|
|
|
use App\Entity\Application;
|
|
use App\Entity\Assignment;
|
|
use App\Entity\Disposition;
|
|
use App\Entity\Teamer;
|
|
use App\Repository\DispositionRepository;
|
|
use App\Service\Cron\DispositionStatusService;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Psr\Log\NullLogger;
|
|
|
|
/**
|
|
* Where a placement lands once its assignment is over.
|
|
*
|
|
* The normal one stops at `ended`, which is what opens the invoice step. A skip-formalities
|
|
* placement has no invoice step to open, so ending it means it is done - anything else would
|
|
* park it in `ended` forever and keep asking the teamer for a Honorarnote nobody wants.
|
|
*/
|
|
class DispositionStatusServiceTest extends TestCase
|
|
{
|
|
private DispositionRepository&MockObject $repository;
|
|
private DispositionStatusService $service;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->repository = $this->createMock(DispositionRepository::class);
|
|
|
|
$entityManager = $this->createMock(EntityManagerInterface::class);
|
|
$entityManager
|
|
->method('getRepository')
|
|
->willReturn($this->repository)
|
|
;
|
|
|
|
$this->service = new DispositionStatusService($entityManager, new NullLogger());
|
|
}
|
|
|
|
public function testANormalPlacementEnds(): void
|
|
{
|
|
$disposition = $this->createDisposition(skipFormalities: false);
|
|
|
|
$this->givenEndedDispositions($disposition);
|
|
$this->service->setEndedStatus();
|
|
|
|
$this->assertSame(Disposition::STATUS_ENDED, $disposition->getStatus());
|
|
}
|
|
|
|
public function testASkipFormalitiesPlacementIsCompletedInsteadOfEnded(): void
|
|
{
|
|
$disposition = $this->createDisposition(skipFormalities: true);
|
|
|
|
$this->givenEndedDispositions($disposition);
|
|
$this->service->setEndedStatus();
|
|
|
|
$this->assertSame(Disposition::STATUS_COMPLETED, $disposition->getStatus());
|
|
}
|
|
|
|
/**
|
|
* Both kinds come out of the same query, so the split has to happen per disposition.
|
|
*/
|
|
public function testAMixedBatchIsSplitPerDisposition(): void
|
|
{
|
|
$normal = $this->createDisposition(skipFormalities: false);
|
|
$skipped = $this->createDisposition(skipFormalities: true);
|
|
|
|
$this->givenEndedDispositions($normal, $skipped);
|
|
$this->service->setEndedStatus();
|
|
|
|
$this->assertSame(Disposition::STATUS_ENDED, $normal->getStatus());
|
|
$this->assertSame(Disposition::STATUS_COMPLETED, $skipped->getStatus());
|
|
}
|
|
|
|
public function testNothingIsFlushedWhenThereIsNothingToEnd(): void
|
|
{
|
|
$this->givenEndedDispositions();
|
|
|
|
$this->assertSame('No ended dispositions to update', $this->service->setEndedStatus());
|
|
}
|
|
|
|
private function givenEndedDispositions(Disposition ...$dispositions): void
|
|
{
|
|
$this->repository
|
|
->method('findEndedDispositions')
|
|
->willReturn($dispositions)
|
|
;
|
|
}
|
|
|
|
private function createDisposition(bool $skipFormalities): Disposition
|
|
{
|
|
$assignment = (new Assignment())->setSkipFormalities($skipFormalities);
|
|
|
|
return new Disposition(new Application($assignment, new Teamer()));
|
|
}
|
|
}
|