|
6 | 6 |
|
7 | 7 | use PHPUnit\Framework\Attributes\CoversNothing; |
8 | 8 | use PHPUnit\Framework\TestCase; |
9 | | -use Typhoon\Type; |
10 | 9 |
|
11 | 10 | #[CoversNothing] |
12 | 11 | final class ConstructorsNamingTest extends TestCase |
13 | 12 | { |
14 | | - public function testFunctionsAreSuffixedWithT(): void |
| 13 | + private const NON_TYPE_CONSTRUCTOR_FUNCTIONS = [ |
| 14 | + 'fromReflection', |
| 15 | + 'optional', |
| 16 | + 'param', |
| 17 | + 'stringify', |
| 18 | + 'template', |
| 19 | + 'templateIn', |
| 20 | + 'templateOut', |
| 21 | + ]; |
| 22 | + |
| 23 | + public function testFunctionsSuffixedWithT(): void |
15 | 24 | { |
16 | 25 | foreach (get_defined_functions()['user'] as $function) { |
17 | 26 | if (!str_starts_with($function, 'typhoon\type\\')) { |
18 | 27 | continue; |
19 | 28 | } |
20 | 29 |
|
21 | | - $reflection = new \ReflectionFunction($function); |
22 | | - $returnType = $reflection->getReturnType(); |
| 30 | + $shortName = (new \ReflectionFunction($function))->getShortName(); |
23 | 31 |
|
24 | | - if (!$returnType instanceof \ReflectionNamedType) { |
| 32 | + if (\in_array($shortName, self::NON_TYPE_CONSTRUCTOR_FUNCTIONS, true)) { |
25 | 33 | continue; |
26 | 34 | } |
27 | 35 |
|
28 | | - if (!is_a($returnType->getName(), Type::class, allow_string: true)) { |
29 | | - continue; |
30 | | - } |
31 | | - |
32 | | - self::assertStringEndsWith('T', $reflection->getShortName()); |
| 36 | + self::assertStringEndsWith('T', $shortName); |
33 | 37 | } |
34 | 38 | } |
35 | 39 |
|
36 | | - public function testConstantsAreSuffixedWithT(): void |
| 40 | + public function testConstantsSuffixedWithT(): void |
37 | 41 | { |
38 | 42 | foreach (get_defined_constants(categorize: true)['user'] as $constant => $value) { |
39 | | - if ($value instanceof Type) { |
| 43 | + if (str_starts_with($constant, 'Typhoon\Type\\')) { |
40 | 44 | self::assertStringEndsWith('T', $constant); |
41 | 45 | } |
42 | 46 | } |
|
0 commit comments