57 lines
1.7 KiB
PHP
57 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Entity;
|
|
|
|
use App\Entity\ResourceType;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class ResourceTypeTest extends TestCase
|
|
{
|
|
public function testEverySlugResolvesBackToItsCase(): void
|
|
{
|
|
foreach (ResourceType::cases() as $type) {
|
|
self::assertSame($type, ResourceType::fromSlug($type->slug()));
|
|
}
|
|
}
|
|
|
|
public function testSlugsAreUnique(): void
|
|
{
|
|
$slugs = array_map(static fn (ResourceType $type): string => $type->slug(), ResourceType::cases());
|
|
|
|
self::assertSame($slugs, array_unique($slugs));
|
|
}
|
|
|
|
public function testAnUnknownSlugIsRejected(): void
|
|
{
|
|
$this->expectException(\ValueError::class);
|
|
|
|
ResourceType::fromSlug('fahrraeder');
|
|
}
|
|
|
|
/**
|
|
* The URL slugs are German while the backing values stay English, because the values are
|
|
* persisted in resource.type and renaming them would need a migration.
|
|
*/
|
|
public function testTheSlugIsNotTheStoredValue(): void
|
|
{
|
|
self::assertSame('desk', ResourceType::DESK->value);
|
|
self::assertSame('schreibtische', ResourceType::DESK->slug());
|
|
}
|
|
|
|
/**
|
|
* Every case must carry the presentation a dashboard tile needs, or adding one would produce
|
|
* a broken tile rather than a working one.
|
|
*/
|
|
public function testEveryCaseIsFullyDescribed(): void
|
|
{
|
|
foreach (ResourceType::cases() as $type) {
|
|
self::assertNotSame('', $type->label());
|
|
self::assertNotSame('', $type->plural());
|
|
self::assertNotSame('', $type->description());
|
|
self::assertStringStartsWith('lucide:', $type->icon());
|
|
}
|
|
}
|
|
}
|