67 lines
1.9 KiB
PHP
67 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Set\UseCases;
|
|
|
|
use App\Exceptions\BadRequestException;
|
|
use App\Set\CreateSetDto;
|
|
use App\Set\Set as DomainSet;
|
|
use App\Set\UseCases\UpdateSet\UpdateDescription;
|
|
use App\Set\UseCases\UpdateSet\UpdateDescriptionRequest;
|
|
use Tests\Fakes\FakeSetRepository;
|
|
use Tests\TestCase;
|
|
|
|
class UpdateDescriptionTest extends TestCase
|
|
{
|
|
private FakeSetRepository $setRepository;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->setRepository = new FakeSetRepository();
|
|
}
|
|
|
|
public function testUpdatesOnlyDescription(): void
|
|
{
|
|
$set = $this->createSet();
|
|
$updateDescription = new UpdateDescription($this->setRepository);
|
|
|
|
$updatedSet = $updateDescription->execute(
|
|
new UpdateDescriptionRequest(
|
|
id: $set->getId(),
|
|
description: 'Updated set description',
|
|
)
|
|
);
|
|
|
|
$this->assertSame(
|
|
'Updated set description',
|
|
$updatedSet->getDescription(),
|
|
);
|
|
$this->assertSame($set->getName(), $updatedSet->getName());
|
|
$this->assertSame(
|
|
$set->getIconImageUrl(),
|
|
$updatedSet->getIconImageUrl(),
|
|
);
|
|
}
|
|
|
|
public function testRejectsBlankDescription(): void
|
|
{
|
|
$set = $this->createSet();
|
|
$updateDescription = new UpdateDescription($this->setRepository);
|
|
|
|
$this->expectException(BadRequestException::class);
|
|
$this->expectExceptionMessage('description is required');
|
|
|
|
$updateDescription->execute(new UpdateDescriptionRequest(
|
|
id: $set->getId(),
|
|
description: '',
|
|
));
|
|
}
|
|
|
|
private function createSet(): DomainSet
|
|
{
|
|
return $this->setRepository->create(new CreateSetDto(
|
|
name: 'Original Set',
|
|
description: 'Original set description',
|
|
iconImageUrl: 'set-icons/original.png',
|
|
));
|
|
}
|
|
}
|