fix controller tests to pass in data in proper form
This commit is contained in:
parent
b12d0fc7d3
commit
56bdee86cc
1 changed files with 21 additions and 14 deletions
|
|
@ -8,6 +8,7 @@ use App\Node\UseCases\CreateNode;
|
||||||
use App\Text\CreateTextDto;
|
use App\Text\CreateTextDto;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Slim\Psr7\Factory\ServerRequestFactory;
|
use Slim\Psr7\Factory\ServerRequestFactory;
|
||||||
|
use Slim\Psr7\Factory\StreamFactory;
|
||||||
use Slim\Psr7\Response;
|
use Slim\Psr7\Response;
|
||||||
use Tests\Fakes\FakeNodeRepository;
|
use Tests\Fakes\FakeNodeRepository;
|
||||||
use Tests\Fakes\FakeTextRepository;
|
use Tests\Fakes\FakeTextRepository;
|
||||||
|
|
@ -92,13 +93,15 @@ class NodeControllerTest extends TestCase
|
||||||
parentNode: null,
|
parentNode: null,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$body = (new StreamFactory())->createStream(json_encode([
|
||||||
|
'textId' => 0,
|
||||||
|
'title' => 'Child Node',
|
||||||
|
'parentNodeId' => $rootNode->getId(),
|
||||||
|
]));
|
||||||
$request = (new ServerRequestFactory())
|
$request = (new ServerRequestFactory())
|
||||||
->createServerRequest('POST', 'http://localhost/api/nodes')
|
->createServerRequest('POST', 'http://localhost/api/nodes')
|
||||||
->withParsedBody([
|
->withHeader('Content-Type', 'application/json')
|
||||||
'textId' => 0,
|
->withBody($body);
|
||||||
'title' => 'Child Node',
|
|
||||||
'parentNodeId' => $rootNode->getId(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response = $this->controller->createNode(
|
$response = $this->controller->createNode(
|
||||||
$request,
|
$request,
|
||||||
|
|
@ -115,12 +118,14 @@ class NodeControllerTest extends TestCase
|
||||||
|
|
||||||
public function test_create_node_returns_400_when_title_missing(): void
|
public function test_create_node_returns_400_when_title_missing(): void
|
||||||
{
|
{
|
||||||
|
$body = (new StreamFactory())->createStream(json_encode([
|
||||||
|
'textId' => 0,
|
||||||
|
'parentNodeId' => null,
|
||||||
|
]));
|
||||||
$request = (new ServerRequestFactory())
|
$request = (new ServerRequestFactory())
|
||||||
->createServerRequest('POST', 'http://localhost/api/nodes')
|
->createServerRequest('POST', 'http://localhost/api/nodes')
|
||||||
->withParsedBody([
|
->withHeader('Content-Type', 'application/json')
|
||||||
'textId' => 0,
|
->withBody($body);
|
||||||
'parentNodeId' => null,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response = $this->controller->createNode(
|
$response = $this->controller->createNode(
|
||||||
$request,
|
$request,
|
||||||
|
|
@ -133,13 +138,15 @@ class NodeControllerTest extends TestCase
|
||||||
|
|
||||||
public function test_create_node_returns_404_when_text_not_found(): void
|
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())
|
$request = (new ServerRequestFactory())
|
||||||
->createServerRequest('POST', 'http://localhost/api/nodes')
|
->createServerRequest('POST', 'http://localhost/api/nodes')
|
||||||
->withParsedBody([
|
->withHeader('Content-Type', 'application/json')
|
||||||
'textId' => 99,
|
->withBody($body);
|
||||||
'title' => 'Some Node',
|
|
||||||
'parentNodeId' => null,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response = $this->controller->createNode(
|
$response = $this->controller->createNode(
|
||||||
$request,
|
$request,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue