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', 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(), ); } public function testReturnsDirectChildElements(): void { $set = $this->createSet(1, 'Baderech'); $parentElement = $this->createElement( $set, 'Baderech HaAvodah', 'A structured path for growth', null, ); $firstChildElement = $this->createElement( $set, 'Avodah Foundations', 'Foundations for steady avodah', $parentElement, ); $secondChildElement = $this->createElement( $set, 'Daily Practice', 'Daily practices for growth', $parentElement, ); $this->createElement( $set, 'Nested Practice', 'Nested description', $firstChildElement, ); $otherSet = $this->createSet(2, 'Daily Learning'); $otherParentElement = $this->createElement( $otherSet, 'Other Parent', 'Other parent description', null, ); $this->createElement( $otherSet, 'Other Child', 'Other child description', $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, ?Element $parentElement, ): Element { return $this->elementRepo->create(new CreateElementDto( set: $set, title: $title, description: $description, parentElement: $parentElement, )); } }