63 lines
1.9 KiB
PHP
63 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Model;
|
|
|
|
use App\Entity\ApplicationFormSubmission;
|
|
use App\Model\ApplicationFormSubmissionCallsDto;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class ApplicationFormSubmissionCallsDtoTest extends TestCase
|
|
{
|
|
public function testTickingABoxStampsToday(): void
|
|
{
|
|
$submission = $this->submission();
|
|
|
|
$dto = new ApplicationFormSubmissionCallsDto($submission);
|
|
$dto->setFirstCallHeld(true)->applyToSubmission();
|
|
|
|
$this->assertSame(
|
|
(new \DateTimeImmutable('today'))->format('Y-m-d'),
|
|
$submission->getFirstCallHeldAt()?->format('Y-m-d')
|
|
);
|
|
$this->assertNull($submission->getSecondCallHeldAt());
|
|
}
|
|
|
|
/**
|
|
* The reason the DTO exists: saving the form again must not move a call from the day it
|
|
* happened to today.
|
|
*/
|
|
public function testAnAlreadyHeldCallKeepsItsDate(): void
|
|
{
|
|
$held = new \DateTimeImmutable('2026-09-01');
|
|
$submission = $this->submission()->setFirstCallHeldAt($held);
|
|
|
|
$dto = new ApplicationFormSubmissionCallsDto($submission);
|
|
$this->assertTrue($dto->isFirstCallHeld());
|
|
|
|
$dto->applyToSubmission();
|
|
|
|
$this->assertSame($held, $submission->getFirstCallHeldAt());
|
|
}
|
|
|
|
public function testUntickingClearsTheDate(): void
|
|
{
|
|
$submission = $this->submission()->setSecondCallHeldAt(new \DateTimeImmutable('2026-09-01'));
|
|
|
|
$dto = new ApplicationFormSubmissionCallsDto($submission);
|
|
$dto->setSecondCallHeld(false)->applyToSubmission();
|
|
|
|
$this->assertNull($submission->getSecondCallHeldAt());
|
|
}
|
|
|
|
private function submission(): ApplicationFormSubmission
|
|
{
|
|
return new ApplicationFormSubmission(
|
|
'applicationform',
|
|
'Bewerbungsformular',
|
|
new \DateTimeImmutable('2026-09-22T12:30:00+02:00')
|
|
);
|
|
}
|
|
}
|