planRepo = new FakePlanRepository(); $this->userRepo = new FakeUserRepository(); $this->textRepo = new FakeTextRepository(); $this->nodeRepo = new FakeNodeRepository(); $this->scheduledNodeRepo = new FakeScheduledNodeRepository(); $this->userRepo->create(new CreateUserDto( email: new EmailAddress('test@test.com'), )); $text = $this->textRepo->create(new CreateTextDto('testname')); $this->nodeRepo->create(new CreateNodeDto( text: $text, title: 'Root Node', parentNode: null, )); $createScheduledNode = new CreateScheduledNode( scheduledNodeRepo: $this->scheduledNodeRepo, planRepo: $this->planRepo, ); $this->createPlan = new CreatePlan( $this->planRepo, $this->userRepo, $this->textRepo, $this->nodeRepo, $createScheduledNode, ); $this->controller = new PlanController(); } private function makeRequest(array $data): ServerRequestInterface { $body = new StreamFactory()->createStream(json_encode($data)); return new ServerRequestFactory() ->createServerRequest('POST', 'http://localhost/api/plans') ->withHeader('Content-Type', 'application/json') ->withBody($body); } public function test_create_plan_returns_201_with_id_and_name(): void { $response = $this->controller->createPlan( $this->makeRequest([ 'userId' => 0, 'textId' => 0, 'name' => 'My Plan', 'dateStart' => '2025-01-01', 'dateEnd' => '2025-01-01', ]), new Response(), $this->createPlan, ); $this->assertEquals(201, $response->getStatusCode()); $body = json_decode($response->getBody(), true); $this->assertArrayHasKey('id', $body); $this->assertEquals('My Plan', $body['name']); } }