2023-01-03 06:45:39 -06:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioTest\Shlink\Core\Functions;
|
|
|
|
|
2023-01-14 08:19:47 -06:00
|
|
|
use BackedEnum;
|
2023-02-09 13:42:18 -06:00
|
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
2023-01-03 06:45:39 -06: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;
|
|
|
|
|
2023-11-29 05:34:13 -06:00
|
|
|
use function array_map;
|
2023-01-03 06:45:39 -06:00
|
|
|
use function Shlinkio\Shlink\Core\enumValues;
|
|
|
|
|
|
|
|
class FunctionsTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
2023-01-14 08:19:47 -06:00
|
|
|
* @param class-string<BackedEnum> $enum
|
2023-01-03 06:45:39 -06:00
|
|
|
*/
|
2023-02-09 13:42:18 -06:00
|
|
|
#[Test, DataProvider('provideEnums')]
|
2023-01-03 06:45:39 -06:00
|
|
|
public function enumValuesReturnsExpectedValueForEnum(string $enum, array $expectedValues): void
|
|
|
|
{
|
|
|
|
self::assertEquals($expectedValues, enumValues($enum));
|
|
|
|
}
|
|
|
|
|
2023-02-09 02:32:38 -06:00
|
|
|
public static function provideEnums(): iterable
|
2023-01-03 06:45:39 -06:00
|
|
|
{
|
2023-11-29 05:34:13 -06:00
|
|
|
yield EnvVars::class => [
|
|
|
|
EnvVars::class,
|
|
|
|
array_map(static fn (EnvVars $envVar) => $envVar->value, EnvVars::cases()),
|
|
|
|
];
|
2023-01-03 06:45:39 -06:00
|
|
|
yield VisitType::class => [
|
|
|
|
VisitType::class,
|
2023-11-29 05:34:13 -06:00
|
|
|
array_map(static fn (VisitType $envVar) => $envVar->value, VisitType::cases()),
|
2023-01-03 06:45:39 -06:00
|
|
|
];
|
|
|
|
yield DeviceType::class => [
|
|
|
|
DeviceType::class,
|
2023-11-29 05:34:13 -06:00
|
|
|
array_map(static fn (DeviceType $envVar) => $envVar->value, DeviceType::cases()),
|
2023-01-03 06:45:39 -06:00
|
|
|
];
|
|
|
|
yield OrderableField::class => [
|
|
|
|
OrderableField::class,
|
2023-11-29 05:34:13 -06:00
|
|
|
array_map(static fn (OrderableField $envVar) => $envVar->value, OrderableField::cases()),
|
2023-01-03 06:45:39 -06:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|