65 lines
1.7 KiB
PHP
65 lines
1.7 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\UpdateName;
|
|
use App\Set\UseCases\UpdateSet\UpdateNameRequest;
|
|
use Tests\Fakes\FakeSetRepository;
|
|
use Tests\TestCase;
|
|
|
|
class UpdateNameTest extends TestCase
|
|
{
|
|
private FakeSetRepository $setRepository;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->setRepository = new FakeSetRepository();
|
|
}
|
|
|
|
public function testUpdatesOnlyName(): void
|
|
{
|
|
$set = $this->createSet();
|
|
$updateName = new UpdateName($this->setRepository);
|
|
|
|
$updatedSet = $updateName->execute(new UpdateNameRequest(
|
|
id: $set->getId(),
|
|
name: 'Updated Set',
|
|
));
|
|
|
|
$this->assertSame('Updated Set', $updatedSet->getName());
|
|
$this->assertSame(
|
|
$set->getDescription(),
|
|
$updatedSet->getDescription(),
|
|
);
|
|
$this->assertSame(
|
|
$set->getIconImageUrl(),
|
|
$updatedSet->getIconImageUrl(),
|
|
);
|
|
}
|
|
|
|
public function testRejectsBlankName(): void
|
|
{
|
|
$set = $this->createSet();
|
|
$updateName = new UpdateName($this->setRepository);
|
|
|
|
$this->expectException(BadRequestException::class);
|
|
$this->expectExceptionMessage('name is required');
|
|
|
|
$updateName->execute(new UpdateNameRequest(
|
|
id: $set->getId(),
|
|
name: '',
|
|
));
|
|
}
|
|
|
|
private function createSet(): DomainSet
|
|
{
|
|
return $this->setRepository->create(new CreateSetDto(
|
|
name: 'Original Set',
|
|
description: 'Original set description',
|
|
iconImageUrl: 'set-icons/original.png',
|
|
));
|
|
}
|
|
}
|