|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Pfilsx\PostgreSQLDoctrine\Tests\Unit\Tools; |
| 4 | + |
| 5 | +use Doctrine\DBAL\Exception\InvalidArgumentException; |
| 6 | +use Pfilsx\PostgreSQLDoctrine\Tests\Fixtures\Enum\TestEnumInterfaceEnum; |
| 7 | +use Pfilsx\PostgreSQLDoctrine\Tests\Fixtures\Enum\TestIntBackedEnum; |
| 8 | +use Pfilsx\PostgreSQLDoctrine\Tests\Fixtures\Enum\TestStringBackedEnum; |
| 9 | +use Pfilsx\PostgreSQLDoctrine\Tests\Fixtures\Enum\TestUnitEnum; |
| 10 | +use Pfilsx\PostgreSQLDoctrine\Tools\EnumTool; |
| 11 | +use PHPUnit\Framework\TestCase; |
| 12 | + |
| 13 | +final class EnumToolTest extends TestCase |
| 14 | +{ |
| 15 | + /** |
| 16 | + * @dataProvider providerTestGetEnumTypeNameFromClassName |
| 17 | + * @see EnumTool::getEnumTypeNameFromClassName() |
| 18 | + */ |
| 19 | + public function testGetEnumTypeNameFromClassName(string $className, ?string $expectedName): void |
| 20 | + { |
| 21 | + if ($expectedName === null) { |
| 22 | + self::expectException(InvalidArgumentException::class); |
| 23 | + } |
| 24 | + |
| 25 | + self::assertSame($expectedName, EnumTool::getEnumTypeNameFromClassName($className)); |
| 26 | + } |
| 27 | + |
| 28 | + public static function providerTestGetEnumTypeNameFromClassName(): array |
| 29 | + { |
| 30 | + return [ |
| 31 | + 'string enum' => [TestStringBackedEnum::class, 'test_string_backed_enum_type'], |
| 32 | + 'unit enum' => [TestUnitEnum::class, 'test_unit_enum_type'], |
| 33 | + 'enum interface' => [TestEnumInterfaceEnum::class, 'test_enum_interface_enum_type'], |
| 34 | + 'int enum' => [TestIntBackedEnum::class, null], |
| 35 | + 'other class' => [\stdClass::class, null], |
| 36 | + 'random string' => ['test', null], |
| 37 | + ]; |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * @dataProvider providerTestGetEnumLabelsByClassName |
| 42 | + * @see EnumTool::getEnumLabelsByClassName() |
| 43 | + */ |
| 44 | + public function testGetEnumLabelsByClassName(string $className, bool $expectException): void |
| 45 | + { |
| 46 | + if ($expectException) { |
| 47 | + self::expectException(InvalidArgumentException::class); |
| 48 | + } |
| 49 | + |
| 50 | + self::assertSame([ |
| 51 | + 'Case1', |
| 52 | + 'Case2', |
| 53 | + 'Case3', |
| 54 | + ], EnumTool::getEnumLabelsByClassName($className)); |
| 55 | + } |
| 56 | + |
| 57 | + public static function providerTestGetEnumLabelsByClassName(): array |
| 58 | + { |
| 59 | + return [ |
| 60 | + 'string enum' => [TestStringBackedEnum::class, false], |
| 61 | + 'unit enum' => [TestUnitEnum::class, false], |
| 62 | + 'enum interface' => [TestEnumInterfaceEnum::class, false], |
| 63 | + 'int enum' => [TestIntBackedEnum::class, true], |
| 64 | + 'other class' => [\stdClass::class, true], |
| 65 | + 'random string' => ['test', true], |
| 66 | + ]; |
| 67 | + } |
| 68 | +} |
0 commit comments