elementRepository = new FakeElementRepository(); $this->createChildElement = new CreateChildElement( $this->elementRepository, ); } public function testCreatesChildElementFromParentSet(): void { $parentElement = $this->createParentElement(); $childElement = $this->createChildElement->execute( new CreateChildElementRequest( parentElementId: $parentElement->getId(), title: 'Admin child', ) ); $this->assertSame('Admin child', $childElement->getTitle()); $this->assertSame('', $childElement->getDescription()); $this->assertNull($childElement->getIconImageUrl()); $this->assertSame('', $childElement->getRichText()); $this->assertNull($childElement->getShortPdfPath()); $this->assertNull($childElement->getLongPdfPath()); $this->assertNull($childElement->getYoutubeUrl()); $this->assertSame( $parentElement->getSet()->getId(), $childElement->getSet()->getId(), ); $this->assertSame( $parentElement->getId(), $childElement->getParentElement()->getId(), ); } public function testThrowsWhenParentElementIsMissing(): void { $this->expectException(NotFoundException::class); $this->expectExceptionMessage('Parent element not found'); $this->createChildElement->execute(new CreateChildElementRequest( parentElementId: 999, title: 'Missing parent child', )); } public function testThrowsWhenTitleIsMissing(): void { $parentElement = $this->createParentElement(); $this->expectException(BadRequestException::class); $this->expectExceptionMessage('title is required'); $this->createChildElement->execute(new CreateChildElementRequest( parentElementId: $parentElement->getId(), title: '', )); } private function createParentElement(): Element { $set = new DomainSet( id: 1, name: 'Baderech', description: 'Baderech description', iconImageUrl: '/assets/baderech-icon.png', ); return $this->elementRepository->create(new CreateElementDto( set: $set, title: 'Parent', description: 'Parent description', iconImageUrl: null, richText: '', shortPdfPath: null, longPdfPath: null, youtubeUrl: null, parentElement: null, )); } }