52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Taxonomy;
|
|
|
|
use Netig\Netslim\Taxonomy\Domain\Entity\Taxon;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
|
|
|
final class TaxonModelTest extends TestCase
|
|
{
|
|
public function testConstructAndGettersExposeTaxonData(): void
|
|
{
|
|
$taxon = new Taxon(4, 'PHP', 'php');
|
|
|
|
self::assertSame(4, $taxon->getId());
|
|
self::assertSame('PHP', $taxon->getName());
|
|
self::assertSame('php', $taxon->getSlug());
|
|
}
|
|
|
|
public function testFromArrayHydratesTaxon(): void
|
|
{
|
|
$taxon = Taxon::fromArray([
|
|
'id' => '6',
|
|
'name' => 'Tests',
|
|
'slug' => 'tests',
|
|
]);
|
|
|
|
self::assertSame(6, $taxon->getId());
|
|
self::assertSame('Tests', $taxon->getName());
|
|
self::assertSame('tests', $taxon->getSlug());
|
|
}
|
|
|
|
public function testValidationRejectsEmptyName(): void
|
|
{
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
$this->expectExceptionMessage('Le nom du terme ne peut pas être vide');
|
|
|
|
new Taxon(1, '', 'slug');
|
|
}
|
|
|
|
public function testValidationRejectsTooLongName(): void
|
|
{
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
$this->expectExceptionMessage('Le nom du terme ne peut pas dépasser 100 caractères');
|
|
|
|
new Taxon(1, str_repeat('a', 101), 'slug');
|
|
}
|
|
}
|