planRepo = new FakePlanRepository(); $this->userRepo = new FakeUserRepository(); $this->textRepo = new FakeTextRepository(); $this->nodeRepo = new FakeNodeRepository(); $this->scheduledNodeRepo = new FakeScheduledNodeRepository(); $this->userRepo->create(new CreateUserDto( email: new EmailAddress('test@test.com'), )); $this->createScheduledNode = new CreateScheduledNode( scheduledNodeRepo: $this->scheduledNodeRepo, planRepo: $this->planRepo, ); $this->useCase = new CreatePlan( $this->planRepo, $this->userRepo, $this->textRepo, $this->nodeRepo, $this->createScheduledNode, ); } public function test_create_plan(): void { $plan = $this->useCase->execute(new CreatePlanRequest( userId: 0, name: 'testPlan', textId: 0, )); $this->assertEquals('testPlan', $plan->getName()); } public function test_plan_has_user(): void { $plan = $this->useCase->execute(new CreatePlanRequest( userId: 0, name: 'testPlan', textId: 0, )); $this->assertInstanceOf(User::class, $plan->getUser()); } public function test_nonexistant_user_id_throws(): void { $this->expectException(DomainException::class); $this->expectExceptionMessage("User with id: 1 doesnt exist"); $plan = $this->useCase->execute(new CreatePlanRequest( userId: 1, name: 'testPlan', textId: 0, )); } public function test_plan_schedules_nodes_on_creation(): void { $text = $this->textRepo->create(new CreateTextDto( name: 'testname', )); $this->nodeRepo->create(new CreateNodeDto( text: $text, title: 'testtitle', parentNode: null, )); $plan = $this->useCase->execute(new CreatePlanRequest( userId: 0, name: 'testPlan', textId: 0, )); $this->assertNotNull($this->scheduledNodeRepo->find(0)); } public function test_plan_only_schedules_nodes_which_arent_parents(): void { $text = $this->textRepo->create(new CreateTextDto( name: 'testname', )); $rootNode = $this->nodeRepo->create(new CreateNodeDto( text: $text, title: 'root node', parentNode: null, )); $this->nodeRepo->create(new CreateNodeDto( text: $text, title: 'child node', parentNode: $rootNode, )); $plan = $this->useCase->execute(new CreatePlanRequest( userId: 0, name: 'testPlan', textId: 0, )); $this->assertEquals( 1, $this->scheduledNodeRepo->getNumberOfTimesCreateCalled() ); } }