test assignment completion
This commit is contained in:
parent
8218de16f5
commit
916f070455
4 changed files with 378 additions and 3 deletions
49
backend/tests/Unit/Schedule/ScheduleAssignmentTest.php
Normal file
49
backend/tests/Unit/Schedule/ScheduleAssignmentTest.php
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Unit\Schedule;
|
||||
|
||||
use App\Schedule\ScheduleAssignment;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeZone;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ScheduleAssignmentTest extends TestCase
|
||||
{
|
||||
public function test_it_completes_only_once_until_reopened(): void
|
||||
{
|
||||
$assignment = $this->assignment();
|
||||
$firstCompletion = $this->utc('2026-08-15T12:00:00');
|
||||
$laterCompletion = $this->utc('2026-08-15T13:00:00');
|
||||
|
||||
$assignment->complete($firstCompletion);
|
||||
$assignment->complete($laterCompletion);
|
||||
|
||||
$this->assertSame($firstCompletion, $assignment->getCompletedAt());
|
||||
|
||||
$assignment->reopen();
|
||||
|
||||
$this->assertNull($assignment->getCompletedAt());
|
||||
|
||||
$assignment->complete($laterCompletion);
|
||||
|
||||
$this->assertSame($laterCompletion, $assignment->getCompletedAt());
|
||||
}
|
||||
|
||||
private function assignment(): ScheduleAssignment
|
||||
{
|
||||
return new ScheduleAssignment(
|
||||
id: 1,
|
||||
name: 'Lesson',
|
||||
kind: 'lesson',
|
||||
path: ['Course', 'Lesson'],
|
||||
scheduledDate: $this->utc('2026-08-15'),
|
||||
position: 1,
|
||||
completedAt: null,
|
||||
);
|
||||
}
|
||||
|
||||
private function utc(string $value): DateTimeImmutable
|
||||
{
|
||||
return new DateTimeImmutable($value, new DateTimeZone('UTC'));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue