add plan controller test scaffold

This commit is contained in:
Yisroel Baum 2026-04-24 11:00:06 +03:00
parent f836a09d02
commit 6b310c8c9c
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9

View file

@ -0,0 +1,73 @@
<?php
namespace Tests\e2e\Controllers;
use App\Node\CreateNodeDto;
use App\Plan\PlanController;
use App\Plan\UseCases\CreatePlan;
use App\ScheduledNode\UseCases\CreateScheduledNode;
use App\Text\CreateTextDto;
use App\User\UseCases\CreateUserDto;
use App\ValueObjects\EmailAddress;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface;
use Slim\Psr7\Factory\ServerRequestFactory;
use Slim\Psr7\Factory\StreamFactory;
use Slim\Psr7\Response;
use Tests\Fakes\FakeNodeRepository;
use Tests\Fakes\FakePlanRepository;
use Tests\Fakes\FakeScheduledNodeRepository;
use Tests\Fakes\FakeTextRepository;
use Tests\Fakes\FakeUserRepository;
class PlanControllerTest extends TestCase
{
private FakePlanRepository $planRepo;
private FakeUserRepository $userRepo;
private FakeTextRepository $textRepo;
private FakeNodeRepository $nodeRepo;
private FakeScheduledNodeRepository $scheduledNodeRepo;
private CreatePlan $createPlan;
private PlanController $controller;
public function setUp(): void
{
$this->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);
}
}