userRepo = new FakeUserRepository(); $this->scheduledNodeRepo = new FakeScheduledNodeRepository(); $this->planRepo = new FakePlanRepository(); $user = $this->userRepo->create(new CreateUserDto( email: new EmailAddress('email@email.com'), passwordHash: 'hash', isAdmin: false, )); $plan = $this->planRepo->create(new CreatePlanDto( name: 'test plan', user: $user, )); $this->scheduledNodeRepo->create(new CreateScheduledNodeDto( date: new DateTimeImmutable('2025-01-02'), plan: $plan, node: new Node( id: 0, title: 'test node', text: new Text(id: 0, name: 'test text'), parentNode: null, ), )); $this->useCase = new GetTodaysSchedule( userRepo: $this->userRepo, scheduledNodeRepo: $this->scheduledNodeRepo, ); } public function test_returns_array_of_scheduled_nodes(): void { $result = $this->useCase->execute(new GetTodaysScheduleRequest( date: '2025-01-02', userId: 0, )); $this->assertIsArray($result); $this->assertInstanceOf(ScheduledNode::class, $result[0]); } public function test_returns_all_unfinished_scheduled_nodes_up_until_today(): void { $this->scheduledNodeRepo->create(new CreateScheduledNodeDto( date: new DateTimeImmutable('2025-01-01'), plan: $this->planRepo->find(0), node: new Node( id: 0, title: 'test node', text: new Text(id: 0, name: 'test text'), parentNode: null, ), )); $result = $this->useCase->execute(new GetTodaysScheduleRequest( date: '2025-01-02', userId: 0, )); $this->assertEquals(2, count($result)); } public function test_only_returns_uncompleted_nodes(): void { $node = $this->scheduledNodeRepo->create( new CreateScheduledNodeDto( date: new DateTimeImmutable('2025-01-01'), plan: $this->planRepo->find(0), node: new Node( id: 0, title: 'test node', text: new Text(id: 0, name: 'test text'), parentNode: null, ), ) ); $node->setCompleted(true); $this->scheduledNodeRepo->update($node); $result = $this->useCase->execute(new GetTodaysScheduleRequest( date: '2025-01-02', userId: 0, )); $this->assertEquals(1, count($result)); } public function test_throws_if_date_is_null(): void { $this->expectException(BadRequestException::class); $this->expectExceptionMessage('date is required'); $this->useCase->execute(new GetTodaysScheduleRequest( date: null, userId: 0, )); } public function test_throws_if_user_id_is_null(): void { $this->expectException(BadRequestException::class); $this->expectExceptionMessage('userId is required'); $this->useCase->execute(new GetTodaysScheduleRequest( date: '2025-01-02', userId: null, )); } public function test_nonexistant_user_throws(): void { $this->expectException(DomainException::class); $this->expectExceptionMessage('User with id: 99 doesnt exist'); $this->useCase->execute(new GetTodaysScheduleRequest( date: '2025-01-02', userId: 99, )); } }