test get element use case
This commit is contained in:
parent
ba6bd357e2
commit
ca4d2dad3b
1 changed files with 71 additions and 0 deletions
71
backend/tests/Unit/Element/UseCases/GetElementTest.php
Normal file
71
backend/tests/Unit/Element/UseCases/GetElementTest.php
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Unit\Element\UseCases;
|
||||||
|
|
||||||
|
use App\Element\CreateElementDto;
|
||||||
|
use App\Element\Element;
|
||||||
|
use App\Element\UseCases\GetElement\GetElement;
|
||||||
|
use App\Element\UseCases\GetElement\GetElementRequest;
|
||||||
|
use App\Exceptions\BadRequestException;
|
||||||
|
use App\Exceptions\NotFoundException;
|
||||||
|
use App\Set\Set as DomainSet;
|
||||||
|
use Tests\Fakes\FakeElementRepository;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class GetElementTest extends TestCase
|
||||||
|
{
|
||||||
|
private FakeElementRepository $elementRepo;
|
||||||
|
|
||||||
|
private GetElement $getElement;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
$this->elementRepo = new FakeElementRepository();
|
||||||
|
$this->getElement = new GetElement($this->elementRepo);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testReturnsElementWhenFound(): void
|
||||||
|
{
|
||||||
|
$element = $this->createElement('Baderech HaAvodah');
|
||||||
|
|
||||||
|
$foundElement = $this->getElement->execute(new GetElementRequest(
|
||||||
|
id: $element->getId(),
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Element::class, $foundElement);
|
||||||
|
$this->assertSame($element->getId(), $foundElement->getId());
|
||||||
|
$this->assertSame('Baderech HaAvodah', $foundElement->getTitle());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testThrowsWhenIdMissing(): void
|
||||||
|
{
|
||||||
|
$this->expectException(BadRequestException::class);
|
||||||
|
$this->expectExceptionMessage('id is required');
|
||||||
|
|
||||||
|
$this->getElement->execute(new GetElementRequest(id: null));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testThrowsWhenElementDoesNotExist(): void
|
||||||
|
{
|
||||||
|
$this->expectException(NotFoundException::class);
|
||||||
|
$this->expectExceptionMessage('Element not found');
|
||||||
|
|
||||||
|
$this->getElement->execute(new GetElementRequest(id: 999));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createElement(string $title): Element
|
||||||
|
{
|
||||||
|
$set = new DomainSet(
|
||||||
|
id: 1,
|
||||||
|
name: 'Baderech',
|
||||||
|
description: 'Baderech description',
|
||||||
|
iconImageUrl: '/assets/baderech-icon.png',
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->elementRepo->create(new CreateElementDto(
|
||||||
|
set: $set,
|
||||||
|
title: $title,
|
||||||
|
parentElement: null,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue