test text controller methods
This commit is contained in:
parent
85ab8f2bbc
commit
98f597914a
1 changed files with 83 additions and 0 deletions
83
tests/e2e/Controllers/TextControllerTest.php
Normal file
83
tests/e2e/Controllers/TextControllerTest.php
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\e2e\Controllers;
|
||||
|
||||
use App\Text\CreateTextDto;
|
||||
use App\Text\TextController;
|
||||
use App\Text\UseCases\CreateText;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Slim\Psr7\Factory\ServerRequestFactory;
|
||||
use Slim\Psr7\Response;
|
||||
use Tests\Fakes\FakeTextRepository;
|
||||
|
||||
class TextControllerTest extends TestCase
|
||||
{
|
||||
private FakeTextRepository $textRepo;
|
||||
|
||||
private TextController $controller;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->textRepo = new FakeTextRepository;
|
||||
$this->textRepo->create(new CreateTextDto(
|
||||
name: 'test text',
|
||||
));
|
||||
$this->controller = new TextController($this->textRepo);
|
||||
}
|
||||
|
||||
public function test_get_one_text(): void
|
||||
{
|
||||
$response = $this->controller->getText(
|
||||
new Response(),
|
||||
0,
|
||||
);
|
||||
$this->assertEquals(
|
||||
json_encode([
|
||||
'id' => 0,
|
||||
'name' => 'test text',
|
||||
]),
|
||||
$response->getBody()
|
||||
);
|
||||
}
|
||||
|
||||
public function test_get_all_texts(): void
|
||||
{
|
||||
$this->textRepo->create(new CreateTextDto(
|
||||
name: 'test text 2',
|
||||
));
|
||||
$response = $this->controller->getTexts(new Response());
|
||||
$this->assertEquals(
|
||||
json_encode([
|
||||
[
|
||||
'id' => 0,
|
||||
'name' => 'test text',
|
||||
],
|
||||
[
|
||||
'id' => 1,
|
||||
'name' => 'test text 2',
|
||||
]
|
||||
]),
|
||||
$response->getBody()
|
||||
);
|
||||
}
|
||||
|
||||
public function test_create_text(): void
|
||||
{
|
||||
$request = (new ServerRequestFactory())
|
||||
->createServerRequest('POST', 'http://localhost/texts')
|
||||
->withParsedBody(['name' => 'my new text']);
|
||||
|
||||
$response = $this->controller->createText(
|
||||
$request,
|
||||
new Response(),
|
||||
new CreateText($this->textRepo),
|
||||
);
|
||||
$this->assertEquals(
|
||||
json_encode([
|
||||
'id' => 1,
|
||||
'name' => 'my new text',
|
||||
]),
|
||||
$response->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue