Files
netslim-core/tests/Taxonomy/TaxonomyServiceReaderTest.php
2026-03-20 22:13:41 +01:00

53 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Taxonomy;
use Netig\Netslim\Taxonomy\Application\TaxonomyServiceInterface;
use Netig\Netslim\Taxonomy\Domain\Entity\Taxon;
use Netig\Netslim\Taxonomy\Infrastructure\TaxonomyServiceReader;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
final class TaxonomyServiceReaderTest extends TestCase
{
/** @var TaxonomyServiceInterface&MockObject */
private TaxonomyServiceInterface $taxonomyService;
private TaxonomyServiceReader $reader;
protected function setUp(): void
{
$this->taxonomyService = $this->createMock(TaxonomyServiceInterface::class);
$this->reader = new TaxonomyServiceReader($this->taxonomyService);
}
public function testFindAllMapsCategoriesToTaxonViews(): void
{
$this->taxonomyService->expects($this->once())
->method('findAll')
->willReturn([
new Taxon(1, 'PHP', 'php'),
new Taxon(2, 'Slim', 'slim'),
]);
$taxons = $this->reader->findAll();
self::assertCount(2, $taxons);
self::assertSame('PHP', $taxons[0]->name);
self::assertSame('slim', $taxons[1]->slug);
}
public function testFindBySlugReturnsNullWhenMissing(): void
{
$this->taxonomyService->expects($this->once())
->method('findBySlug')
->with('missing')
->willReturn(null);
self::assertNull($this->reader->findBySlug('missing'));
}
}