| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- declare(strict_types=1);
- namespace App\Tests\Repositories;
- use App\Domain\SprintWeek;
- use App\Repositories\SprintRepository;
- use App\Repositories\SprintWeekRepository;
- use App\Tests\TestCase;
- /**
- * Phase 12: per-week weekday selection drives Arbeitstage.
- */
- final class SprintWeekRepositoryTest extends TestCase
- {
- /** @return array{SprintRepository, SprintWeekRepository, int} */
- private function seedSprint(): array
- {
- $pdo = $this->makeDb();
- $sprints = new SprintRepository($pdo);
- $weeks = new SprintWeekRepository($pdo);
- $sprint = $sprints->create('S', '2026-01-05', '2026-01-30', 0.2);
- $sprints->materializeWeeks($sprint->id, '2026-01-05', 4);
- return [$sprints, $weeks, $sprint->id];
- }
- public function testMaterializeWeeksDefaultsToAllFiveDays(): void
- {
- [, $weeks, $sprintId] = $this->seedSprint();
- $rows = $weeks->allForSprint($sprintId);
- $this->assertCount(4, $rows);
- foreach ($rows as $w) {
- $this->assertSame(SprintWeek::MASK_ALL, $w->activeDaysMask);
- $this->assertSame(5.0, $w->maxWorkingDays);
- }
- }
- public function testUpdateActiveDaysWritesBothColumns(): void
- {
- [, $weeks, $sprintId] = $this->seedSprint();
- $first = $weeks->allForSprint($sprintId)[0];
- $result = $weeks->updateActiveDays($first->id, 0b01111); // drop Fr
- $this->assertSame(SprintWeek::MASK_ALL, $result['before']->activeDaysMask);
- $this->assertSame(0b01111, $result['after']->activeDaysMask);
- $this->assertSame(4.0, $result['after']->maxWorkingDays);
- // Second query hydrates the same row from disk.
- $reloaded = $weeks->find($first->id);
- $this->assertNotNull($reloaded);
- $this->assertSame(0b01111, $reloaded->activeDaysMask);
- $this->assertSame(4.0, $reloaded->maxWorkingDays);
- }
- public function testUpdateActiveDaysClampsBitsOutsideMoFr(): void
- {
- [, $weeks, $sprintId] = $this->seedSprint();
- $first = $weeks->allForSprint($sprintId)[0];
- $result = $weeks->updateActiveDays($first->id, 0xFF);
- $this->assertSame(SprintWeek::MASK_ALL, $result['after']->activeDaysMask);
- $this->assertSame(5.0, $result['after']->maxWorkingDays);
- }
- public function testUpdateActiveDaysToEmptyMaskZeroesCount(): void
- {
- [, $weeks, $sprintId] = $this->seedSprint();
- $first = $weeks->allForSprint($sprintId)[0];
- $result = $weeks->updateActiveDays($first->id, 0);
- $this->assertSame(0, $result['after']->activeDaysMask);
- $this->assertSame(0.0, $result['after']->maxWorkingDays);
- $this->assertSame([], $result['after']->activeDays());
- }
- public function testSyncCountAppendsWeeksWithAllDaysActive(): void
- {
- [, $weeks, $sprintId] = $this->seedSprint();
- $diff = $weeks->syncCount($sprintId, '2026-01-05', 6);
- $this->assertCount(2, $diff['added']);
- foreach ($diff['added'] as $w) {
- $this->assertSame(SprintWeek::MASK_ALL, $w->activeDaysMask);
- $this->assertSame(5.0, $w->maxWorkingDays);
- }
- }
- }
|