add setup method and test that node has a text
This commit is contained in:
parent
df7ce696a9
commit
cd9e96f7b1
1 changed files with 32 additions and 4 deletions
|
|
@ -6,20 +6,48 @@ use App\Node\Node;
|
||||||
use App\Node\NodeRepository;
|
use App\Node\NodeRepository;
|
||||||
use App\Node\UseCases\CreateNode;
|
use App\Node\UseCases\CreateNode;
|
||||||
use App\Node\UseCases\CreateNodeRequest;
|
use App\Node\UseCases\CreateNodeRequest;
|
||||||
|
use App\Text\CreateTextDto;
|
||||||
|
use App\Text\Text;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Tests\Fakes\FakeNodeRepository;
|
use Tests\Fakes\FakeNodeRepository;
|
||||||
|
use Tests\Fakes\FakeTextRepository;
|
||||||
|
|
||||||
class CreateNodeTest extends TestCase
|
class CreateNodeTest extends TestCase
|
||||||
{
|
{
|
||||||
|
private FakeTextRepository $textRepo;
|
||||||
|
private FakeNodeRepository $nodeRepo;
|
||||||
|
private CreateNode $useCase;
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
$this->textRepo = new FakeTextRepository;
|
||||||
|
$this->textRepo->create(new CreateTextDto(
|
||||||
|
name: 'text'
|
||||||
|
));
|
||||||
|
$this->nodeRepo = new FakeNodeRepository;
|
||||||
|
$this->useCase = new CreateNode(
|
||||||
|
nodeRepo: $this->nodeRepo,
|
||||||
|
textRepo: $this->textRepo,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function test_create_node(): void
|
public function test_create_node(): void
|
||||||
{
|
{
|
||||||
$nodeRepo = new FakeNodeRepository;
|
$node = $this->useCase->execute(new CreateNodeRequest(
|
||||||
$useCase = new CreateNode($nodeRepo);
|
textId: 0,
|
||||||
$node = $useCase->execute(new CreateNodeRequest(
|
|
||||||
title: 'test',
|
title: 'test',
|
||||||
));
|
));
|
||||||
$this->assertInstanceOf(NodeRepository::class, $nodeRepo);
|
$this->assertInstanceOf(NodeRepository::class, $this->nodeRepo);
|
||||||
$this->assertInstanceOf(Node::class, $node);
|
$this->assertInstanceOf(Node::class, $node);
|
||||||
$this->assertEquals('test', $node->getTitle());
|
$this->assertEquals('test', $node->getTitle());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_node_belongs_to_text(): void
|
||||||
|
{
|
||||||
|
$node = $this->useCase->execute(new CreateNodeRequest(
|
||||||
|
textId: 0,
|
||||||
|
title: 'test',
|
||||||
|
));
|
||||||
|
$this->assertInstanceOf(Text::class, $node->getText());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue