Goal-Calibration/tests/Unit/Text/UseCases/CreateTextTest.php
2026-04-19 23:07:48 +03:00

54 lines
1.5 KiB
PHP

<?php
namespace Tests\Unit\Text\UseCases;
use App\Text\Text;
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
{
$text = $this->useCase->execute(new CreateTextRequest(
name: 'test',
));
$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());
}
}