test set elements
This commit is contained in:
parent
104909bcf5
commit
db35a97910
6 changed files with 409 additions and 0 deletions
63
backend/tests/Unit/Set/UseCases/CreateSetTest.php
Normal file
63
backend/tests/Unit/Set/UseCases/CreateSetTest.php
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Unit\Set\UseCases;
|
||||
|
||||
use App\Exceptions\BadRequestException;
|
||||
use App\Set\Set as DomainSet;
|
||||
use App\Set\UseCases\CreateSet\CreateSet;
|
||||
use App\Set\UseCases\CreateSet\CreateSetRequest;
|
||||
use Tests\Fakes\FakeElementRepository;
|
||||
use Tests\Fakes\FakeSetRepository;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CreateSetTest extends TestCase
|
||||
{
|
||||
private FakeSetRepository $setRepo;
|
||||
|
||||
private FakeElementRepository $elementRepo;
|
||||
|
||||
private CreateSet $createSet;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->setRepo = new FakeSetRepository();
|
||||
$this->elementRepo = new FakeElementRepository();
|
||||
$this->createSet = new CreateSet(
|
||||
$this->setRepo,
|
||||
$this->elementRepo,
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreatesSet(): void
|
||||
{
|
||||
$set = $this->createSet->execute(
|
||||
new CreateSetRequest('Daily learning')
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(DomainSet::class, $set);
|
||||
$this->assertSame(1, $set->getId());
|
||||
$this->assertSame('Daily learning', $set->getName());
|
||||
}
|
||||
|
||||
public function testCreatesRootElementForSet(): void
|
||||
{
|
||||
$set = $this->createSet->execute(
|
||||
new CreateSetRequest('Daily learning')
|
||||
);
|
||||
|
||||
$elements = $this->elementRepo->findBySetId($set->getId());
|
||||
|
||||
$this->assertCount(1, $elements);
|
||||
$this->assertSame('Daily learning', $elements[0]->getTitle());
|
||||
$this->assertSame($set->getId(), $elements[0]->getSet()->getId());
|
||||
$this->assertNull($elements[0]->getParentElement());
|
||||
}
|
||||
|
||||
public function testThrowsWhenNameMissing(): void
|
||||
{
|
||||
$this->expectException(BadRequestException::class);
|
||||
$this->expectExceptionMessage('name is required');
|
||||
|
||||
$this->createSet->execute(new CreateSetRequest(null));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue