elementRepo = new FakeElementRepository(); $this->getElement = new GetElement($this->elementRepo); } public function testReturnsElementWhenFound(): void { $set = $this->createSet(1, 'Baderech'); $element = $this->createElement( $set, 'Baderech HaAvodah', 'A structured path for growth', '/assets/baderech-icon.png', '

A structured path for growth

', '/assets/pdfs/baderech.pdf', 'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s', null, ); $result = $this->getElement->execute(new GetElementRequest( id: $element->getId(), )); $foundElement = $result->getElement(); $this->assertInstanceOf(Element::class, $foundElement); $this->assertSame($element->getId(), $foundElement->getId()); $this->assertSame('Baderech HaAvodah', $foundElement->getTitle()); $this->assertSame( 'A structured path for growth', $foundElement->getDescription(), ); $this->assertSame( '/assets/baderech-icon.png', $foundElement->getIconImageUrl(), ); $this->assertSame( '

A structured path for growth

', $foundElement->getRichText(), ); $this->assertSame( '/assets/pdfs/baderech.pdf', $foundElement->getPdfPath(), ); $this->assertSame( 'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s', $foundElement->getYoutubeUrl(), ); } public function testReturnsDirectChildElements(): void { $set = $this->createSet(1, 'Baderech'); $parentElement = $this->createElement( $set, 'Baderech HaAvodah', 'A structured path for growth', null, '

A structured path for growth

', '/assets/pdfs/baderech.pdf', null, null, ); $firstChildElement = $this->createElement( $set, 'Avodah Foundations', 'Foundations for steady avodah', null, '

Foundations rich text

', '/assets/pdfs/foundations.pdf', null, $parentElement, ); $secondChildElement = $this->createElement( $set, 'Daily Practice', 'Daily practices for growth', null, '

Daily practice rich text

', null, null, $parentElement, ); $this->createElement( $set, 'Nested Practice', 'Nested description', null, '

Nested rich text

', null, null, $firstChildElement, ); $otherSet = $this->createSet(2, 'Daily Learning'); $otherParentElement = $this->createElement( $otherSet, 'Other Parent', 'Other parent description', null, '

Other parent rich text

', null, null, null, ); $this->createElement( $otherSet, 'Other Child', 'Other child description', null, '

Other child rich text

', null, null, $otherParentElement, ); $result = $this->getElement->execute(new GetElementRequest( id: $parentElement->getId(), )); $childElements = $result->getChildElements(); $this->assertCount(2, $childElements); $this->assertSame( $firstChildElement->getId(), $childElements[0]->getId(), ); $this->assertSame('Avodah Foundations', $childElements[0]->getTitle()); $this->assertSame( 'Foundations for steady avodah', $childElements[0]->getDescription(), ); $this->assertSame( $secondChildElement->getId(), $childElements[1]->getId(), ); $this->assertSame('Daily Practice', $childElements[1]->getTitle()); $this->assertSame( 'Daily practices for growth', $childElements[1]->getDescription(), ); } public function testThrowsWhenIdMissing(): void { $this->expectException(BadRequestException::class); $this->expectExceptionMessage('id is required'); $this->getElement->execute(new GetElementRequest(id: null)); } public function testThrowsWhenElementDoesNotExist(): void { $this->expectException(NotFoundException::class); $this->expectExceptionMessage('Element not found'); $this->getElement->execute(new GetElementRequest(id: 999)); } private function createSet(int $id, string $name): DomainSet { return new DomainSet( id: $id, name: $name, description: "$name description", iconImageUrl: '/assets/baderech-icon.png', ); } private function createElement( DomainSet $set, string $title, string $description, ?string $iconImageUrl, string $richText, ?string $pdfPath, ?string $youtubeUrl, ?Element $parentElement, ): Element { return $this->elementRepo->create(new CreateElementDto( set: $set, title: $title, description: $description, iconImageUrl: $iconImageUrl, richText: $richText, pdfPath: $pdfPath, youtubeUrl: $youtubeUrl, parentElement: $parentElement, )); } }