tasks = new FakeTaskQueries; $this->entries = new InMemoryTimeEntryRepository; $booking = new TimeBooking($this->tasks, $this->entries); $transactions = new FakeTransactionManager; $this->setDayHours = new SetDayHours($this->entries, $booking, $transactions); $this->addTaskHours = new AddTaskHours($this->entries, $booking, $transactions); $this->updateEntry = new UpdateTimeEntry($this->entries, $booking, $transactions); $this->removeEntry = new RemoveTimeEntry($this->entries, $booking, $transactions); $this->tasks->addTask(1); $this->tasks->addTask(2); $this->tasks->addTask(3, jobStatus: JobStatus::Done); }); it('parses hours in quarters, with a comma or a point', function (string $input, ?string $formatted) { expect(WorkedHours::parse($input)?->format())->toBe($formatted); })->with([ 'quarter' => ['0,25', '0,25'], 'comma' => ['7,5', '7,5'], 'point' => ['7.50', '7,5'], 'whole day' => ['24', '24'], 'empty' => ['', null], ]); it('rejects hours that are not quarters or out of range', function (string $input) { WorkedHours::parse($input); })->throws(InvalidWorkedHours::class)->with(['0,1', '24,25', '-1', 'kaksi', '0']); it('adds hours and continues the note of a day entry', function () { $entry = TimeEntry::create(10, 1, 1, 7, new DateTimeImmutable('2026-05-18'), new WorkedHours(8), 'Luonnokset'); $entry->addHours(new WorkedHours(2), 'Korjaukset'); $entry->addHours(new WorkedHours(1), ' '); expect($entry->hours()->format())->toBe('2,75') ->and($entry->note())->toBe("Luonnokset\nKorjaukset"); }); it('sets a cell, changes it and clears it', function () { $this->setDayHours->execute(10, 1, '2026-05-18', '2,5'); $this->setDayHours->execute(10, 1, '2026-05-18', '3'); expect($this->entries->entries)->toHaveCount(1) ->and(array_values($this->entries->entries)[0]->hours()->format())->toBe('3') ->and(array_values($this->entries->entries)[0]->workTypeId())->toBe(7); $this->setDayHours->execute(10, 1, '2026-05-18', '0'); expect($this->entries->entries)->toBeEmpty(); $this->setDayHours->execute(10, 1, '2026-05-18', ''); expect($this->entries->entries)->toBeEmpty(); }); it('adds hours from the task page to the day entry', function () { $this->addTaskHours->execute(10, 1, '2026-05-18', '2', 'Aamu'); $total = $this->addTaskHours->execute(10, 1, '2026-05-18', '1,5', 'Iltapäivä'); expect($total)->toBe('3,5') ->and($this->entries->entries)->toHaveCount(1); }); it('keeps a day within 24 hours across tasks', function () { $this->setDayHours->execute(10, 1, '2026-05-18', '20'); expect(fn () => $this->setDayHours->execute(10, 2, '2026-05-18', '4,25'))->toThrow(DailyHoursExceeded::class); $this->setDayHours->execute(10, 2, '2026-05-18', '4'); $this->setDayHours->execute(10, 1, '2026-05-18', '19'); $this->setDayHours->execute(11, 1, '2026-05-18', '8'); expect($this->entries->quartersOn(10, new DateTimeImmutable('2026-05-18')))->toBe(92); }); it('does not record or change hours on a locked job or an unknown task', function () { expect(fn () => $this->setDayHours->execute(10, 3, '2026-05-18', '1'))->toThrow(TimeLocked::class) ->and(fn () => $this->addTaskHours->execute(10, 99, '2026-05-18', '1'))->toThrow(TaskNotBookable::class); $this->setDayHours->execute(10, 1, '2026-05-18', '2'); $entryId = array_key_first($this->entries->entries); $this->tasks->addTask(1, jobStatus: JobStatus::Invoiced); expect(fn () => $this->updateEntry->execute(10, $entryId, '3', null))->toThrow(TimeLocked::class) ->and(fn () => $this->removeEntry->execute(10, $entryId))->toThrow(TimeLocked::class) ->and($this->entries->entries)->toHaveCount(1); }); it('lets users change only their own entries', function () { $this->setDayHours->execute(10, 1, '2026-05-18', '2'); $entryId = array_key_first($this->entries->entries); expect(fn () => $this->updateEntry->execute(11, $entryId, '3', null))->toThrow(TimeEntryNotFound::class) ->and(fn () => $this->removeEntry->execute(11, $entryId))->toThrow(TimeEntryNotFound::class); $this->updateEntry->execute(10, $entryId, '3,75', 'Muutettu'); expect($this->entries->entries[$entryId]->hours()->format())->toBe('3,75') ->and($this->entries->entries[$entryId]->note())->toBe('Muutettu'); $this->removeEntry->execute(10, $entryId); expect($this->entries->entries)->toBeEmpty(); });