fix controller tests to pass in data in proper form

This commit is contained in:
Yisroel Baum 2026-04-18 21:59:57 +03:00
parent b12d0fc7d3
commit 56bdee86cc
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9

View file

@ -8,6 +8,7 @@ use App\Node\UseCases\CreateNode;
use App\Text\CreateTextDto;
use PHPUnit\Framework\TestCase;
use Slim\Psr7\Factory\ServerRequestFactory;
use Slim\Psr7\Factory\StreamFactory;
use Slim\Psr7\Response;
use Tests\Fakes\FakeNodeRepository;
use Tests\Fakes\FakeTextRepository;
@ -92,13 +93,15 @@ class NodeControllerTest extends TestCase
parentNode: null,
));
$body = (new StreamFactory())->createStream(json_encode([
'textId' => 0,
'title' => 'Child Node',
'parentNodeId' => $rootNode->getId(),
]));
$request = (new ServerRequestFactory())
->createServerRequest('POST', 'http://localhost/api/nodes')
->withParsedBody([
'textId' => 0,
'title' => 'Child Node',
'parentNodeId' => $rootNode->getId(),
]);
->withHeader('Content-Type', 'application/json')
->withBody($body);
$response = $this->controller->createNode(
$request,
@ -115,12 +118,14 @@ class NodeControllerTest extends TestCase
public function test_create_node_returns_400_when_title_missing(): void
{
$body = (new StreamFactory())->createStream(json_encode([
'textId' => 0,
'parentNodeId' => null,
]));
$request = (new ServerRequestFactory())
->createServerRequest('POST', 'http://localhost/api/nodes')
->withParsedBody([
'textId' => 0,
'parentNodeId' => null,
]);
->withHeader('Content-Type', 'application/json')
->withBody($body);
$response = $this->controller->createNode(
$request,
@ -133,13 +138,15 @@ class NodeControllerTest extends TestCase
public function test_create_node_returns_404_when_text_not_found(): void
{
$body = (new StreamFactory())->createStream(json_encode([
'textId' => 99,
'title' => 'Some Node',
'parentNodeId' => null,
]));
$request = (new ServerRequestFactory())
->createServerRequest('POST', 'http://localhost/api/nodes')
->withParsedBody([
'textId' => 99,
'title' => 'Some Node',
'parentNodeId' => null,
]);
->withHeader('Content-Type', 'application/json')
->withBody($body);
$response = $this->controller->createNode(
$request,