Skip to content

Commit 3995d0b

Browse files
committed
Revert "Avoid hardcoding in ConstructorsNamingTest"
This reverts commit 094b39e.
1 parent 094b39e commit 3995d0b

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

tests/Type/ConstructorsNamingTest.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,41 @@
66

77
use PHPUnit\Framework\Attributes\CoversNothing;
88
use PHPUnit\Framework\TestCase;
9-
use Typhoon\Type;
109

1110
#[CoversNothing]
1211
final class ConstructorsNamingTest extends TestCase
1312
{
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
1524
{
1625
foreach (get_defined_functions()['user'] as $function) {
1726
if (!str_starts_with($function, 'typhoon\type\\')) {
1827
continue;
1928
}
2029

21-
$reflection = new \ReflectionFunction($function);
22-
$returnType = $reflection->getReturnType();
30+
$shortName = (new \ReflectionFunction($function))->getShortName();
2331

24-
if (!$returnType instanceof \ReflectionNamedType) {
32+
if (\in_array($shortName, self::NON_TYPE_CONSTRUCTOR_FUNCTIONS, true)) {
2533
continue;
2634
}
2735

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);
3337
}
3438
}
3539

36-
public function testConstantsAreSuffixedWithT(): void
40+
public function testConstantsSuffixedWithT(): void
3741
{
3842
foreach (get_defined_constants(categorize: true)['user'] as $constant => $value) {
39-
if ($value instanceof Type) {
43+
if (str_starts_with($constant, 'Typhoon\Type\\')) {
4044
self::assertStringEndsWith('T', $constant);
4145
}
4246
}

0 commit comments

Comments
 (0)