test seeded sets
This commit is contained in:
parent
3bfcdfd0cc
commit
f62b05bc37
3 changed files with 20 additions and 80 deletions
|
|
@ -6,7 +6,7 @@ use App\Element\Element;
|
|||
use App\Element\UseCases\CreateElement\CreateElement;
|
||||
use App\Element\UseCases\CreateElement\CreateElementRequest;
|
||||
use App\Exceptions\BadRequestException;
|
||||
use App\Set\CreateSetDto;
|
||||
use App\Set\Set as DomainSet;
|
||||
use DomainException;
|
||||
use Tests\Fakes\FakeElementRepository;
|
||||
use Tests\Fakes\FakeSetRepository;
|
||||
|
|
@ -30,9 +30,20 @@ class CreateElementTest extends TestCase
|
|||
);
|
||||
}
|
||||
|
||||
private function seedSet(int $id, string $name): DomainSet
|
||||
{
|
||||
$set = new DomainSet(
|
||||
id: $id,
|
||||
name: $name,
|
||||
);
|
||||
$this->setRepo->store($set);
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
public function testCreatesRootElement(): void
|
||||
{
|
||||
$set = $this->setRepo->create(new CreateSetDto('Daily learning'));
|
||||
$set = $this->seedSet(1, 'Daily learning');
|
||||
|
||||
$element = $this->createElement->execute(new CreateElementRequest(
|
||||
setId: $set->getId(),
|
||||
|
|
@ -48,7 +59,7 @@ class CreateElementTest extends TestCase
|
|||
|
||||
public function testCreatesChildElement(): void
|
||||
{
|
||||
$set = $this->setRepo->create(new CreateSetDto('Daily learning'));
|
||||
$set = $this->seedSet(1, 'Daily learning');
|
||||
$rootElement = $this->createElement->execute(
|
||||
new CreateElementRequest(
|
||||
setId: $set->getId(),
|
||||
|
|
@ -110,7 +121,7 @@ class CreateElementTest extends TestCase
|
|||
|
||||
public function testThrowsWhenParentElementDoesNotExist(): void
|
||||
{
|
||||
$set = $this->setRepo->create(new CreateSetDto('Daily learning'));
|
||||
$set = $this->seedSet(1, 'Daily learning');
|
||||
|
||||
$this->expectException(DomainException::class);
|
||||
$this->expectExceptionMessage(
|
||||
|
|
@ -126,7 +137,7 @@ class CreateElementTest extends TestCase
|
|||
|
||||
public function testThrowsWhenRootElementAlreadyExists(): void
|
||||
{
|
||||
$set = $this->setRepo->create(new CreateSetDto('Daily learning'));
|
||||
$set = $this->seedSet(1, 'Daily learning');
|
||||
$this->createElement->execute(new CreateElementRequest(
|
||||
setId: $set->getId(),
|
||||
title: 'Root',
|
||||
|
|
@ -147,8 +158,8 @@ class CreateElementTest extends TestCase
|
|||
|
||||
public function testThrowsWhenParentBelongsToAnotherSet(): void
|
||||
{
|
||||
$parentSet = $this->setRepo->create(new CreateSetDto('Parent set'));
|
||||
$childSet = $this->setRepo->create(new CreateSetDto('Child set'));
|
||||
$parentSet = $this->seedSet(1, 'Parent set');
|
||||
$childSet = $this->seedSet(2, 'Child set');
|
||||
$parentElement = $this->createElement->execute(
|
||||
new CreateElementRequest(
|
||||
setId: $parentSet->getId(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue