first commit
This commit is contained in:
52
tests/Taxonomy/TaxonomyServiceReaderTest.php
Normal file
52
tests/Taxonomy/TaxonomyServiceReaderTest.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?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'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user