elementRepo = new FakeElementRepository(); $getElement = new GetElement($this->elementRepo); $this->controller = new ElementController($getElement); } public function testShowReturnsElementPayload(): void { $set = $this->createSet(1, 'Baderech'); $element = $this->createElement( $set, 'Baderech HaAvodah', 'A structured path for growth', '

A structured path for growth

', null, ); $firstChildElement = $this->createElement( $set, 'Avodah Foundations', 'Foundations for steady avodah', '

Foundations rich text

', $element, ); $secondChildElement = $this->createElement( $set, 'Daily Practice', 'Daily practices for growth', '

Daily practice rich text

', $element, ); $response = $this->controller->show($element->getId()); $this->assertEquals(200, $response->getStatusCode()); $body = json_decode($response->getContent(), true); $this->assertSame($element->getId(), $body['element']['id']); $this->assertSame('Baderech HaAvodah', $body['element']['title']); $this->assertSame( 'A structured path for growth', $body['element']['description'], ); $this->assertSame( '

A structured path for growth

', $body['element']['richText'], ); $this->assertSame([ [ 'id' => $firstChildElement->getId(), 'title' => 'Avodah Foundations', 'description' => 'Foundations for steady avodah', ], [ 'id' => $secondChildElement->getId(), 'title' => 'Daily Practice', 'description' => 'Daily practices for growth', ], ], $body['childElements']); } public function testShowReturns400WhenIdMissing(): void { $response = $this->controller->show(null); $this->assertEquals(400, $response->getStatusCode()); $this->assertSame( ['error' => 'id is required'], json_decode($response->getContent(), true), ); } public function testShowReturns404WhenElementDoesNotExist(): void { $response = $this->controller->show(999); $this->assertEquals(404, $response->getStatusCode()); $this->assertSame( ['error' => 'Element not found'], json_decode($response->getContent(), true), ); } 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 $richText, ?Element $parentElement, ): Element { return $this->elementRepo->create(new CreateElementDto( set: $set, title: $title, description: $description, richText: $richText, parentElement: $parentElement, )); } }