textRepo = new FakeTextRepository(); $this->nodeRepo = new FakeNodeRepository(); $this->userRepo = new FakeUserRepository(); $this->user = $this->userRepo->create(new CreateUserDto( email: new EmailAddress('a@b.com'), passwordHash: '', isAdmin: false, )); $this->useCase = new CreateText( $this->textRepo, $this->nodeRepo, ); } public function test_create_text(): void { $text = $this->useCase->execute(new CreateTextRequest( name: 'test', user: $this->user, )); $this->assertInstanceOf(TextRepository::class, $this->textRepo); $this->assertInstanceOf(Text::class, $text); $this->assertEquals('test', $text->getName()); } public function test_creates_root_node_on_text_creation(): void { $text = $this->useCase->execute(new CreateTextRequest( name: 'my text', user: $this->user, )); $nodes = $this->nodeRepo->findByTextId($text->getId()); $this->assertCount(1, $nodes); $rootNode = array_values($nodes)[0]; $this->assertEquals('my text', $rootNode->getTitle()); $this->assertNull($rootNode->getParentNode()); } public function test_text_belongs_to_user(): void { $text = $this->useCase->execute(new CreateTextRequest( name: 'my text', user: $this->user, )); $this->assertSame($this->user, $text->getUser()); $this->assertEquals($this->user->getId(), $text->getUser()->getId()); } public function test_throws_if_name_is_null(): void { $this->expectException(BadRequestException::class); $this->expectExceptionMessage('name is required'); $this->useCase->execute(new CreateTextRequest( name: null, user: $this->user, )); } public function test_throws_if_user_is_null(): void { $this->expectException(BadRequestException::class); $this->expectExceptionMessage('user is required'); $this->useCase->execute(new CreateTextRequest( name: 'name', user: null, )); } }