Initial commit after upgrading to php 8.3 and splitting to seperated tool chain
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tez\Utils\Tests\Enum;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tez\Utils\Enum\BackedEnumTrait;
|
||||
use Tez\Utils\Enum\TranslatableTrait;
|
||||
|
||||
enum StatusWithLabels: string
|
||||
{
|
||||
use BackedEnumTrait;
|
||||
use TranslatableTrait;
|
||||
|
||||
case Active = 'active';
|
||||
case Pending = 'pending';
|
||||
case Archived = 'archived';
|
||||
|
||||
/** @return array<string, string> */
|
||||
protected static function labels(): array
|
||||
{
|
||||
return [
|
||||
self::Active->name => 'Aktiv',
|
||||
self::Pending->name => 'Ausstehend',
|
||||
// Archived intentionally has no label → fallback to name
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
enum PureWithLabels
|
||||
{
|
||||
use TranslatableTrait;
|
||||
|
||||
case Open;
|
||||
case Closed;
|
||||
|
||||
/** @return array<string, string> */
|
||||
protected static function labels(): array
|
||||
{
|
||||
return [
|
||||
self::Open->name => 'Offen',
|
||||
self::Closed->name => 'Geschlossen',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
enum NoLabels: int
|
||||
{
|
||||
use TranslatableTrait;
|
||||
|
||||
case One = 1;
|
||||
case Two = 2;
|
||||
}
|
||||
|
||||
final class TranslatableTraitTest extends TestCase
|
||||
{
|
||||
// -------------------------------------------------------------------------
|
||||
// label()
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public function testLabelReturnsConfiguredString(): void
|
||||
{
|
||||
self::assertSame('Aktiv', StatusWithLabels::Active->label());
|
||||
self::assertSame('Ausstehend', StatusWithLabels::Pending->label());
|
||||
}
|
||||
|
||||
public function testLabelFallsBackToCaseNameWhenNotConfigured(): void
|
||||
{
|
||||
self::assertSame('Archived', StatusWithLabels::Archived->label());
|
||||
}
|
||||
|
||||
public function testLabelWorksForPureEnum(): void
|
||||
{
|
||||
self::assertSame('Offen', PureWithLabels::Open->label());
|
||||
self::assertSame('Geschlossen', PureWithLabels::Closed->label());
|
||||
}
|
||||
|
||||
public function testLabelFallsBackWhenNoLabelsMethodOverridden(): void
|
||||
{
|
||||
self::assertSame('One', NoLabels::One->label());
|
||||
self::assertSame('Two', NoLabels::Two->label());
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// labelsArray()
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public function testLabelsArrayReturnsAllCasesMappedToLabels(): void
|
||||
{
|
||||
self::assertSame(
|
||||
[
|
||||
'Active' => 'Aktiv',
|
||||
'Pending' => 'Ausstehend',
|
||||
'Archived' => 'Archived',
|
||||
],
|
||||
StatusWithLabels::labelsArray(),
|
||||
);
|
||||
}
|
||||
|
||||
public function testLabelsArrayWorksForPureEnum(): void
|
||||
{
|
||||
self::assertSame(
|
||||
[
|
||||
'Open' => 'Offen',
|
||||
'Closed' => 'Geschlossen',
|
||||
],
|
||||
PureWithLabels::labelsArray(),
|
||||
);
|
||||
}
|
||||
|
||||
public function testLabelsArrayFallsBackToNamesWhenEmpty(): void
|
||||
{
|
||||
self::assertSame(
|
||||
[
|
||||
'One' => 'One',
|
||||
'Two' => 'Two',
|
||||
],
|
||||
NoLabels::labelsArray(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user