unit test for create text that it creates a root node as well.

refactor to setUp as well
This commit is contained in:
Yisroel Baum 2026-04-17 10:49:41 +03:00
parent 98f597914a
commit f6791b6459
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9

View file

@ -7,19 +7,48 @@ use App\Text\TextRepository;
use App\Text\UseCases\CreateText;
use App\Text\UseCases\CreateTextRequest;
use PHPUnit\Framework\TestCase;
use Tests\Fakes\FakeNodeRepository;
use Tests\Fakes\FakeTextRepository;
class CreateTextTest extends TestCase
{
private FakeTextRepository $textRepo;
private FakeNodeRepository $nodeRepo;
private CreateText $useCase;
protected function setUp(): void
{
$this->textRepo = new FakeTextRepository;
$this->nodeRepo = new FakeNodeRepository;
$this->useCase = new CreateText(
$this->textRepo,
$this->nodeRepo,
);
}
public function test_create_text(): void
{
$textRepo = new FakeTextRepository;
$useCase = new CreateText($textRepo);
$text = $useCase->execute(new CreateTextRequest(
$text = $this->useCase->execute(new CreateTextRequest(
name: 'test',
));
$this->assertInstanceOf(TextRepository::class, $textRepo);
$this->assertInstanceOf(TextRepository::class, $this->textRepo);
$this->assertInstanceOf(Text::class, $text);
$this->assertEquals('test', $text->getName());
}
public function test_creates_root_node_on_text_creation(): void
{
$text = $this->useCase->execute(new CreateTextRequest(
name: 'my text',
));
$nodes = $this->nodeRepo->findByTextId($text->getId());
$this->assertCount(1, $nodes);
$rootNode = array_values($nodes)[0];
$this->assertEquals('my text', $rootNode->getTitle());
$this->assertNull($rootNode->getParentNode());
}
}