Files
myep-team/tests/Entity/DispositionTest.php
T

97 lines
3.5 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Entity;
use App\Entity\Application;
use App\Entity\Assignment;
use App\Entity\Destination;
use App\Entity\Disposition;
use App\Entity\Teamer;
use App\Entity\Upload;
use PHPUnit\Framework\TestCase;
/**
* The two "document is due" flags on the teamer dashboard. Both rest on CarbonPeriodImmutable,
* whose isStarted() stays true once the period has begun - which is right for one of them and
* was a bug in the other, so the difference is pinned here.
*/
class DispositionTest extends TestCase
{
private const CONTRACT_DEADLINE_DAYS = 5;
private const INVOICE_DEADLINE_DAYS = 14;
public function testTheContractIsNotDueBeforeTheUploadPeriodHasRunOut(): void
{
$disposition = $this->createDisposition(createdAt: 'today -2 days', assignmentEndsIn: '+30 days');
$this->assertFalse($disposition->isContractDue(self::CONTRACT_DEADLINE_DAYS));
}
public function testTheContractIsDueOnceTheUploadPeriodHasRunOut(): void
{
$disposition = $this->createDisposition(createdAt: 'today -6 days', assignmentEndsIn: '+30 days');
$this->assertTrue($disposition->isContractDue(self::CONTRACT_DEADLINE_DAYS));
}
/**
* The upload is blocked from the day before the assignment ends, so past that point the
* dashboard would be asking for something the workflow guard refuses.
*/
public function testTheContractStopsBeingDueOnceTheUploadIsBlocked(): void
{
$disposition = $this->createDisposition(createdAt: 'today -60 days', assignmentEndsIn: '+1 day');
$this->assertFalse($disposition->isContractDue(self::CONTRACT_DEADLINE_DAYS));
}
public function testAnUploadedContractIsNeverDue(): void
{
$disposition = $this->createDisposition(createdAt: 'today -60 days', assignmentEndsIn: '+30 days');
$disposition->addDocument((new Upload())->setType(Upload::TYPE_CONTRACT));
$this->assertFalse($disposition->isContractDue(self::CONTRACT_DEADLINE_DAYS));
}
public function testTheInvoiceIsNotDueWhileTheAssignmentIsStillRunning(): void
{
$disposition = $this->createDisposition(createdAt: 'today -30 days', assignmentEndsIn: '+5 days');
$this->assertFalse($disposition->isInvoiceDue(self::INVOICE_DEADLINE_DAYS));
}
public function testTheInvoiceIsDueOnceTheAssignmentHasEnded(): void
{
$disposition = $this->createDisposition(createdAt: 'today -30 days', assignmentEndsIn: '-1 day');
$this->assertTrue($disposition->isInvoiceDue(self::INVOICE_DEADLINE_DAYS));
}
/**
* Nothing blocks a late invoice upload, so unlike the contract this must keep asking.
*/
public function testTheInvoiceStaysDueAfterTheUploadPeriodHasRunOut(): void
{
$disposition = $this->createDisposition(createdAt: 'today -90 days', assignmentEndsIn: '-60 days');
$this->assertTrue($disposition->isInvoiceDue(self::INVOICE_DEADLINE_DAYS));
}
private function createDisposition(string $createdAt, string $assignmentEndsIn): Disposition
{
$destination = (new Destination())
->setProduct('Skireise')
->setDateFrom(new \DateTimeImmutable($assignmentEndsIn.' -7 days'))
->setDateTo(new \DateTimeImmutable($assignmentEndsIn))
;
$disposition = new Disposition(
new Application((new Assignment())->setDestination($destination), new Teamer())
);
return $disposition->setCreatedAt(new \DateTimeImmutable($createdAt));
}
}