2023-01-03 15:45:39 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioTest\Shlink\Core\Functions;
|
|
|
|
|
2023-01-14 17:19:47 +03:00
|
|
|
use BackedEnum;
|
2023-01-03 15:45:39 +03:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Shlinkio\Shlink\Core\Config\EnvVars;
|
|
|
|
use Shlinkio\Shlink\Core\Model\DeviceType;
|
|
|
|
use Shlinkio\Shlink\Core\ShortUrl\Model\OrderableField;
|
|
|
|
use Shlinkio\Shlink\Core\Visit\Model\VisitType;
|
|
|
|
|
|
|
|
use function Functional\map;
|
|
|
|
use function Shlinkio\Shlink\Core\enumValues;
|
|
|
|
|
|
|
|
class FunctionsTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
2023-01-14 17:19:47 +03:00
|
|
|
* @param class-string<BackedEnum> $enum
|
2023-01-03 15:45:39 +03:00
|
|
|
* @test
|
|
|
|
* @dataProvider provideEnums
|
|
|
|
*/
|
|
|
|
public function enumValuesReturnsExpectedValueForEnum(string $enum, array $expectedValues): void
|
|
|
|
{
|
|
|
|
self::assertEquals($expectedValues, enumValues($enum));
|
|
|
|
}
|
|
|
|
|
2023-02-09 11:32:38 +03:00
|
|
|
public static function provideEnums(): iterable
|
2023-01-03 15:45:39 +03:00
|
|
|
{
|
|
|
|
yield EnvVars::class => [EnvVars::class, map(EnvVars::cases(), static fn (EnvVars $envVar) => $envVar->value)];
|
|
|
|
yield VisitType::class => [
|
|
|
|
VisitType::class,
|
|
|
|
map(VisitType::cases(), static fn (VisitType $envVar) => $envVar->value),
|
|
|
|
];
|
|
|
|
yield DeviceType::class => [
|
|
|
|
DeviceType::class,
|
|
|
|
map(DeviceType::cases(), static fn (DeviceType $envVar) => $envVar->value),
|
|
|
|
];
|
|
|
|
yield OrderableField::class => [
|
|
|
|
OrderableField::class,
|
|
|
|
map(OrderableField::cases(), static fn (OrderableField $envVar) => $envVar->value),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|