@@ -17,157 +17,157 @@ |
||
17 | 17 | |
18 | 18 | class BaseFunctionsTest extends BaseStubsTest |
19 | 19 | { |
20 | - /** |
|
21 | - * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionFunctionsProvider::allFunctionsProvider |
|
22 | - * @throws Exception|RuntimeException |
|
23 | - */ |
|
24 | - public function testFunctionsExist(PHPFunction $function): void |
|
25 | - { |
|
26 | - $functionName = $function->name; |
|
27 | - $stubFunction = PhpStormStubsSingleton::getPhpStormStubs()->getFunction($functionName); |
|
28 | - $params = BaseStubsTest::getParameterRepresentation($function); |
|
29 | - static::assertNotEmpty($stubFunction, "Missing function: function $functionName($params){}"); |
|
30 | - } |
|
20 | + /** |
|
21 | + * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionFunctionsProvider::allFunctionsProvider |
|
22 | + * @throws Exception|RuntimeException |
|
23 | + */ |
|
24 | + public function testFunctionsExist(PHPFunction $function): void |
|
25 | + { |
|
26 | + $functionName = $function->name; |
|
27 | + $stubFunction = PhpStormStubsSingleton::getPhpStormStubs()->getFunction($functionName); |
|
28 | + $params = BaseStubsTest::getParameterRepresentation($function); |
|
29 | + static::assertNotEmpty($stubFunction, "Missing function: function $functionName($params){}"); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionFunctionsProvider::functionsForDeprecationTestsProvider |
|
34 | - * @throws RuntimeException |
|
35 | - */ |
|
36 | - public function testFunctionsDeprecation(PHPFunction $function) |
|
37 | - { |
|
38 | - $functionName = $function->name; |
|
39 | - $stubFunction = PhpStormStubsSingleton::getPhpStormStubs()->getFunction($functionName); |
|
40 | - static::assertFalse( |
|
41 | - $function->is_deprecated && $stubFunction->is_deprecated !== true, |
|
42 | - "Function $functionName is not deprecated in stubs" |
|
43 | - ); |
|
44 | - } |
|
32 | + /** |
|
33 | + * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionFunctionsProvider::functionsForDeprecationTestsProvider |
|
34 | + * @throws RuntimeException |
|
35 | + */ |
|
36 | + public function testFunctionsDeprecation(PHPFunction $function) |
|
37 | + { |
|
38 | + $functionName = $function->name; |
|
39 | + $stubFunction = PhpStormStubsSingleton::getPhpStormStubs()->getFunction($functionName); |
|
40 | + static::assertFalse( |
|
41 | + $function->is_deprecated && $stubFunction->is_deprecated !== true, |
|
42 | + "Function $functionName is not deprecated in stubs" |
|
43 | + ); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionFunctionsProvider::functionsForParamsAmountTestsProvider |
|
48 | - * @throws Exception|RuntimeException |
|
49 | - */ |
|
50 | - public function testFunctionsParametersAmount(PHPFunction $function) |
|
51 | - { |
|
52 | - $functionName = $function->name; |
|
53 | - $stubFunction = PhpStormStubsSingleton::getPhpStormStubs()->getFunction($functionName); |
|
54 | - $filteredStubParameters = array_filter( |
|
55 | - $stubFunction->parameters, |
|
56 | - fn ($parameter) => BasePHPElement::entitySuitsCurrentPhpVersion($parameter) |
|
57 | - ); |
|
58 | - $uniqueParameterNames = array_unique(array_map(fn (PHPParameter $parameter) => $parameter->name, $filteredStubParameters)); |
|
46 | + /** |
|
47 | + * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionFunctionsProvider::functionsForParamsAmountTestsProvider |
|
48 | + * @throws Exception|RuntimeException |
|
49 | + */ |
|
50 | + public function testFunctionsParametersAmount(PHPFunction $function) |
|
51 | + { |
|
52 | + $functionName = $function->name; |
|
53 | + $stubFunction = PhpStormStubsSingleton::getPhpStormStubs()->getFunction($functionName); |
|
54 | + $filteredStubParameters = array_filter( |
|
55 | + $stubFunction->parameters, |
|
56 | + fn ($parameter) => BasePHPElement::entitySuitsCurrentPhpVersion($parameter) |
|
57 | + ); |
|
58 | + $uniqueParameterNames = array_unique(array_map(fn (PHPParameter $parameter) => $parameter->name, $filteredStubParameters)); |
|
59 | 59 | |
60 | - static::assertSameSize( |
|
61 | - $function->parameters, |
|
62 | - $uniqueParameterNames, |
|
63 | - "Parameter number mismatch for function $functionName. |
|
60 | + static::assertSameSize( |
|
61 | + $function->parameters, |
|
62 | + $uniqueParameterNames, |
|
63 | + "Parameter number mismatch for function $functionName. |
|
64 | 64 | Expected: " . BaseStubsTest::getParameterRepresentation($function) . "\n" . |
65 | - 'Actual: ' . BaseStubsTest::getParameterRepresentation($stubFunction) |
|
66 | - ); |
|
67 | - } |
|
65 | + 'Actual: ' . BaseStubsTest::getParameterRepresentation($stubFunction) |
|
66 | + ); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @throws Exception|RuntimeException |
|
71 | - */ |
|
72 | - public function testFunctionsDuplicates() |
|
73 | - { |
|
74 | - $filtered = EntitiesFilter::getFiltered( |
|
75 | - PhpStormStubsSingleton::getPhpStormStubs()->getFunctions(), |
|
76 | - problemTypes: StubProblemType::HAS_DUPLICATION |
|
77 | - ); |
|
78 | - $duplicates = self::getDuplicatedFunctions($filtered); |
|
79 | - self::assertCount( |
|
80 | - 0, |
|
81 | - $duplicates, |
|
82 | - "Functions \"" . implode(', ', $duplicates) . |
|
83 | - "\" have duplicates in stubs.\nPlease use #[LanguageLevelTypeAware] or #[PhpStormStubsElementAvailable] if possible" |
|
84 | - ); |
|
85 | - } |
|
69 | + /** |
|
70 | + * @throws Exception|RuntimeException |
|
71 | + */ |
|
72 | + public function testFunctionsDuplicates() |
|
73 | + { |
|
74 | + $filtered = EntitiesFilter::getFiltered( |
|
75 | + PhpStormStubsSingleton::getPhpStormStubs()->getFunctions(), |
|
76 | + problemTypes: StubProblemType::HAS_DUPLICATION |
|
77 | + ); |
|
78 | + $duplicates = self::getDuplicatedFunctions($filtered); |
|
79 | + self::assertCount( |
|
80 | + 0, |
|
81 | + $duplicates, |
|
82 | + "Functions \"" . implode(', ', $duplicates) . |
|
83 | + "\" have duplicates in stubs.\nPlease use #[LanguageLevelTypeAware] or #[PhpStormStubsElementAvailable] if possible" |
|
84 | + ); |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionParametersProvider::functionParametersProvider |
|
89 | - * @throws RuntimeException |
|
90 | - */ |
|
91 | - public function testFunctionsOptionalParameters(PHPFunction $function, PHPParameter $parameter) |
|
92 | - { |
|
93 | - $phpstormFunction = PhpStormStubsSingleton::getPhpStormStubs()->getFunction($function->name); |
|
94 | - $stubParameters = array_filter($phpstormFunction->parameters, fn (PHPParameter $stubParameter) => $stubParameter->indexInSignature === $parameter->indexInSignature); |
|
95 | - /** @var PHPParameter $stubOptionalParameter */ |
|
96 | - $stubOptionalParameter = array_pop($stubParameters); |
|
97 | - self::assertEquals( |
|
98 | - $parameter->isOptional, |
|
99 | - $stubOptionalParameter->isOptional, |
|
100 | - sprintf( |
|
101 | - 'Reflection function %s %s optional parameter %s with index %d |
|
87 | + /** |
|
88 | + * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionParametersProvider::functionParametersProvider |
|
89 | + * @throws RuntimeException |
|
90 | + */ |
|
91 | + public function testFunctionsOptionalParameters(PHPFunction $function, PHPParameter $parameter) |
|
92 | + { |
|
93 | + $phpstormFunction = PhpStormStubsSingleton::getPhpStormStubs()->getFunction($function->name); |
|
94 | + $stubParameters = array_filter($phpstormFunction->parameters, fn (PHPParameter $stubParameter) => $stubParameter->indexInSignature === $parameter->indexInSignature); |
|
95 | + /** @var PHPParameter $stubOptionalParameter */ |
|
96 | + $stubOptionalParameter = array_pop($stubParameters); |
|
97 | + self::assertEquals( |
|
98 | + $parameter->isOptional, |
|
99 | + $stubOptionalParameter->isOptional, |
|
100 | + sprintf( |
|
101 | + 'Reflection function %s %s optional parameter %s with index %d |
|
102 | 102 | but stubs parameter %s with index %d %s', |
103 | - $function->name, |
|
104 | - $parameter->isOptional ? 'has' : 'has no', |
|
105 | - $parameter->name, |
|
106 | - $parameter->indexInSignature, |
|
107 | - $stubOptionalParameter->name, |
|
108 | - $stubOptionalParameter->indexInSignature, |
|
109 | - $stubOptionalParameter->isOptional ? 'is optional' : 'is not optional' |
|
110 | - ) |
|
111 | - ); |
|
112 | - } |
|
103 | + $function->name, |
|
104 | + $parameter->isOptional ? 'has' : 'has no', |
|
105 | + $parameter->name, |
|
106 | + $parameter->indexInSignature, |
|
107 | + $stubOptionalParameter->name, |
|
108 | + $stubOptionalParameter->indexInSignature, |
|
109 | + $stubOptionalParameter->isOptional ? 'is optional' : 'is not optional' |
|
110 | + ) |
|
111 | + ); |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionParametersProvider::methodOptionalParametersProvider |
|
116 | - * @throws RuntimeException |
|
117 | - */ |
|
118 | - public function testMethodsOptionalParameters(PHPClass|PHPInterface $class, PHPMethod $method, PHPParameter $parameter) |
|
119 | - { |
|
120 | - if ($class instanceof PHPClass) { |
|
121 | - $phpstormFunction = PhpStormStubsSingleton::getPhpStormStubs()->getClass($class->name)->getMethod($method->name); |
|
122 | - } else { |
|
123 | - $phpstormFunction = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($class->name)->getMethod($method->name); |
|
124 | - } |
|
125 | - $stubParameters = array_filter($phpstormFunction->parameters, fn (PHPParameter $stubParameter) => $stubParameter->indexInSignature === $parameter->indexInSignature); |
|
126 | - /** @var PHPParameter $stubOptionalParameter */ |
|
127 | - $stubOptionalParameter = array_pop($stubParameters); |
|
128 | - self::assertEquals( |
|
129 | - $parameter->isOptional, |
|
130 | - $stubOptionalParameter->isOptional, |
|
131 | - sprintf( |
|
132 | - 'Reflection method %s::%s has optional parameter %s with index %d but stub parameter %s with index %d is not optional', |
|
133 | - $class->name, |
|
134 | - $method->name, |
|
135 | - $parameter->name, |
|
136 | - $parameter->indexInSignature, |
|
137 | - $stubOptionalParameter->name, |
|
138 | - $stubOptionalParameter->indexInSignature |
|
139 | - ) |
|
140 | - ); |
|
141 | - } |
|
114 | + /** |
|
115 | + * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionParametersProvider::methodOptionalParametersProvider |
|
116 | + * @throws RuntimeException |
|
117 | + */ |
|
118 | + public function testMethodsOptionalParameters(PHPClass|PHPInterface $class, PHPMethod $method, PHPParameter $parameter) |
|
119 | + { |
|
120 | + if ($class instanceof PHPClass) { |
|
121 | + $phpstormFunction = PhpStormStubsSingleton::getPhpStormStubs()->getClass($class->name)->getMethod($method->name); |
|
122 | + } else { |
|
123 | + $phpstormFunction = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($class->name)->getMethod($method->name); |
|
124 | + } |
|
125 | + $stubParameters = array_filter($phpstormFunction->parameters, fn (PHPParameter $stubParameter) => $stubParameter->indexInSignature === $parameter->indexInSignature); |
|
126 | + /** @var PHPParameter $stubOptionalParameter */ |
|
127 | + $stubOptionalParameter = array_pop($stubParameters); |
|
128 | + self::assertEquals( |
|
129 | + $parameter->isOptional, |
|
130 | + $stubOptionalParameter->isOptional, |
|
131 | + sprintf( |
|
132 | + 'Reflection method %s::%s has optional parameter %s with index %d but stub parameter %s with index %d is not optional', |
|
133 | + $class->name, |
|
134 | + $method->name, |
|
135 | + $parameter->name, |
|
136 | + $parameter->indexInSignature, |
|
137 | + $stubOptionalParameter->name, |
|
138 | + $stubOptionalParameter->indexInSignature |
|
139 | + ) |
|
140 | + ); |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * @throws Exception |
|
145 | - */ |
|
146 | - public function testImplodeFunctionIsCorrect() |
|
147 | - { |
|
148 | - $implodeFunctions = array_filter( |
|
149 | - PhpStormStubsSingleton::getPhpStormStubs()->getFunctions(), |
|
150 | - fn (PHPFunction $function) => $function->name === 'implode' |
|
151 | - ); |
|
152 | - self::assertCount(1, $implodeFunctions); |
|
153 | - /** @var PHPFunction $implodeFunction */ |
|
154 | - $implodeFunction = array_pop($implodeFunctions); |
|
155 | - $implodeParameters = $implodeFunction->parameters; |
|
156 | - $separatorParameters = array_filter($implodeParameters, fn (PHPParameter $parameter) => $parameter->name === 'separator'); |
|
157 | - $arrayParameters = array_filter($implodeParameters, fn (PHPParameter $parameter) => $parameter->name === 'array'); |
|
158 | - /** @var PHPParameter $separatorParameter */ |
|
159 | - $separatorParameter = array_pop($separatorParameters); |
|
160 | - /** @var PHPParameter $arrayParameter */ |
|
161 | - $arrayParameter = array_pop($arrayParameters); |
|
162 | - self::assertCount(2, $implodeParameters); |
|
163 | - self::assertEquals(['array', 'string'], $separatorParameter->typesFromSignature); |
|
164 | - if (property_exists($separatorParameter->defaultValue, 'value')) { |
|
165 | - self::assertEquals('', $separatorParameter->defaultValue->value); |
|
166 | - } else { |
|
167 | - self::fail("Couldn't read default value"); |
|
168 | - } |
|
169 | - self::assertEquals(['?array'], $arrayParameter->typesFromSignature); |
|
170 | - self::assertEquals(['string'], $implodeFunction->returnTypesFromSignature); |
|
171 | - self::assertEquals(['string'], $implodeFunction->returnTypesFromPhpDoc); |
|
172 | - } |
|
143 | + /** |
|
144 | + * @throws Exception |
|
145 | + */ |
|
146 | + public function testImplodeFunctionIsCorrect() |
|
147 | + { |
|
148 | + $implodeFunctions = array_filter( |
|
149 | + PhpStormStubsSingleton::getPhpStormStubs()->getFunctions(), |
|
150 | + fn (PHPFunction $function) => $function->name === 'implode' |
|
151 | + ); |
|
152 | + self::assertCount(1, $implodeFunctions); |
|
153 | + /** @var PHPFunction $implodeFunction */ |
|
154 | + $implodeFunction = array_pop($implodeFunctions); |
|
155 | + $implodeParameters = $implodeFunction->parameters; |
|
156 | + $separatorParameters = array_filter($implodeParameters, fn (PHPParameter $parameter) => $parameter->name === 'separator'); |
|
157 | + $arrayParameters = array_filter($implodeParameters, fn (PHPParameter $parameter) => $parameter->name === 'array'); |
|
158 | + /** @var PHPParameter $separatorParameter */ |
|
159 | + $separatorParameter = array_pop($separatorParameters); |
|
160 | + /** @var PHPParameter $arrayParameter */ |
|
161 | + $arrayParameter = array_pop($arrayParameters); |
|
162 | + self::assertCount(2, $implodeParameters); |
|
163 | + self::assertEquals(['array', 'string'], $separatorParameter->typesFromSignature); |
|
164 | + if (property_exists($separatorParameter->defaultValue, 'value')) { |
|
165 | + self::assertEquals('', $separatorParameter->defaultValue->value); |
|
166 | + } else { |
|
167 | + self::fail("Couldn't read default value"); |
|
168 | + } |
|
169 | + self::assertEquals(['?array'], $arrayParameter->typesFromSignature); |
|
170 | + self::assertEquals(['string'], $implodeFunction->returnTypesFromSignature); |
|
171 | + self::assertEquals(['string'], $implodeFunction->returnTypesFromPhpDoc); |
|
172 | + } |
|
173 | 173 | } |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | $function->parameters, |
62 | 62 | $uniqueParameterNames, |
63 | 63 | "Parameter number mismatch for function $functionName. |
64 | - Expected: " . BaseStubsTest::getParameterRepresentation($function) . "\n" . |
|
65 | - 'Actual: ' . BaseStubsTest::getParameterRepresentation($stubFunction) |
|
64 | + Expected: ".BaseStubsTest::getParameterRepresentation($function)."\n". |
|
65 | + 'Actual: '.BaseStubsTest::getParameterRepresentation($stubFunction) |
|
66 | 66 | ); |
67 | 67 | } |
68 | 68 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | self::assertCount( |
80 | 80 | 0, |
81 | 81 | $duplicates, |
82 | - "Functions \"" . implode(', ', $duplicates) . |
|
82 | + "Functions \"".implode(', ', $duplicates). |
|
83 | 83 | "\" have duplicates in stubs.\nPlease use #[LanguageLevelTypeAware] or #[PhpStormStubsElementAvailable] if possible" |
84 | 84 | ); |
85 | 85 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionParametersProvider::methodOptionalParametersProvider |
116 | 116 | * @throws RuntimeException |
117 | 117 | */ |
118 | - public function testMethodsOptionalParameters(PHPClass|PHPInterface $class, PHPMethod $method, PHPParameter $parameter) |
|
118 | + public function testMethodsOptionalParameters(PHPClass | PHPInterface $class, PHPMethod $method, PHPParameter $parameter) |
|
119 | 119 | { |
120 | 120 | if ($class instanceof PHPClass) { |
121 | 121 | $phpstormFunction = PhpStormStubsSingleton::getPhpStormStubs()->getClass($class->name)->getMethod($method->name); |
@@ -15,8 +15,7 @@ |
||
15 | 15 | use StubTests\TestData\Providers\EntitiesFilter; |
16 | 16 | use StubTests\TestData\Providers\PhpStormStubsSingleton; |
17 | 17 | |
18 | -class BaseFunctionsTest extends BaseStubsTest |
|
19 | -{ |
|
18 | +class BaseFunctionsTest extends BaseStubsTest { |
|
20 | 19 | /** |
21 | 20 | * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionFunctionsProvider::allFunctionsProvider |
22 | 21 | * @throws Exception|RuntimeException |
@@ -17,333 +17,333 @@ |
||
17 | 17 | |
18 | 18 | class StubsTypeHintsTest extends BaseStubsTest |
19 | 19 | { |
20 | - /** |
|
21 | - * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionFunctionsProvider::allFunctionsProvider |
|
22 | - * @throws RuntimeException |
|
23 | - */ |
|
24 | - public function testFunctionsReturnTypeHints(PHPFunction $function) |
|
25 | - { |
|
26 | - $functionName = $function->name; |
|
27 | - $stubFunction = PhpStormStubsSingleton::getPhpStormStubs()->getFunction($functionName); |
|
28 | - $unifiedStubsReturnTypes = []; |
|
29 | - $unifiedStubsAttributesReturnTypes = []; |
|
30 | - $unifiedReflectionReturnTypes = []; |
|
31 | - self::convertNullableTypesToUnion($function->returnTypesFromSignature, $unifiedReflectionReturnTypes); |
|
32 | - if (!empty($stubFunction->returnTypesFromSignature)) { |
|
33 | - self::convertNullableTypesToUnion($stubFunction->returnTypesFromSignature, $unifiedStubsReturnTypes); |
|
34 | - } |
|
35 | - foreach ($stubFunction->returnTypesFromAttribute as $languageVersion => $listOfTypes) { |
|
36 | - $unifiedStubsAttributesReturnTypes[$languageVersion] = []; |
|
37 | - self::convertNullableTypesToUnion($listOfTypes, $unifiedStubsAttributesReturnTypes[$languageVersion]); |
|
38 | - } |
|
39 | - $conditionToCompareWithSignature = BaseStubsTest::isReflectionTypesMatchSignature( |
|
40 | - $unifiedReflectionReturnTypes, |
|
41 | - $unifiedStubsReturnTypes |
|
42 | - ); |
|
43 | - $typesFromAttribute = []; |
|
44 | - if (!empty($unifiedStubsAttributesReturnTypes)) { |
|
45 | - $typesFromAttribute = !empty($unifiedStubsAttributesReturnTypes[getenv('PHP_VERSION')]) ? |
|
46 | - $unifiedStubsAttributesReturnTypes[getenv('PHP_VERSION')] : |
|
47 | - $unifiedStubsAttributesReturnTypes['default']; |
|
48 | - } |
|
49 | - $conditionToCompareWithAttribute = BaseStubsTest::isReflectionTypesExistInAttributes($unifiedReflectionReturnTypes, $typesFromAttribute); |
|
50 | - $testCondition = $conditionToCompareWithSignature || $conditionToCompareWithAttribute; |
|
51 | - self::assertTrue($testCondition, "Function $functionName has invalid return type. |
|
20 | + /** |
|
21 | + * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionFunctionsProvider::allFunctionsProvider |
|
22 | + * @throws RuntimeException |
|
23 | + */ |
|
24 | + public function testFunctionsReturnTypeHints(PHPFunction $function) |
|
25 | + { |
|
26 | + $functionName = $function->name; |
|
27 | + $stubFunction = PhpStormStubsSingleton::getPhpStormStubs()->getFunction($functionName); |
|
28 | + $unifiedStubsReturnTypes = []; |
|
29 | + $unifiedStubsAttributesReturnTypes = []; |
|
30 | + $unifiedReflectionReturnTypes = []; |
|
31 | + self::convertNullableTypesToUnion($function->returnTypesFromSignature, $unifiedReflectionReturnTypes); |
|
32 | + if (!empty($stubFunction->returnTypesFromSignature)) { |
|
33 | + self::convertNullableTypesToUnion($stubFunction->returnTypesFromSignature, $unifiedStubsReturnTypes); |
|
34 | + } |
|
35 | + foreach ($stubFunction->returnTypesFromAttribute as $languageVersion => $listOfTypes) { |
|
36 | + $unifiedStubsAttributesReturnTypes[$languageVersion] = []; |
|
37 | + self::convertNullableTypesToUnion($listOfTypes, $unifiedStubsAttributesReturnTypes[$languageVersion]); |
|
38 | + } |
|
39 | + $conditionToCompareWithSignature = BaseStubsTest::isReflectionTypesMatchSignature( |
|
40 | + $unifiedReflectionReturnTypes, |
|
41 | + $unifiedStubsReturnTypes |
|
42 | + ); |
|
43 | + $typesFromAttribute = []; |
|
44 | + if (!empty($unifiedStubsAttributesReturnTypes)) { |
|
45 | + $typesFromAttribute = !empty($unifiedStubsAttributesReturnTypes[getenv('PHP_VERSION')]) ? |
|
46 | + $unifiedStubsAttributesReturnTypes[getenv('PHP_VERSION')] : |
|
47 | + $unifiedStubsAttributesReturnTypes['default']; |
|
48 | + } |
|
49 | + $conditionToCompareWithAttribute = BaseStubsTest::isReflectionTypesExistInAttributes($unifiedReflectionReturnTypes, $typesFromAttribute); |
|
50 | + $testCondition = $conditionToCompareWithSignature || $conditionToCompareWithAttribute; |
|
51 | + self::assertTrue($testCondition, "Function $functionName has invalid return type. |
|
52 | 52 | Reflection function has return type " . implode('|', $function->returnTypesFromSignature) . ' but stubs has return type ' . |
53 | - implode('|', $stubFunction->returnTypesFromSignature) . ' in signature and attribute has types ' . |
|
54 | - implode('|', $typesFromAttribute)); |
|
55 | - } |
|
53 | + implode('|', $stubFunction->returnTypesFromSignature) . ' in signature and attribute has types ' . |
|
54 | + implode('|', $typesFromAttribute)); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionParametersProvider::functionParametersWithTypeProvider |
|
59 | - * @throws RuntimeException |
|
60 | - */ |
|
61 | - public function testFunctionsParametersTypeHints(PHPFunction $function, PHPParameter $parameter) |
|
62 | - { |
|
63 | - $functionName = $function->name; |
|
64 | - $phpstormFunction = PhpStormStubsSingleton::getPhpStormStubs()->getFunction($functionName); |
|
65 | - /** @var PHPParameter $stubParameter */ |
|
66 | - $stubParameter = current(array_filter($phpstormFunction->parameters, fn (PHPParameter $stubParameter) => $stubParameter->indexInSignature === $parameter->indexInSignature)); |
|
67 | - self::compareTypeHintsWithReflection($parameter, $stubParameter, $functionName); |
|
68 | - if (!$parameter->hasMutedProblem(StubProblemType::PARAMETER_REFERENCE)) { |
|
69 | - self::assertEquals( |
|
70 | - $parameter->is_passed_by_ref, |
|
71 | - $stubParameter->is_passed_by_ref, |
|
72 | - "Invalid pass by ref $functionName: \$$parameter->name " |
|
73 | - ); |
|
74 | - } |
|
75 | - self::assertEquals( |
|
76 | - $parameter->is_vararg, |
|
77 | - $stubParameter->is_vararg, |
|
78 | - "Invalid vararg $functionName: \$$parameter->name " |
|
79 | - ); |
|
80 | - } |
|
57 | + /** |
|
58 | + * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionParametersProvider::functionParametersWithTypeProvider |
|
59 | + * @throws RuntimeException |
|
60 | + */ |
|
61 | + public function testFunctionsParametersTypeHints(PHPFunction $function, PHPParameter $parameter) |
|
62 | + { |
|
63 | + $functionName = $function->name; |
|
64 | + $phpstormFunction = PhpStormStubsSingleton::getPhpStormStubs()->getFunction($functionName); |
|
65 | + /** @var PHPParameter $stubParameter */ |
|
66 | + $stubParameter = current(array_filter($phpstormFunction->parameters, fn (PHPParameter $stubParameter) => $stubParameter->indexInSignature === $parameter->indexInSignature)); |
|
67 | + self::compareTypeHintsWithReflection($parameter, $stubParameter, $functionName); |
|
68 | + if (!$parameter->hasMutedProblem(StubProblemType::PARAMETER_REFERENCE)) { |
|
69 | + self::assertEquals( |
|
70 | + $parameter->is_passed_by_ref, |
|
71 | + $stubParameter->is_passed_by_ref, |
|
72 | + "Invalid pass by ref $functionName: \$$parameter->name " |
|
73 | + ); |
|
74 | + } |
|
75 | + self::assertEquals( |
|
76 | + $parameter->is_vararg, |
|
77 | + $stubParameter->is_vararg, |
|
78 | + "Invalid vararg $functionName: \$$parameter->name " |
|
79 | + ); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionMethodsProvider::classMethodsWithoutTentitiveReturnTypeProvider |
|
84 | - * @throws RuntimeException |
|
85 | - */ |
|
86 | - public function testMethodsReturnTypeHints(PHPClass|PHPInterface $class, PHPMethod $method) |
|
87 | - { |
|
88 | - $functionName = $method->name; |
|
89 | - if ($class instanceof PHPClass) { |
|
90 | - $stubMethod = PhpStormStubsSingleton::getPhpStormStubs()->getClass($class->name)->getMethod($functionName); |
|
91 | - } else { |
|
92 | - $stubMethod = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($class->name)->getMethod($functionName); |
|
93 | - } |
|
94 | - $unifiedStubsReturnTypes = []; |
|
95 | - $unifiedStubsAttributesReturnTypes = []; |
|
96 | - $unifiedReflectionReturnTypes = []; |
|
97 | - self::convertNullableTypesToUnion($method->returnTypesFromSignature, $unifiedReflectionReturnTypes); |
|
98 | - if (!empty($stubMethod->returnTypesFromSignature)) { |
|
99 | - self::convertNullableTypesToUnion($stubMethod->returnTypesFromSignature, $unifiedStubsReturnTypes); |
|
100 | - } else { |
|
101 | - foreach ($stubMethod->returnTypesFromAttribute as $languageVersion => $listOfTypes) { |
|
102 | - $unifiedStubsAttributesReturnTypes[$languageVersion] = []; |
|
103 | - self::convertNullableTypesToUnion($listOfTypes, $unifiedStubsAttributesReturnTypes[$languageVersion]); |
|
104 | - } |
|
105 | - } |
|
106 | - $conditionToCompareWithSignature = BaseStubsTest::isReflectionTypesMatchSignature( |
|
107 | - $unifiedReflectionReturnTypes, |
|
108 | - $unifiedStubsReturnTypes |
|
109 | - ); |
|
110 | - $typesFromAttribute = []; |
|
111 | - if (!empty($unifiedStubsAttributesReturnTypes)) { |
|
112 | - $typesFromAttribute = !empty($unifiedStubsAttributesReturnTypes[getenv('PHP_VERSION')]) ? |
|
113 | - $unifiedStubsAttributesReturnTypes[getenv('PHP_VERSION')] : |
|
114 | - $unifiedStubsAttributesReturnTypes['default']; |
|
115 | - } |
|
116 | - $conditionToCompareWithAttribute = BaseStubsTest::isReflectionTypesExistInAttributes($unifiedReflectionReturnTypes, $typesFromAttribute); |
|
117 | - $testCondition = $conditionToCompareWithSignature || $conditionToCompareWithAttribute; |
|
118 | - self::assertTrue($testCondition, "Method $class->name::$functionName has invalid return type. |
|
82 | + /** |
|
83 | + * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionMethodsProvider::classMethodsWithoutTentitiveReturnTypeProvider |
|
84 | + * @throws RuntimeException |
|
85 | + */ |
|
86 | + public function testMethodsReturnTypeHints(PHPClass|PHPInterface $class, PHPMethod $method) |
|
87 | + { |
|
88 | + $functionName = $method->name; |
|
89 | + if ($class instanceof PHPClass) { |
|
90 | + $stubMethod = PhpStormStubsSingleton::getPhpStormStubs()->getClass($class->name)->getMethod($functionName); |
|
91 | + } else { |
|
92 | + $stubMethod = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($class->name)->getMethod($functionName); |
|
93 | + } |
|
94 | + $unifiedStubsReturnTypes = []; |
|
95 | + $unifiedStubsAttributesReturnTypes = []; |
|
96 | + $unifiedReflectionReturnTypes = []; |
|
97 | + self::convertNullableTypesToUnion($method->returnTypesFromSignature, $unifiedReflectionReturnTypes); |
|
98 | + if (!empty($stubMethod->returnTypesFromSignature)) { |
|
99 | + self::convertNullableTypesToUnion($stubMethod->returnTypesFromSignature, $unifiedStubsReturnTypes); |
|
100 | + } else { |
|
101 | + foreach ($stubMethod->returnTypesFromAttribute as $languageVersion => $listOfTypes) { |
|
102 | + $unifiedStubsAttributesReturnTypes[$languageVersion] = []; |
|
103 | + self::convertNullableTypesToUnion($listOfTypes, $unifiedStubsAttributesReturnTypes[$languageVersion]); |
|
104 | + } |
|
105 | + } |
|
106 | + $conditionToCompareWithSignature = BaseStubsTest::isReflectionTypesMatchSignature( |
|
107 | + $unifiedReflectionReturnTypes, |
|
108 | + $unifiedStubsReturnTypes |
|
109 | + ); |
|
110 | + $typesFromAttribute = []; |
|
111 | + if (!empty($unifiedStubsAttributesReturnTypes)) { |
|
112 | + $typesFromAttribute = !empty($unifiedStubsAttributesReturnTypes[getenv('PHP_VERSION')]) ? |
|
113 | + $unifiedStubsAttributesReturnTypes[getenv('PHP_VERSION')] : |
|
114 | + $unifiedStubsAttributesReturnTypes['default']; |
|
115 | + } |
|
116 | + $conditionToCompareWithAttribute = BaseStubsTest::isReflectionTypesExistInAttributes($unifiedReflectionReturnTypes, $typesFromAttribute); |
|
117 | + $testCondition = $conditionToCompareWithSignature || $conditionToCompareWithAttribute; |
|
118 | + self::assertTrue($testCondition, "Method $class->name::$functionName has invalid return type. |
|
119 | 119 | Reflection method has return type " . implode('|', $method->returnTypesFromSignature) . ' but stubs has return type ' . |
120 | - implode('|', $stubMethod->returnTypesFromSignature) . ' in signature and attribute has types ' . |
|
121 | - implode('|', $typesFromAttribute)); |
|
122 | - } |
|
120 | + implode('|', $stubMethod->returnTypesFromSignature) . ' in signature and attribute has types ' . |
|
121 | + implode('|', $typesFromAttribute)); |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionParametersProvider::methodParametersProvider |
|
126 | - * @throws RuntimeException |
|
127 | - */ |
|
128 | - public function testMethodsParametersTypeHints(PHPClass|PHPInterface $reflectionClass, PHPMethod $reflectionMethod, PHPParameter $reflectionParameter) |
|
129 | - { |
|
130 | - $className = $reflectionClass->name; |
|
131 | - $methodName = $reflectionMethod->name; |
|
132 | - if ($reflectionClass instanceof PHPClass) { |
|
133 | - $stubMethod = PhpStormStubsSingleton::getPhpStormStubs()->getClass($className)->getMethod($methodName); |
|
134 | - } else { |
|
135 | - $stubMethod = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($className)->getMethod($methodName); |
|
136 | - } |
|
137 | - /** @var PHPParameter $stubParameter */ |
|
138 | - $stubParameter = current(array_filter( |
|
139 | - $stubMethod->parameters, |
|
140 | - fn (PHPParameter $stubParameter) => $stubParameter->name === $reflectionParameter->name |
|
141 | - )); |
|
142 | - self::assertNotFalse($stubParameter, "Parameter $$reflectionParameter->name not found at |
|
124 | + /** |
|
125 | + * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionParametersProvider::methodParametersProvider |
|
126 | + * @throws RuntimeException |
|
127 | + */ |
|
128 | + public function testMethodsParametersTypeHints(PHPClass|PHPInterface $reflectionClass, PHPMethod $reflectionMethod, PHPParameter $reflectionParameter) |
|
129 | + { |
|
130 | + $className = $reflectionClass->name; |
|
131 | + $methodName = $reflectionMethod->name; |
|
132 | + if ($reflectionClass instanceof PHPClass) { |
|
133 | + $stubMethod = PhpStormStubsSingleton::getPhpStormStubs()->getClass($className)->getMethod($methodName); |
|
134 | + } else { |
|
135 | + $stubMethod = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($className)->getMethod($methodName); |
|
136 | + } |
|
137 | + /** @var PHPParameter $stubParameter */ |
|
138 | + $stubParameter = current(array_filter( |
|
139 | + $stubMethod->parameters, |
|
140 | + fn (PHPParameter $stubParameter) => $stubParameter->name === $reflectionParameter->name |
|
141 | + )); |
|
142 | + self::assertNotFalse($stubParameter, "Parameter $$reflectionParameter->name not found at |
|
143 | 143 | $reflectionClass->name::$stubMethod->name(" . |
144 | - StubsParameterNamesTest::printParameters($stubMethod->parameters) . ')'); |
|
145 | - self::compareTypeHintsWithReflection($reflectionParameter, $stubParameter, $methodName); |
|
146 | - if (!$reflectionParameter->hasMutedProblem(StubProblemType::PARAMETER_REFERENCE)) { |
|
147 | - self::assertEquals( |
|
148 | - $reflectionParameter->is_passed_by_ref, |
|
149 | - $stubParameter->is_passed_by_ref, |
|
150 | - "Invalid pass by ref $className::$methodName: \$$reflectionParameter->name " |
|
151 | - ); |
|
152 | - } |
|
153 | - self::assertEquals( |
|
154 | - $reflectionParameter->is_vararg, |
|
155 | - $stubParameter->is_vararg, |
|
156 | - "Invalid pass by ref $className::$methodName: \$$reflectionParameter->name " |
|
157 | - ); |
|
158 | - } |
|
144 | + StubsParameterNamesTest::printParameters($stubMethod->parameters) . ')'); |
|
145 | + self::compareTypeHintsWithReflection($reflectionParameter, $stubParameter, $methodName); |
|
146 | + if (!$reflectionParameter->hasMutedProblem(StubProblemType::PARAMETER_REFERENCE)) { |
|
147 | + self::assertEquals( |
|
148 | + $reflectionParameter->is_passed_by_ref, |
|
149 | + $stubParameter->is_passed_by_ref, |
|
150 | + "Invalid pass by ref $className::$methodName: \$$reflectionParameter->name " |
|
151 | + ); |
|
152 | + } |
|
153 | + self::assertEquals( |
|
154 | + $reflectionParameter->is_vararg, |
|
155 | + $stubParameter->is_vararg, |
|
156 | + "Invalid pass by ref $className::$methodName: \$$reflectionParameter->name " |
|
157 | + ); |
|
158 | + } |
|
159 | 159 | |
160 | - /** |
|
161 | - * @dataProvider \StubTests\TestData\Providers\Stubs\StubsParametersProvider::parametersForScalarTypeHintTestsProvider |
|
162 | - * @throws RuntimeException |
|
163 | - */ |
|
164 | - public static function testMethodDoesNotHaveScalarTypeHintsInParameters(PHPClass|PHPInterface $class, PHPMethod $stubMethod, PHPParameter $parameter) |
|
165 | - { |
|
166 | - $sinceVersion = ParserUtils::getDeclaredSinceVersion($stubMethod); |
|
167 | - self::assertEmpty( |
|
168 | - array_intersect(['int', 'float', 'string', 'bool', 'mixed', 'object'], $parameter->typesFromSignature), |
|
169 | - "Method '$class->name::$stubMethod->name' with @since '$sinceVersion' |
|
160 | + /** |
|
161 | + * @dataProvider \StubTests\TestData\Providers\Stubs\StubsParametersProvider::parametersForScalarTypeHintTestsProvider |
|
162 | + * @throws RuntimeException |
|
163 | + */ |
|
164 | + public static function testMethodDoesNotHaveScalarTypeHintsInParameters(PHPClass|PHPInterface $class, PHPMethod $stubMethod, PHPParameter $parameter) |
|
165 | + { |
|
166 | + $sinceVersion = ParserUtils::getDeclaredSinceVersion($stubMethod); |
|
167 | + self::assertEmpty( |
|
168 | + array_intersect(['int', 'float', 'string', 'bool', 'mixed', 'object'], $parameter->typesFromSignature), |
|
169 | + "Method '$class->name::$stubMethod->name' with @since '$sinceVersion' |
|
170 | 170 | has parameter '$parameter->name' with typehint '" . implode('|', $parameter->typesFromSignature) . |
171 | - "' but typehints available only since php 7" |
|
172 | - ); |
|
173 | - } |
|
171 | + "' but typehints available only since php 7" |
|
172 | + ); |
|
173 | + } |
|
174 | 174 | |
175 | - /** |
|
176 | - * @dataProvider \StubTests\TestData\Providers\Stubs\StubsParametersProvider::parametersForNullableTypeHintTestsProvider |
|
177 | - * @throws RuntimeException |
|
178 | - */ |
|
179 | - public static function testMethodDoesNotHaveNullableTypeHintsInParameters(PHPClass|PHPInterface $class, PHPMethod $stubMethod, PHPParameter $parameter) |
|
180 | - { |
|
181 | - $sinceVersion = ParserUtils::getDeclaredSinceVersion($stubMethod); |
|
182 | - self::assertEmpty( |
|
183 | - array_filter($parameter->typesFromSignature, fn (string $type) => str_contains($type, '?')), |
|
184 | - "Method '$class->name::$stubMethod->name' with @since '$sinceVersion' |
|
175 | + /** |
|
176 | + * @dataProvider \StubTests\TestData\Providers\Stubs\StubsParametersProvider::parametersForNullableTypeHintTestsProvider |
|
177 | + * @throws RuntimeException |
|
178 | + */ |
|
179 | + public static function testMethodDoesNotHaveNullableTypeHintsInParameters(PHPClass|PHPInterface $class, PHPMethod $stubMethod, PHPParameter $parameter) |
|
180 | + { |
|
181 | + $sinceVersion = ParserUtils::getDeclaredSinceVersion($stubMethod); |
|
182 | + self::assertEmpty( |
|
183 | + array_filter($parameter->typesFromSignature, fn (string $type) => str_contains($type, '?')), |
|
184 | + "Method '$class->name::$stubMethod->name' with @since '$sinceVersion' |
|
185 | 185 | has nullable parameter '$parameter->name' with typehint '" . implode('|', $parameter->typesFromSignature) . "' |
186 | 186 | but nullable typehints available only since php 7.1" |
187 | - ); |
|
188 | - } |
|
187 | + ); |
|
188 | + } |
|
189 | 189 | |
190 | - /** |
|
191 | - * @dataProvider \StubTests\TestData\Providers\Stubs\StubsParametersProvider::parametersForUnionTypeHintTestsProvider |
|
192 | - * @throws RuntimeException |
|
193 | - */ |
|
194 | - public static function testMethodDoesNotHaveUnionTypeHintsInParameters(PHPClass|PHPInterface $class, PHPMethod $stubMethod, PHPParameter $parameter) |
|
195 | - { |
|
196 | - $sinceVersion = ParserUtils::getDeclaredSinceVersion($stubMethod); |
|
197 | - self::assertLessThan( |
|
198 | - 2, |
|
199 | - count($parameter->typesFromSignature), |
|
200 | - "Method '$class->name::$stubMethod->name' with @since '$sinceVersion' |
|
190 | + /** |
|
191 | + * @dataProvider \StubTests\TestData\Providers\Stubs\StubsParametersProvider::parametersForUnionTypeHintTestsProvider |
|
192 | + * @throws RuntimeException |
|
193 | + */ |
|
194 | + public static function testMethodDoesNotHaveUnionTypeHintsInParameters(PHPClass|PHPInterface $class, PHPMethod $stubMethod, PHPParameter $parameter) |
|
195 | + { |
|
196 | + $sinceVersion = ParserUtils::getDeclaredSinceVersion($stubMethod); |
|
197 | + self::assertLessThan( |
|
198 | + 2, |
|
199 | + count($parameter->typesFromSignature), |
|
200 | + "Method '$class->name::$stubMethod->name' with @since '$sinceVersion' |
|
201 | 201 | has parameter '$parameter->name' with union typehint '" . implode('|', $parameter->typesFromSignature) . "' |
202 | 202 | but union typehints available only since php 8.0" |
203 | - ); |
|
204 | - } |
|
203 | + ); |
|
204 | + } |
|
205 | 205 | |
206 | - /** |
|
207 | - * @dataProvider \StubTests\TestData\Providers\Stubs\StubMethodsProvider::methodsForReturnTypeHintTestsProvider |
|
208 | - * @throws RuntimeException |
|
209 | - */ |
|
210 | - public static function testMethodDoesNotHaveReturnTypeHint(PHPMethod $stubMethod) |
|
211 | - { |
|
212 | - $sinceVersion = ParserUtils::getDeclaredSinceVersion($stubMethod); |
|
213 | - self::assertEmpty($stubMethod->returnTypesFromSignature, "Method '$stubMethod->parentName::$stubMethod->name' has since version '$sinceVersion' |
|
206 | + /** |
|
207 | + * @dataProvider \StubTests\TestData\Providers\Stubs\StubMethodsProvider::methodsForReturnTypeHintTestsProvider |
|
208 | + * @throws RuntimeException |
|
209 | + */ |
|
210 | + public static function testMethodDoesNotHaveReturnTypeHint(PHPMethod $stubMethod) |
|
211 | + { |
|
212 | + $sinceVersion = ParserUtils::getDeclaredSinceVersion($stubMethod); |
|
213 | + self::assertEmpty($stubMethod->returnTypesFromSignature, "Method '$stubMethod->parentName::$stubMethod->name' has since version '$sinceVersion' |
|
214 | 214 | but has return typehint '" . implode('|', $stubMethod->returnTypesFromSignature) . "' that supported only since PHP 7. Please declare return type via PhpDoc"); |
215 | - } |
|
215 | + } |
|
216 | 216 | |
217 | - /** |
|
218 | - * @dataProvider \StubTests\TestData\Providers\Stubs\StubMethodsProvider::methodsForNullableReturnTypeHintTestsProvider |
|
219 | - * @throws RuntimeException |
|
220 | - */ |
|
221 | - public static function testMethodDoesNotHaveNullableReturnTypeHint(PHPMethod $stubMethod) |
|
222 | - { |
|
223 | - $sinceVersion = ParserUtils::getDeclaredSinceVersion($stubMethod); |
|
224 | - $returnTypes = $stubMethod->returnTypesFromSignature; |
|
225 | - self::assertEmpty( |
|
226 | - array_filter($returnTypes, fn (string $type) => str_contains($type, '?')), |
|
227 | - "Method '$stubMethod->parentName::$stubMethod->name' has since version '$sinceVersion' |
|
217 | + /** |
|
218 | + * @dataProvider \StubTests\TestData\Providers\Stubs\StubMethodsProvider::methodsForNullableReturnTypeHintTestsProvider |
|
219 | + * @throws RuntimeException |
|
220 | + */ |
|
221 | + public static function testMethodDoesNotHaveNullableReturnTypeHint(PHPMethod $stubMethod) |
|
222 | + { |
|
223 | + $sinceVersion = ParserUtils::getDeclaredSinceVersion($stubMethod); |
|
224 | + $returnTypes = $stubMethod->returnTypesFromSignature; |
|
225 | + self::assertEmpty( |
|
226 | + array_filter($returnTypes, fn (string $type) => str_contains($type, '?')), |
|
227 | + "Method '$stubMethod->parentName::$stubMethod->name' has since version '$sinceVersion' |
|
228 | 228 | but has nullable return typehint '" . implode('|', $returnTypes) . "' that supported only since PHP 7.1. |
229 | 229 | Please declare return type via PhpDoc" |
230 | - ); |
|
231 | - } |
|
230 | + ); |
|
231 | + } |
|
232 | 232 | |
233 | - /** |
|
234 | - * @dataProvider \StubTests\TestData\Providers\Stubs\StubMethodsProvider::methodsForUnionReturnTypeHintTestsProvider |
|
235 | - * @throws RuntimeException |
|
236 | - */ |
|
237 | - public static function testMethodDoesNotHaveUnionReturnTypeHint(PHPMethod $stubMethod) |
|
238 | - { |
|
239 | - $sinceVersion = ParserUtils::getDeclaredSinceVersion($stubMethod); |
|
240 | - self::assertLessThan( |
|
241 | - 2, |
|
242 | - count($stubMethod->returnTypesFromSignature), |
|
243 | - "Method '$stubMethod->parentName::$stubMethod->name' has since version '$sinceVersion' |
|
233 | + /** |
|
234 | + * @dataProvider \StubTests\TestData\Providers\Stubs\StubMethodsProvider::methodsForUnionReturnTypeHintTestsProvider |
|
235 | + * @throws RuntimeException |
|
236 | + */ |
|
237 | + public static function testMethodDoesNotHaveUnionReturnTypeHint(PHPMethod $stubMethod) |
|
238 | + { |
|
239 | + $sinceVersion = ParserUtils::getDeclaredSinceVersion($stubMethod); |
|
240 | + self::assertLessThan( |
|
241 | + 2, |
|
242 | + count($stubMethod->returnTypesFromSignature), |
|
243 | + "Method '$stubMethod->parentName::$stubMethod->name' has since version '$sinceVersion' |
|
244 | 244 | but has union return typehint '" . implode('|', $stubMethod->returnTypesFromSignature) . "' that supported only since PHP 8.0. |
245 | 245 | Please declare return type via PhpDoc" |
246 | - ); |
|
247 | - } |
|
246 | + ); |
|
247 | + } |
|
248 | 248 | |
249 | - /** |
|
250 | - * @dataProvider \StubTests\TestData\Providers\Stubs\StubsParametersProvider::parametersForAllowedScalarTypeHintTestsProvider |
|
251 | - * @throws RuntimeException |
|
252 | - */ |
|
253 | - public function testMethodScalarTypeHintsInParametersMatchReflection(PHPClass|PHPInterface $class, PHPMethod $stubMethod, PHPParameter $stubParameter) |
|
254 | - { |
|
255 | - $reflectionMethod = ReflectionStubsSingleton::getReflectionStubs()->getClass($class->name)->getMethod($stubMethod->name); |
|
256 | - $reflectionParameters = array_filter($reflectionMethod->parameters, fn (PHPParameter $parameter) => $parameter->name === $stubParameter->name); |
|
257 | - $reflectionParameter = array_pop($reflectionParameters); |
|
258 | - self::compareTypeHintsWithReflection($reflectionParameter, $stubParameter, $stubMethod->name); |
|
259 | - } |
|
249 | + /** |
|
250 | + * @dataProvider \StubTests\TestData\Providers\Stubs\StubsParametersProvider::parametersForAllowedScalarTypeHintTestsProvider |
|
251 | + * @throws RuntimeException |
|
252 | + */ |
|
253 | + public function testMethodScalarTypeHintsInParametersMatchReflection(PHPClass|PHPInterface $class, PHPMethod $stubMethod, PHPParameter $stubParameter) |
|
254 | + { |
|
255 | + $reflectionMethod = ReflectionStubsSingleton::getReflectionStubs()->getClass($class->name)->getMethod($stubMethod->name); |
|
256 | + $reflectionParameters = array_filter($reflectionMethod->parameters, fn (PHPParameter $parameter) => $parameter->name === $stubParameter->name); |
|
257 | + $reflectionParameter = array_pop($reflectionParameters); |
|
258 | + self::compareTypeHintsWithReflection($reflectionParameter, $stubParameter, $stubMethod->name); |
|
259 | + } |
|
260 | 260 | |
261 | - /** |
|
262 | - * @dataProvider \StubTests\TestData\Providers\Stubs\StubsParametersProvider::parametersForAllowedNullableTypeHintTestsProvider |
|
263 | - * @throws RuntimeException |
|
264 | - */ |
|
265 | - public function testMethodNullableTypeHintsInParametersMatchReflection(PHPClass|PHPInterface $class, PHPMethod $stubMethod, PHPParameter $stubParameter) |
|
266 | - { |
|
267 | - $reflectionMethod = ReflectionStubsSingleton::getReflectionStubs()->getClass($class->name)->getMethod($stubMethod->name); |
|
268 | - $reflectionParameters = array_filter($reflectionMethod->parameters, fn (PHPParameter $parameter) => $parameter->name === $stubParameter->name); |
|
269 | - $reflectionParameter = array_pop($reflectionParameters); |
|
270 | - self::compareTypeHintsWithReflection($reflectionParameter, $stubParameter, $stubMethod->name); |
|
271 | - } |
|
261 | + /** |
|
262 | + * @dataProvider \StubTests\TestData\Providers\Stubs\StubsParametersProvider::parametersForAllowedNullableTypeHintTestsProvider |
|
263 | + * @throws RuntimeException |
|
264 | + */ |
|
265 | + public function testMethodNullableTypeHintsInParametersMatchReflection(PHPClass|PHPInterface $class, PHPMethod $stubMethod, PHPParameter $stubParameter) |
|
266 | + { |
|
267 | + $reflectionMethod = ReflectionStubsSingleton::getReflectionStubs()->getClass($class->name)->getMethod($stubMethod->name); |
|
268 | + $reflectionParameters = array_filter($reflectionMethod->parameters, fn (PHPParameter $parameter) => $parameter->name === $stubParameter->name); |
|
269 | + $reflectionParameter = array_pop($reflectionParameters); |
|
270 | + self::compareTypeHintsWithReflection($reflectionParameter, $stubParameter, $stubMethod->name); |
|
271 | + } |
|
272 | 272 | |
273 | - /** |
|
274 | - * @dataProvider \StubTests\TestData\Providers\Stubs\StubsParametersProvider::parametersForAllowedUnionTypeHintTestsProvider |
|
275 | - * @throws RuntimeException |
|
276 | - */ |
|
277 | - public function testMethodUnionTypeHintsInParametersMatchReflection(PHPClass|PHPInterface $class, PHPMethod $stubMethod, PHPParameter $stubParameter) |
|
278 | - { |
|
279 | - $reflectionMethod = ReflectionStubsSingleton::getReflectionStubs()->getClass($class->name)->getMethod($stubMethod->name); |
|
280 | - $reflectionParameters = array_filter($reflectionMethod->parameters, fn (PHPParameter $parameter) => $parameter->name === $stubParameter->name); |
|
281 | - $reflectionParameter = array_pop($reflectionParameters); |
|
282 | - self::compareTypeHintsWithReflection($reflectionParameter, $stubParameter, $stubMethod->name); |
|
283 | - } |
|
273 | + /** |
|
274 | + * @dataProvider \StubTests\TestData\Providers\Stubs\StubsParametersProvider::parametersForAllowedUnionTypeHintTestsProvider |
|
275 | + * @throws RuntimeException |
|
276 | + */ |
|
277 | + public function testMethodUnionTypeHintsInParametersMatchReflection(PHPClass|PHPInterface $class, PHPMethod $stubMethod, PHPParameter $stubParameter) |
|
278 | + { |
|
279 | + $reflectionMethod = ReflectionStubsSingleton::getReflectionStubs()->getClass($class->name)->getMethod($stubMethod->name); |
|
280 | + $reflectionParameters = array_filter($reflectionMethod->parameters, fn (PHPParameter $parameter) => $parameter->name === $stubParameter->name); |
|
281 | + $reflectionParameter = array_pop($reflectionParameters); |
|
282 | + self::compareTypeHintsWithReflection($reflectionParameter, $stubParameter, $stubMethod->name); |
|
283 | + } |
|
284 | 284 | |
285 | - /** |
|
286 | - * @dataProvider \StubTests\TestData\Providers\Stubs\StubMethodsProvider::allFunctionAndMethodsWithReturnTypeHintsProvider |
|
287 | - * @throws Exception |
|
288 | - */ |
|
289 | - public static function testSignatureTypeHintsComplainPhpDocInMethods(PHPFunction|PHPMethod $method) |
|
290 | - { |
|
291 | - $functionName = $method->name; |
|
292 | - $unifiedPhpDocTypes = array_map(function (string $type) { |
|
293 | - $typeParts = explode('\\', $type); |
|
294 | - $typeName = end($typeParts); |
|
285 | + /** |
|
286 | + * @dataProvider \StubTests\TestData\Providers\Stubs\StubMethodsProvider::allFunctionAndMethodsWithReturnTypeHintsProvider |
|
287 | + * @throws Exception |
|
288 | + */ |
|
289 | + public static function testSignatureTypeHintsComplainPhpDocInMethods(PHPFunction|PHPMethod $method) |
|
290 | + { |
|
291 | + $functionName = $method->name; |
|
292 | + $unifiedPhpDocTypes = array_map(function (string $type) { |
|
293 | + $typeParts = explode('\\', $type); |
|
294 | + $typeName = end($typeParts); |
|
295 | 295 | |
296 | - // replace array notations like int[] or array<string,mixed> to match the array type |
|
297 | - return preg_replace(['/\w+\[]/', '/array<[a-z,\s]+>/'], 'array', $typeName); |
|
298 | - }, $method->returnTypesFromPhpDoc); |
|
299 | - $unifiedSignatureTypes = $method->returnTypesFromSignature; |
|
300 | - if (count($unifiedSignatureTypes) === 1) { |
|
301 | - $unifiedSignatureTypes = []; |
|
302 | - $type = array_pop($method->returnTypesFromSignature); |
|
303 | - if (str_contains($type, '?')) { |
|
304 | - array_push($unifiedSignatureTypes, 'null'); |
|
305 | - } |
|
306 | - $typeParts = explode('\\', ltrim($type, '?')); |
|
307 | - $typeName = end($typeParts); |
|
308 | - array_push($unifiedSignatureTypes, $typeName); |
|
309 | - } |
|
310 | - $typesIntersection = array_intersect($unifiedSignatureTypes, $unifiedPhpDocTypes); |
|
311 | - self::assertSameSize( |
|
312 | - $unifiedSignatureTypes, |
|
313 | - $typesIntersection, |
|
314 | - $method instanceof PHPMethod ? "Method $method->parentName::" : 'Function ' . |
|
315 | - "$functionName has mismatch in phpdoc return type and signature return type\n |
|
296 | + // replace array notations like int[] or array<string,mixed> to match the array type |
|
297 | + return preg_replace(['/\w+\[]/', '/array<[a-z,\s]+>/'], 'array', $typeName); |
|
298 | + }, $method->returnTypesFromPhpDoc); |
|
299 | + $unifiedSignatureTypes = $method->returnTypesFromSignature; |
|
300 | + if (count($unifiedSignatureTypes) === 1) { |
|
301 | + $unifiedSignatureTypes = []; |
|
302 | + $type = array_pop($method->returnTypesFromSignature); |
|
303 | + if (str_contains($type, '?')) { |
|
304 | + array_push($unifiedSignatureTypes, 'null'); |
|
305 | + } |
|
306 | + $typeParts = explode('\\', ltrim($type, '?')); |
|
307 | + $typeName = end($typeParts); |
|
308 | + array_push($unifiedSignatureTypes, $typeName); |
|
309 | + } |
|
310 | + $typesIntersection = array_intersect($unifiedSignatureTypes, $unifiedPhpDocTypes); |
|
311 | + self::assertSameSize( |
|
312 | + $unifiedSignatureTypes, |
|
313 | + $typesIntersection, |
|
314 | + $method instanceof PHPMethod ? "Method $method->parentName::" : 'Function ' . |
|
315 | + "$functionName has mismatch in phpdoc return type and signature return type\n |
|
316 | 316 | signature has " . implode('|', $unifiedSignatureTypes) . "\n |
317 | 317 | but phpdoc has " . implode('|', $unifiedPhpDocTypes) |
318 | - ); |
|
319 | - } |
|
318 | + ); |
|
319 | + } |
|
320 | 320 | |
321 | - private static function compareTypeHintsWithReflection(PHPParameter $parameter, PHPParameter $stubParameter, ?string $functionName): void |
|
322 | - { |
|
323 | - $unifiedStubsParameterTypes = []; |
|
324 | - $unifiedStubsAttributesParameterTypes = []; |
|
325 | - $unifiedReflectionParameterTypes = []; |
|
326 | - self::convertNullableTypesToUnion($parameter->typesFromSignature, $unifiedReflectionParameterTypes); |
|
327 | - if (!empty($stubParameter->typesFromSignature)) { |
|
328 | - self::convertNullableTypesToUnion($stubParameter->typesFromSignature, $unifiedStubsParameterTypes); |
|
329 | - } |
|
330 | - foreach ($stubParameter->typesFromAttribute as $languageVersion => $listOfTypes) { |
|
331 | - $unifiedStubsAttributesParameterTypes[$languageVersion] = []; |
|
332 | - self::convertNullableTypesToUnion($listOfTypes, $unifiedStubsAttributesParameterTypes[$languageVersion]); |
|
333 | - } |
|
334 | - $typesFromAttribute = []; |
|
335 | - $testCondition = BaseStubsTest::isReflectionTypesMatchSignature($unifiedReflectionParameterTypes, $unifiedStubsParameterTypes); |
|
336 | - if (!$testCondition) { |
|
337 | - if (!empty($unifiedStubsAttributesParameterTypes)) { |
|
338 | - $typesFromAttribute = !empty($unifiedStubsAttributesParameterTypes[getenv('PHP_VERSION')]) ? |
|
339 | - $unifiedStubsAttributesParameterTypes[getenv('PHP_VERSION')] : |
|
340 | - $unifiedStubsAttributesParameterTypes['default']; |
|
341 | - $testCondition = BaseStubsTest::isReflectionTypesExistInAttributes($unifiedReflectionParameterTypes, $typesFromAttribute); |
|
342 | - } |
|
343 | - } |
|
344 | - self::assertTrue($testCondition, "Type mismatch $functionName: \$$parameter->name \n |
|
321 | + private static function compareTypeHintsWithReflection(PHPParameter $parameter, PHPParameter $stubParameter, ?string $functionName): void |
|
322 | + { |
|
323 | + $unifiedStubsParameterTypes = []; |
|
324 | + $unifiedStubsAttributesParameterTypes = []; |
|
325 | + $unifiedReflectionParameterTypes = []; |
|
326 | + self::convertNullableTypesToUnion($parameter->typesFromSignature, $unifiedReflectionParameterTypes); |
|
327 | + if (!empty($stubParameter->typesFromSignature)) { |
|
328 | + self::convertNullableTypesToUnion($stubParameter->typesFromSignature, $unifiedStubsParameterTypes); |
|
329 | + } |
|
330 | + foreach ($stubParameter->typesFromAttribute as $languageVersion => $listOfTypes) { |
|
331 | + $unifiedStubsAttributesParameterTypes[$languageVersion] = []; |
|
332 | + self::convertNullableTypesToUnion($listOfTypes, $unifiedStubsAttributesParameterTypes[$languageVersion]); |
|
333 | + } |
|
334 | + $typesFromAttribute = []; |
|
335 | + $testCondition = BaseStubsTest::isReflectionTypesMatchSignature($unifiedReflectionParameterTypes, $unifiedStubsParameterTypes); |
|
336 | + if (!$testCondition) { |
|
337 | + if (!empty($unifiedStubsAttributesParameterTypes)) { |
|
338 | + $typesFromAttribute = !empty($unifiedStubsAttributesParameterTypes[getenv('PHP_VERSION')]) ? |
|
339 | + $unifiedStubsAttributesParameterTypes[getenv('PHP_VERSION')] : |
|
340 | + $unifiedStubsAttributesParameterTypes['default']; |
|
341 | + $testCondition = BaseStubsTest::isReflectionTypesExistInAttributes($unifiedReflectionParameterTypes, $typesFromAttribute); |
|
342 | + } |
|
343 | + } |
|
344 | + self::assertTrue($testCondition, "Type mismatch $functionName: \$$parameter->name \n |
|
345 | 345 | Reflection parameter $parameter->name with index $parameter->indexInSignature has type '" . implode('|', $unifiedReflectionParameterTypes) . |
346 | - "' but stub parameter $stubParameter->name with index $stubParameter->indexInSignature has type '" . implode('|', $unifiedStubsParameterTypes) . "' in signature and " . |
|
347 | - implode('|', $typesFromAttribute) . ' in attribute'); |
|
348 | - } |
|
346 | + "' but stub parameter $stubParameter->name with index $stubParameter->indexInSignature has type '" . implode('|', $unifiedStubsParameterTypes) . "' in signature and " . |
|
347 | + implode('|', $typesFromAttribute) . ' in attribute'); |
|
348 | + } |
|
349 | 349 | } |
@@ -43,14 +43,13 @@ discard block |
||
43 | 43 | $typesFromAttribute = []; |
44 | 44 | if (!empty($unifiedStubsAttributesReturnTypes)) { |
45 | 45 | $typesFromAttribute = !empty($unifiedStubsAttributesReturnTypes[getenv('PHP_VERSION')]) ? |
46 | - $unifiedStubsAttributesReturnTypes[getenv('PHP_VERSION')] : |
|
47 | - $unifiedStubsAttributesReturnTypes['default']; |
|
46 | + $unifiedStubsAttributesReturnTypes[getenv('PHP_VERSION')] : $unifiedStubsAttributesReturnTypes['default']; |
|
48 | 47 | } |
49 | 48 | $conditionToCompareWithAttribute = BaseStubsTest::isReflectionTypesExistInAttributes($unifiedReflectionReturnTypes, $typesFromAttribute); |
50 | 49 | $testCondition = $conditionToCompareWithSignature || $conditionToCompareWithAttribute; |
51 | 50 | self::assertTrue($testCondition, "Function $functionName has invalid return type. |
52 | - Reflection function has return type " . implode('|', $function->returnTypesFromSignature) . ' but stubs has return type ' . |
|
53 | - implode('|', $stubFunction->returnTypesFromSignature) . ' in signature and attribute has types ' . |
|
51 | + Reflection function has return type ".implode('|', $function->returnTypesFromSignature).' but stubs has return type '. |
|
52 | + implode('|', $stubFunction->returnTypesFromSignature).' in signature and attribute has types '. |
|
54 | 53 | implode('|', $typesFromAttribute)); |
55 | 54 | } |
56 | 55 | |
@@ -83,7 +82,7 @@ discard block |
||
83 | 82 | * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionMethodsProvider::classMethodsWithoutTentitiveReturnTypeProvider |
84 | 83 | * @throws RuntimeException |
85 | 84 | */ |
86 | - public function testMethodsReturnTypeHints(PHPClass|PHPInterface $class, PHPMethod $method) |
|
85 | + public function testMethodsReturnTypeHints(PHPClass | PHPInterface $class, PHPMethod $method) |
|
87 | 86 | { |
88 | 87 | $functionName = $method->name; |
89 | 88 | if ($class instanceof PHPClass) { |
@@ -110,14 +109,13 @@ discard block |
||
110 | 109 | $typesFromAttribute = []; |
111 | 110 | if (!empty($unifiedStubsAttributesReturnTypes)) { |
112 | 111 | $typesFromAttribute = !empty($unifiedStubsAttributesReturnTypes[getenv('PHP_VERSION')]) ? |
113 | - $unifiedStubsAttributesReturnTypes[getenv('PHP_VERSION')] : |
|
114 | - $unifiedStubsAttributesReturnTypes['default']; |
|
112 | + $unifiedStubsAttributesReturnTypes[getenv('PHP_VERSION')] : $unifiedStubsAttributesReturnTypes['default']; |
|
115 | 113 | } |
116 | 114 | $conditionToCompareWithAttribute = BaseStubsTest::isReflectionTypesExistInAttributes($unifiedReflectionReturnTypes, $typesFromAttribute); |
117 | 115 | $testCondition = $conditionToCompareWithSignature || $conditionToCompareWithAttribute; |
118 | 116 | self::assertTrue($testCondition, "Method $class->name::$functionName has invalid return type. |
119 | - Reflection method has return type " . implode('|', $method->returnTypesFromSignature) . ' but stubs has return type ' . |
|
120 | - implode('|', $stubMethod->returnTypesFromSignature) . ' in signature and attribute has types ' . |
|
117 | + Reflection method has return type ".implode('|', $method->returnTypesFromSignature).' but stubs has return type '. |
|
118 | + implode('|', $stubMethod->returnTypesFromSignature).' in signature and attribute has types '. |
|
121 | 119 | implode('|', $typesFromAttribute)); |
122 | 120 | } |
123 | 121 | |
@@ -125,7 +123,7 @@ discard block |
||
125 | 123 | * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionParametersProvider::methodParametersProvider |
126 | 124 | * @throws RuntimeException |
127 | 125 | */ |
128 | - public function testMethodsParametersTypeHints(PHPClass|PHPInterface $reflectionClass, PHPMethod $reflectionMethod, PHPParameter $reflectionParameter) |
|
126 | + public function testMethodsParametersTypeHints(PHPClass | PHPInterface $reflectionClass, PHPMethod $reflectionMethod, PHPParameter $reflectionParameter) |
|
129 | 127 | { |
130 | 128 | $className = $reflectionClass->name; |
131 | 129 | $methodName = $reflectionMethod->name; |
@@ -140,8 +138,8 @@ discard block |
||
140 | 138 | fn (PHPParameter $stubParameter) => $stubParameter->name === $reflectionParameter->name |
141 | 139 | )); |
142 | 140 | self::assertNotFalse($stubParameter, "Parameter $$reflectionParameter->name not found at |
143 | - $reflectionClass->name::$stubMethod->name(" . |
|
144 | - StubsParameterNamesTest::printParameters($stubMethod->parameters) . ')'); |
|
141 | + $reflectionClass->name::$stubMethod->name(". |
|
142 | + StubsParameterNamesTest::printParameters($stubMethod->parameters).')'); |
|
145 | 143 | self::compareTypeHintsWithReflection($reflectionParameter, $stubParameter, $methodName); |
146 | 144 | if (!$reflectionParameter->hasMutedProblem(StubProblemType::PARAMETER_REFERENCE)) { |
147 | 145 | self::assertEquals( |
@@ -161,13 +159,13 @@ discard block |
||
161 | 159 | * @dataProvider \StubTests\TestData\Providers\Stubs\StubsParametersProvider::parametersForScalarTypeHintTestsProvider |
162 | 160 | * @throws RuntimeException |
163 | 161 | */ |
164 | - public static function testMethodDoesNotHaveScalarTypeHintsInParameters(PHPClass|PHPInterface $class, PHPMethod $stubMethod, PHPParameter $parameter) |
|
162 | + public static function testMethodDoesNotHaveScalarTypeHintsInParameters(PHPClass | PHPInterface $class, PHPMethod $stubMethod, PHPParameter $parameter) |
|
165 | 163 | { |
166 | 164 | $sinceVersion = ParserUtils::getDeclaredSinceVersion($stubMethod); |
167 | 165 | self::assertEmpty( |
168 | 166 | array_intersect(['int', 'float', 'string', 'bool', 'mixed', 'object'], $parameter->typesFromSignature), |
169 | 167 | "Method '$class->name::$stubMethod->name' with @since '$sinceVersion' |
170 | - has parameter '$parameter->name' with typehint '" . implode('|', $parameter->typesFromSignature) . |
|
168 | + has parameter '$parameter->name' with typehint '".implode('|', $parameter->typesFromSignature). |
|
171 | 169 | "' but typehints available only since php 7" |
172 | 170 | ); |
173 | 171 | } |
@@ -176,13 +174,13 @@ discard block |
||
176 | 174 | * @dataProvider \StubTests\TestData\Providers\Stubs\StubsParametersProvider::parametersForNullableTypeHintTestsProvider |
177 | 175 | * @throws RuntimeException |
178 | 176 | */ |
179 | - public static function testMethodDoesNotHaveNullableTypeHintsInParameters(PHPClass|PHPInterface $class, PHPMethod $stubMethod, PHPParameter $parameter) |
|
177 | + public static function testMethodDoesNotHaveNullableTypeHintsInParameters(PHPClass | PHPInterface $class, PHPMethod $stubMethod, PHPParameter $parameter) |
|
180 | 178 | { |
181 | 179 | $sinceVersion = ParserUtils::getDeclaredSinceVersion($stubMethod); |
182 | 180 | self::assertEmpty( |
183 | 181 | array_filter($parameter->typesFromSignature, fn (string $type) => str_contains($type, '?')), |
184 | 182 | "Method '$class->name::$stubMethod->name' with @since '$sinceVersion' |
185 | - has nullable parameter '$parameter->name' with typehint '" . implode('|', $parameter->typesFromSignature) . "' |
|
183 | + has nullable parameter '$parameter->name' with typehint '".implode('|', $parameter->typesFromSignature)."' |
|
186 | 184 | but nullable typehints available only since php 7.1" |
187 | 185 | ); |
188 | 186 | } |
@@ -191,14 +189,14 @@ discard block |
||
191 | 189 | * @dataProvider \StubTests\TestData\Providers\Stubs\StubsParametersProvider::parametersForUnionTypeHintTestsProvider |
192 | 190 | * @throws RuntimeException |
193 | 191 | */ |
194 | - public static function testMethodDoesNotHaveUnionTypeHintsInParameters(PHPClass|PHPInterface $class, PHPMethod $stubMethod, PHPParameter $parameter) |
|
192 | + public static function testMethodDoesNotHaveUnionTypeHintsInParameters(PHPClass | PHPInterface $class, PHPMethod $stubMethod, PHPParameter $parameter) |
|
195 | 193 | { |
196 | 194 | $sinceVersion = ParserUtils::getDeclaredSinceVersion($stubMethod); |
197 | 195 | self::assertLessThan( |
198 | 196 | 2, |
199 | 197 | count($parameter->typesFromSignature), |
200 | 198 | "Method '$class->name::$stubMethod->name' with @since '$sinceVersion' |
201 | - has parameter '$parameter->name' with union typehint '" . implode('|', $parameter->typesFromSignature) . "' |
|
199 | + has parameter '$parameter->name' with union typehint '".implode('|', $parameter->typesFromSignature)."' |
|
202 | 200 | but union typehints available only since php 8.0" |
203 | 201 | ); |
204 | 202 | } |
@@ -211,7 +209,7 @@ discard block |
||
211 | 209 | { |
212 | 210 | $sinceVersion = ParserUtils::getDeclaredSinceVersion($stubMethod); |
213 | 211 | self::assertEmpty($stubMethod->returnTypesFromSignature, "Method '$stubMethod->parentName::$stubMethod->name' has since version '$sinceVersion' |
214 | - but has return typehint '" . implode('|', $stubMethod->returnTypesFromSignature) . "' that supported only since PHP 7. Please declare return type via PhpDoc"); |
|
212 | + but has return typehint '".implode('|', $stubMethod->returnTypesFromSignature)."' that supported only since PHP 7. Please declare return type via PhpDoc"); |
|
215 | 213 | } |
216 | 214 | |
217 | 215 | /** |
@@ -225,7 +223,7 @@ discard block |
||
225 | 223 | self::assertEmpty( |
226 | 224 | array_filter($returnTypes, fn (string $type) => str_contains($type, '?')), |
227 | 225 | "Method '$stubMethod->parentName::$stubMethod->name' has since version '$sinceVersion' |
228 | - but has nullable return typehint '" . implode('|', $returnTypes) . "' that supported only since PHP 7.1. |
|
226 | + but has nullable return typehint '".implode('|', $returnTypes)."' that supported only since PHP 7.1. |
|
229 | 227 | Please declare return type via PhpDoc" |
230 | 228 | ); |
231 | 229 | } |
@@ -241,7 +239,7 @@ discard block |
||
241 | 239 | 2, |
242 | 240 | count($stubMethod->returnTypesFromSignature), |
243 | 241 | "Method '$stubMethod->parentName::$stubMethod->name' has since version '$sinceVersion' |
244 | - but has union return typehint '" . implode('|', $stubMethod->returnTypesFromSignature) . "' that supported only since PHP 8.0. |
|
242 | + but has union return typehint '".implode('|', $stubMethod->returnTypesFromSignature)."' that supported only since PHP 8.0. |
|
245 | 243 | Please declare return type via PhpDoc" |
246 | 244 | ); |
247 | 245 | } |
@@ -250,7 +248,7 @@ discard block |
||
250 | 248 | * @dataProvider \StubTests\TestData\Providers\Stubs\StubsParametersProvider::parametersForAllowedScalarTypeHintTestsProvider |
251 | 249 | * @throws RuntimeException |
252 | 250 | */ |
253 | - public function testMethodScalarTypeHintsInParametersMatchReflection(PHPClass|PHPInterface $class, PHPMethod $stubMethod, PHPParameter $stubParameter) |
|
251 | + public function testMethodScalarTypeHintsInParametersMatchReflection(PHPClass | PHPInterface $class, PHPMethod $stubMethod, PHPParameter $stubParameter) |
|
254 | 252 | { |
255 | 253 | $reflectionMethod = ReflectionStubsSingleton::getReflectionStubs()->getClass($class->name)->getMethod($stubMethod->name); |
256 | 254 | $reflectionParameters = array_filter($reflectionMethod->parameters, fn (PHPParameter $parameter) => $parameter->name === $stubParameter->name); |
@@ -262,7 +260,7 @@ discard block |
||
262 | 260 | * @dataProvider \StubTests\TestData\Providers\Stubs\StubsParametersProvider::parametersForAllowedNullableTypeHintTestsProvider |
263 | 261 | * @throws RuntimeException |
264 | 262 | */ |
265 | - public function testMethodNullableTypeHintsInParametersMatchReflection(PHPClass|PHPInterface $class, PHPMethod $stubMethod, PHPParameter $stubParameter) |
|
263 | + public function testMethodNullableTypeHintsInParametersMatchReflection(PHPClass | PHPInterface $class, PHPMethod $stubMethod, PHPParameter $stubParameter) |
|
266 | 264 | { |
267 | 265 | $reflectionMethod = ReflectionStubsSingleton::getReflectionStubs()->getClass($class->name)->getMethod($stubMethod->name); |
268 | 266 | $reflectionParameters = array_filter($reflectionMethod->parameters, fn (PHPParameter $parameter) => $parameter->name === $stubParameter->name); |
@@ -274,7 +272,7 @@ discard block |
||
274 | 272 | * @dataProvider \StubTests\TestData\Providers\Stubs\StubsParametersProvider::parametersForAllowedUnionTypeHintTestsProvider |
275 | 273 | * @throws RuntimeException |
276 | 274 | */ |
277 | - public function testMethodUnionTypeHintsInParametersMatchReflection(PHPClass|PHPInterface $class, PHPMethod $stubMethod, PHPParameter $stubParameter) |
|
275 | + public function testMethodUnionTypeHintsInParametersMatchReflection(PHPClass | PHPInterface $class, PHPMethod $stubMethod, PHPParameter $stubParameter) |
|
278 | 276 | { |
279 | 277 | $reflectionMethod = ReflectionStubsSingleton::getReflectionStubs()->getClass($class->name)->getMethod($stubMethod->name); |
280 | 278 | $reflectionParameters = array_filter($reflectionMethod->parameters, fn (PHPParameter $parameter) => $parameter->name === $stubParameter->name); |
@@ -286,10 +284,10 @@ discard block |
||
286 | 284 | * @dataProvider \StubTests\TestData\Providers\Stubs\StubMethodsProvider::allFunctionAndMethodsWithReturnTypeHintsProvider |
287 | 285 | * @throws Exception |
288 | 286 | */ |
289 | - public static function testSignatureTypeHintsComplainPhpDocInMethods(PHPFunction|PHPMethod $method) |
|
287 | + public static function testSignatureTypeHintsComplainPhpDocInMethods(PHPFunction | PHPMethod $method) |
|
290 | 288 | { |
291 | 289 | $functionName = $method->name; |
292 | - $unifiedPhpDocTypes = array_map(function (string $type) { |
|
290 | + $unifiedPhpDocTypes = array_map(function(string $type) { |
|
293 | 291 | $typeParts = explode('\\', $type); |
294 | 292 | $typeName = end($typeParts); |
295 | 293 | |
@@ -311,9 +309,9 @@ discard block |
||
311 | 309 | self::assertSameSize( |
312 | 310 | $unifiedSignatureTypes, |
313 | 311 | $typesIntersection, |
314 | - $method instanceof PHPMethod ? "Method $method->parentName::" : 'Function ' . |
|
312 | + $method instanceof PHPMethod ? "Method $method->parentName::" : 'Function '. |
|
315 | 313 | "$functionName has mismatch in phpdoc return type and signature return type\n |
316 | - signature has " . implode('|', $unifiedSignatureTypes) . "\n |
|
314 | + signature has ".implode('|', $unifiedSignatureTypes)."\n |
|
317 | 315 | but phpdoc has " . implode('|', $unifiedPhpDocTypes) |
318 | 316 | ); |
319 | 317 | } |
@@ -336,14 +334,13 @@ discard block |
||
336 | 334 | if (!$testCondition) { |
337 | 335 | if (!empty($unifiedStubsAttributesParameterTypes)) { |
338 | 336 | $typesFromAttribute = !empty($unifiedStubsAttributesParameterTypes[getenv('PHP_VERSION')]) ? |
339 | - $unifiedStubsAttributesParameterTypes[getenv('PHP_VERSION')] : |
|
340 | - $unifiedStubsAttributesParameterTypes['default']; |
|
337 | + $unifiedStubsAttributesParameterTypes[getenv('PHP_VERSION')] : $unifiedStubsAttributesParameterTypes['default']; |
|
341 | 338 | $testCondition = BaseStubsTest::isReflectionTypesExistInAttributes($unifiedReflectionParameterTypes, $typesFromAttribute); |
342 | 339 | } |
343 | 340 | } |
344 | 341 | self::assertTrue($testCondition, "Type mismatch $functionName: \$$parameter->name \n |
345 | - Reflection parameter $parameter->name with index $parameter->indexInSignature has type '" . implode('|', $unifiedReflectionParameterTypes) . |
|
346 | - "' but stub parameter $stubParameter->name with index $stubParameter->indexInSignature has type '" . implode('|', $unifiedStubsParameterTypes) . "' in signature and " . |
|
347 | - implode('|', $typesFromAttribute) . ' in attribute'); |
|
342 | + Reflection parameter $parameter->name with index $parameter->indexInSignature has type '".implode('|', $unifiedReflectionParameterTypes). |
|
343 | + "' but stub parameter $stubParameter->name with index $stubParameter->indexInSignature has type '".implode('|', $unifiedStubsParameterTypes)."' in signature and ". |
|
344 | + implode('|', $typesFromAttribute).' in attribute'); |
|
348 | 345 | } |
349 | 346 | } |
@@ -15,8 +15,7 @@ |
||
15 | 15 | use StubTests\TestData\Providers\PhpStormStubsSingleton; |
16 | 16 | use StubTests\TestData\Providers\ReflectionStubsSingleton; |
17 | 17 | |
18 | -class StubsTypeHintsTest extends BaseStubsTest |
|
19 | -{ |
|
18 | +class StubsTypeHintsTest extends BaseStubsTest { |
|
20 | 19 | /** |
21 | 20 | * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionFunctionsProvider::allFunctionsProvider |
22 | 21 | * @throws RuntimeException |
@@ -12,58 +12,58 @@ |
||
12 | 12 | |
13 | 13 | class BaseConstantsTest extends BaseStubsTest |
14 | 14 | { |
15 | - /** |
|
16 | - * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionConstantsProvider::constantProvider |
|
17 | - * @throws Exception |
|
18 | - */ |
|
19 | - public function testConstants(PHPConst $constant): void |
|
20 | - { |
|
21 | - $constantName = $constant->name; |
|
22 | - $constantValue = $constant->value; |
|
23 | - $stubConstant = PhpStormStubsSingleton::getPhpStormStubs()->getConstant($constantName); |
|
24 | - static::assertNotEmpty( |
|
25 | - $stubConstant, |
|
26 | - "Missing constant: const $constantName = $constantValue\n" |
|
27 | - ); |
|
28 | - } |
|
15 | + /** |
|
16 | + * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionConstantsProvider::constantProvider |
|
17 | + * @throws Exception |
|
18 | + */ |
|
19 | + public function testConstants(PHPConst $constant): void |
|
20 | + { |
|
21 | + $constantName = $constant->name; |
|
22 | + $constantValue = $constant->value; |
|
23 | + $stubConstant = PhpStormStubsSingleton::getPhpStormStubs()->getConstant($constantName); |
|
24 | + static::assertNotEmpty( |
|
25 | + $stubConstant, |
|
26 | + "Missing constant: const $constantName = $constantValue\n" |
|
27 | + ); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionConstantsProvider::classConstantProvider |
|
32 | - * @throws Exception|RuntimeException |
|
33 | - */ |
|
34 | - public function testClassConstants(PHPClass|PHPInterface $class, PHPConst $constant): void |
|
35 | - { |
|
36 | - $constantName = $constant->name; |
|
37 | - $constantValue = $constant->value; |
|
38 | - if ($class instanceof PHPClass) { |
|
39 | - $stubConstant = PhpStormStubsSingleton::getPhpStormStubs()->getClass($class->name)->getConstant($constantName); |
|
40 | - } else { |
|
41 | - $stubConstant = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($class->name)->getConstant($constantName); |
|
42 | - } |
|
43 | - static::assertNotEmpty( |
|
44 | - $stubConstant, |
|
45 | - "Missing constant: const $constantName = $constantValue\n" |
|
46 | - ); |
|
47 | - } |
|
30 | + /** |
|
31 | + * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionConstantsProvider::classConstantProvider |
|
32 | + * @throws Exception|RuntimeException |
|
33 | + */ |
|
34 | + public function testClassConstants(PHPClass|PHPInterface $class, PHPConst $constant): void |
|
35 | + { |
|
36 | + $constantName = $constant->name; |
|
37 | + $constantValue = $constant->value; |
|
38 | + if ($class instanceof PHPClass) { |
|
39 | + $stubConstant = PhpStormStubsSingleton::getPhpStormStubs()->getClass($class->name)->getConstant($constantName); |
|
40 | + } else { |
|
41 | + $stubConstant = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($class->name)->getConstant($constantName); |
|
42 | + } |
|
43 | + static::assertNotEmpty( |
|
44 | + $stubConstant, |
|
45 | + "Missing constant: const $constantName = $constantValue\n" |
|
46 | + ); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionConstantsProvider::classConstantProvider |
|
51 | - * @throws RuntimeException |
|
52 | - */ |
|
53 | - public function testClassConstantsVisibility(PHPClass|PHPInterface $class, PHPConst $constant): void |
|
54 | - { |
|
55 | - $constantName = $constant->name; |
|
56 | - $constantVisibility = $constant->visibility; |
|
57 | - if ($class instanceof PHPClass) { |
|
58 | - $stubConstant = PhpStormStubsSingleton::getPhpStormStubs()->getClass($class->name)->getConstant($constantName); |
|
59 | - } else { |
|
60 | - $stubConstant = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($class->name)->getConstant($constantName); |
|
61 | - } |
|
62 | - static::assertEquals( |
|
63 | - $constantVisibility, |
|
64 | - $stubConstant->visibility, |
|
65 | - "Constant visibility mismatch: const $constantName \n |
|
49 | + /** |
|
50 | + * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionConstantsProvider::classConstantProvider |
|
51 | + * @throws RuntimeException |
|
52 | + */ |
|
53 | + public function testClassConstantsVisibility(PHPClass|PHPInterface $class, PHPConst $constant): void |
|
54 | + { |
|
55 | + $constantName = $constant->name; |
|
56 | + $constantVisibility = $constant->visibility; |
|
57 | + if ($class instanceof PHPClass) { |
|
58 | + $stubConstant = PhpStormStubsSingleton::getPhpStormStubs()->getClass($class->name)->getConstant($constantName); |
|
59 | + } else { |
|
60 | + $stubConstant = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($class->name)->getConstant($constantName); |
|
61 | + } |
|
62 | + static::assertEquals( |
|
63 | + $constantVisibility, |
|
64 | + $stubConstant->visibility, |
|
65 | + "Constant visibility mismatch: const $constantName \n |
|
66 | 66 | Expected visibility: $constantVisibility but was $stubConstant->visibility" |
67 | - ); |
|
68 | - } |
|
67 | + ); |
|
68 | + } |
|
69 | 69 | } |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionConstantsProvider::classConstantProvider |
32 | 32 | * @throws Exception|RuntimeException |
33 | 33 | */ |
34 | - public function testClassConstants(PHPClass|PHPInterface $class, PHPConst $constant): void |
|
34 | + public function testClassConstants(PHPClass | PHPInterface $class, PHPConst $constant): void |
|
35 | 35 | { |
36 | 36 | $constantName = $constant->name; |
37 | 37 | $constantValue = $constant->value; |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionConstantsProvider::classConstantProvider |
51 | 51 | * @throws RuntimeException |
52 | 52 | */ |
53 | - public function testClassConstantsVisibility(PHPClass|PHPInterface $class, PHPConst $constant): void |
|
53 | + public function testClassConstantsVisibility(PHPClass | PHPInterface $class, PHPConst $constant): void |
|
54 | 54 | { |
55 | 55 | $constantName = $constant->name; |
56 | 56 | $constantVisibility = $constant->visibility; |
@@ -10,8 +10,7 @@ |
||
10 | 10 | use StubTests\Model\PHPInterface; |
11 | 11 | use StubTests\TestData\Providers\PhpStormStubsSingleton; |
12 | 12 | |
13 | -class BaseConstantsTest extends BaseStubsTest |
|
14 | -{ |
|
13 | +class BaseConstantsTest extends BaseStubsTest { |
|
15 | 14 | /** |
16 | 15 | * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionConstantsProvider::constantProvider |
17 | 16 | * @throws Exception |
@@ -11,23 +11,23 @@ |
||
11 | 11 | $peclAndCoreStubs = unserialize(file_get_contents(__DIR__ . '/../../ReflectionDataPecl.json'), ['allowed_classes' => true]); |
12 | 12 | $onlyPeclStubs = new StubsContainer(); |
13 | 13 | foreach ($peclAndCoreStubs->getConstants() as $peclConstant) { |
14 | - if (empty(array_filter($coreStubs->getConstants(), fn ($constant) => $constant->name === $peclConstant->name))) { |
|
15 | - $onlyPeclStubs->addConstant($peclConstant); |
|
16 | - } |
|
14 | + if (empty(array_filter($coreStubs->getConstants(), fn ($constant) => $constant->name === $peclConstant->name))) { |
|
15 | + $onlyPeclStubs->addConstant($peclConstant); |
|
16 | + } |
|
17 | 17 | } |
18 | 18 | foreach ($peclAndCoreStubs->getClasses() as $peclClass) { |
19 | - if (empty(array_filter($coreStubs->getClasses(), fn ($class) => $class->name === $peclClass->name))) { |
|
20 | - $onlyPeclStubs->addClass($peclClass); |
|
21 | - } |
|
19 | + if (empty(array_filter($coreStubs->getClasses(), fn ($class) => $class->name === $peclClass->name))) { |
|
20 | + $onlyPeclStubs->addClass($peclClass); |
|
21 | + } |
|
22 | 22 | } |
23 | 23 | foreach ($peclAndCoreStubs->getFunctions() as $peclFunction) { |
24 | - if (empty(array_filter($coreStubs->getFunctions(), fn ($function) => $function->name === $peclFunction->name))) { |
|
25 | - $onlyPeclStubs->addFunction($peclFunction); |
|
26 | - } |
|
24 | + if (empty(array_filter($coreStubs->getFunctions(), fn ($function) => $function->name === $peclFunction->name))) { |
|
25 | + $onlyPeclStubs->addFunction($peclFunction); |
|
26 | + } |
|
27 | 27 | } |
28 | 28 | foreach ($peclAndCoreStubs->getInterfaces() as $peclInterface) { |
29 | - if (empty(array_filter($coreStubs->getInterfaces(), fn ($interface) => $interface->name === $peclInterface->name))) { |
|
30 | - $onlyPeclStubs->addInterface($peclInterface); |
|
31 | - } |
|
29 | + if (empty(array_filter($coreStubs->getInterfaces(), fn ($interface) => $interface->name === $peclInterface->name))) { |
|
30 | + $onlyPeclStubs->addInterface($peclInterface); |
|
31 | + } |
|
32 | 32 | } |
33 | 33 | file_put_contents(__DIR__ . '/../../ReflectionData.json', serialize($onlyPeclStubs)); |
@@ -3,12 +3,12 @@ discard block |
||
3 | 3 | |
4 | 4 | use StubTests\Model\StubsContainer; |
5 | 5 | |
6 | -require_once __DIR__ . '/../../vendor/autoload.php'; |
|
6 | +require_once __DIR__.'/../../vendor/autoload.php'; |
|
7 | 7 | |
8 | 8 | /** @var StubsContainer $coreStubs */ |
9 | -$coreStubs = unserialize(file_get_contents(__DIR__ . '/../../ReflectionData.json'), ['allowed_classes' => true]); |
|
9 | +$coreStubs = unserialize(file_get_contents(__DIR__.'/../../ReflectionData.json'), ['allowed_classes' => true]); |
|
10 | 10 | /** @var StubsContainer $peclAndCoreStubs */ |
11 | -$peclAndCoreStubs = unserialize(file_get_contents(__DIR__ . '/../../ReflectionDataPecl.json'), ['allowed_classes' => true]); |
|
11 | +$peclAndCoreStubs = unserialize(file_get_contents(__DIR__.'/../../ReflectionDataPecl.json'), ['allowed_classes' => true]); |
|
12 | 12 | $onlyPeclStubs = new StubsContainer(); |
13 | 13 | foreach ($peclAndCoreStubs->getConstants() as $peclConstant) { |
14 | 14 | if (empty(array_filter($coreStubs->getConstants(), fn ($constant) => $constant->name === $peclConstant->name))) { |
@@ -30,4 +30,4 @@ discard block |
||
30 | 30 | $onlyPeclStubs->addInterface($peclInterface); |
31 | 31 | } |
32 | 32 | } |
33 | -file_put_contents(__DIR__ . '/../../ReflectionData.json', serialize($onlyPeclStubs)); |
|
33 | +file_put_contents(__DIR__.'/../../ReflectionData.json', serialize($onlyPeclStubs)); |
@@ -3,9 +3,9 @@ |
||
3 | 3 | |
4 | 4 | namespace StubTests\TestData; |
5 | 5 | |
6 | -require_once __DIR__ . '/../../vendor/autoload.php'; |
|
6 | +require_once __DIR__.'/../../vendor/autoload.php'; |
|
7 | 7 | |
8 | 8 | use StubTests\TestData\Providers\ReflectionStubsSingleton; |
9 | 9 | |
10 | 10 | $reflectionFileName = $argv[1]; |
11 | -file_put_contents(__DIR__ . "/../../$reflectionFileName", serialize(ReflectionStubsSingleton::getReflectionStubs())); |
|
11 | +file_put_contents(__DIR__."/../../$reflectionFileName", serialize(ReflectionStubsSingleton::getReflectionStubs())); |
@@ -15,74 +15,74 @@ |
||
15 | 15 | |
16 | 16 | class StubsConstantsAndParametersValuesTest extends BaseStubsTest |
17 | 17 | { |
18 | - /** |
|
19 | - * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionConstantsProvider::constantValuesProvider |
|
20 | - */ |
|
21 | - public function testConstantsValues(PHPConst $constant): void |
|
22 | - { |
|
23 | - $constantName = $constant->name; |
|
24 | - $constantValue = $constant->value; |
|
25 | - $stubConstant = PhpStormStubsSingleton::getPhpStormStubs()->getConstant($constantName); |
|
26 | - self::assertEquals( |
|
27 | - $constantValue, |
|
28 | - $stubConstant->value, |
|
29 | - "Constant value mismatch: const $constantName \n |
|
18 | + /** |
|
19 | + * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionConstantsProvider::constantValuesProvider |
|
20 | + */ |
|
21 | + public function testConstantsValues(PHPConst $constant): void |
|
22 | + { |
|
23 | + $constantName = $constant->name; |
|
24 | + $constantValue = $constant->value; |
|
25 | + $stubConstant = PhpStormStubsSingleton::getPhpStormStubs()->getConstant($constantName); |
|
26 | + self::assertEquals( |
|
27 | + $constantValue, |
|
28 | + $stubConstant->value, |
|
29 | + "Constant value mismatch: const $constantName \n |
|
30 | 30 | Expected value: $constantValue but was $stubConstant->value" |
31 | - ); |
|
32 | - } |
|
31 | + ); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionParametersProvider::functionOptionalParametersWithDefaultValueProvider |
|
36 | - * @throws Exception|RuntimeException |
|
37 | - */ |
|
38 | - public function testFunctionsDefaultParametersValue(PHPFunction $function, PHPParameter $parameter) |
|
39 | - { |
|
40 | - $phpstormFunction = PhpStormStubsSingleton::getPhpStormStubs()->getFunction($function->name); |
|
41 | - $stubParameters = array_filter($phpstormFunction->parameters, fn (PHPParameter $stubParameter) => $stubParameter->indexInSignature === $parameter->indexInSignature); |
|
42 | - /** @var PHPParameter $stubOptionalParameter */ |
|
43 | - $stubOptionalParameter = array_pop($stubParameters); |
|
44 | - $reflectionValue = BaseStubsTest::getStringRepresentationOfDefaultParameterValue($parameter->defaultValue); |
|
45 | - $stubValue = BaseStubsTest::getStringRepresentationOfDefaultParameterValue($stubOptionalParameter->defaultValue); |
|
46 | - self::assertEquals( |
|
47 | - $reflectionValue, |
|
48 | - $stubValue, |
|
49 | - sprintf( |
|
50 | - 'Reflection function %s has optional parameter %s with default value %s but stub parameter has value %s', |
|
51 | - $function->name, |
|
52 | - $parameter->name, |
|
53 | - $reflectionValue, |
|
54 | - $stubValue |
|
55 | - ) |
|
56 | - ); |
|
57 | - } |
|
34 | + /** |
|
35 | + * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionParametersProvider::functionOptionalParametersWithDefaultValueProvider |
|
36 | + * @throws Exception|RuntimeException |
|
37 | + */ |
|
38 | + public function testFunctionsDefaultParametersValue(PHPFunction $function, PHPParameter $parameter) |
|
39 | + { |
|
40 | + $phpstormFunction = PhpStormStubsSingleton::getPhpStormStubs()->getFunction($function->name); |
|
41 | + $stubParameters = array_filter($phpstormFunction->parameters, fn (PHPParameter $stubParameter) => $stubParameter->indexInSignature === $parameter->indexInSignature); |
|
42 | + /** @var PHPParameter $stubOptionalParameter */ |
|
43 | + $stubOptionalParameter = array_pop($stubParameters); |
|
44 | + $reflectionValue = BaseStubsTest::getStringRepresentationOfDefaultParameterValue($parameter->defaultValue); |
|
45 | + $stubValue = BaseStubsTest::getStringRepresentationOfDefaultParameterValue($stubOptionalParameter->defaultValue); |
|
46 | + self::assertEquals( |
|
47 | + $reflectionValue, |
|
48 | + $stubValue, |
|
49 | + sprintf( |
|
50 | + 'Reflection function %s has optional parameter %s with default value %s but stub parameter has value %s', |
|
51 | + $function->name, |
|
52 | + $parameter->name, |
|
53 | + $reflectionValue, |
|
54 | + $stubValue |
|
55 | + ) |
|
56 | + ); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionParametersProvider::methodOptionalParametersWithDefaultValueProvider |
|
61 | - * @throws Exception|RuntimeException |
|
62 | - */ |
|
63 | - public function testMethodsDefaultParametersValue(PHPClass|PHPInterface $class, PHPMethod $method, PHPParameter $parameter) |
|
64 | - { |
|
65 | - if ($class instanceof PHPClass) { |
|
66 | - $phpstormFunction = PhpStormStubsSingleton::getPhpStormStubs()->getClass($class->name)->getMethod($method->name); |
|
67 | - } else { |
|
68 | - $phpstormFunction = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($class->name)->getMethod($method->name); |
|
69 | - } |
|
70 | - $stubParameters = array_filter($phpstormFunction->parameters, fn (PHPParameter $stubParameter) => $stubParameter->indexInSignature === $parameter->indexInSignature); |
|
71 | - /** @var PHPParameter $stubOptionalParameter */ |
|
72 | - $stubOptionalParameter = array_pop($stubParameters); |
|
73 | - $reflectionValue = BaseStubsTest::getStringRepresentationOfDefaultParameterValue($parameter->defaultValue); |
|
74 | - $stubValue = BaseStubsTest::getStringRepresentationOfDefaultParameterValue($stubOptionalParameter->defaultValue, $class); |
|
75 | - self::assertEquals( |
|
76 | - $reflectionValue, |
|
77 | - $stubValue, |
|
78 | - sprintf( |
|
79 | - 'Reflection method %s::%s has optional parameter %s with default value %s but stub parameter has value %s', |
|
80 | - $class->name, |
|
81 | - $method->name, |
|
82 | - $parameter->name, |
|
83 | - $reflectionValue, |
|
84 | - $stubValue |
|
85 | - ) |
|
86 | - ); |
|
87 | - } |
|
59 | + /** |
|
60 | + * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionParametersProvider::methodOptionalParametersWithDefaultValueProvider |
|
61 | + * @throws Exception|RuntimeException |
|
62 | + */ |
|
63 | + public function testMethodsDefaultParametersValue(PHPClass|PHPInterface $class, PHPMethod $method, PHPParameter $parameter) |
|
64 | + { |
|
65 | + if ($class instanceof PHPClass) { |
|
66 | + $phpstormFunction = PhpStormStubsSingleton::getPhpStormStubs()->getClass($class->name)->getMethod($method->name); |
|
67 | + } else { |
|
68 | + $phpstormFunction = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($class->name)->getMethod($method->name); |
|
69 | + } |
|
70 | + $stubParameters = array_filter($phpstormFunction->parameters, fn (PHPParameter $stubParameter) => $stubParameter->indexInSignature === $parameter->indexInSignature); |
|
71 | + /** @var PHPParameter $stubOptionalParameter */ |
|
72 | + $stubOptionalParameter = array_pop($stubParameters); |
|
73 | + $reflectionValue = BaseStubsTest::getStringRepresentationOfDefaultParameterValue($parameter->defaultValue); |
|
74 | + $stubValue = BaseStubsTest::getStringRepresentationOfDefaultParameterValue($stubOptionalParameter->defaultValue, $class); |
|
75 | + self::assertEquals( |
|
76 | + $reflectionValue, |
|
77 | + $stubValue, |
|
78 | + sprintf( |
|
79 | + 'Reflection method %s::%s has optional parameter %s with default value %s but stub parameter has value %s', |
|
80 | + $class->name, |
|
81 | + $method->name, |
|
82 | + $parameter->name, |
|
83 | + $reflectionValue, |
|
84 | + $stubValue |
|
85 | + ) |
|
86 | + ); |
|
87 | + } |
|
88 | 88 | } |
@@ -60,7 +60,7 @@ |
||
60 | 60 | * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionParametersProvider::methodOptionalParametersWithDefaultValueProvider |
61 | 61 | * @throws Exception|RuntimeException |
62 | 62 | */ |
63 | - public function testMethodsDefaultParametersValue(PHPClass|PHPInterface $class, PHPMethod $method, PHPParameter $parameter) |
|
63 | + public function testMethodsDefaultParametersValue(PHPClass | PHPInterface $class, PHPMethod $method, PHPParameter $parameter) |
|
64 | 64 | { |
65 | 65 | if ($class instanceof PHPClass) { |
66 | 66 | $phpstormFunction = PhpStormStubsSingleton::getPhpStormStubs()->getClass($class->name)->getMethod($method->name); |
@@ -13,8 +13,7 @@ |
||
13 | 13 | use StubTests\Model\PHPParameter; |
14 | 14 | use StubTests\TestData\Providers\PhpStormStubsSingleton; |
15 | 15 | |
16 | -class StubsConstantsAndParametersValuesTest extends BaseStubsTest |
|
17 | -{ |
|
16 | +class StubsConstantsAndParametersValuesTest extends BaseStubsTest { |
|
18 | 17 | /** |
19 | 18 | * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionConstantsProvider::constantValuesProvider |
20 | 19 | */ |
@@ -15,75 +15,75 @@ |
||
15 | 15 | |
16 | 16 | class StubsMetaInternalTagTest extends BaseStubsTest |
17 | 17 | { |
18 | - /** |
|
19 | - * @var string[] |
|
20 | - */ |
|
21 | - private static array $overriddenFunctionsInMeta; |
|
18 | + /** |
|
19 | + * @var string[] |
|
20 | + */ |
|
21 | + private static array $overriddenFunctionsInMeta; |
|
22 | 22 | |
23 | - public static function setUpBeforeClass(): void |
|
24 | - { |
|
25 | - parent::setUpBeforeClass(); |
|
26 | - self::$overriddenFunctionsInMeta = (new MetaOverrideFunctionsParser())->overridenFunctions; |
|
27 | - } |
|
23 | + public static function setUpBeforeClass(): void |
|
24 | + { |
|
25 | + parent::setUpBeforeClass(); |
|
26 | + self::$overriddenFunctionsInMeta = (new MetaOverrideFunctionsParser())->overridenFunctions; |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * @throws Exception |
|
31 | - */ |
|
32 | - public function testFunctionInternalMetaTag(): void |
|
33 | - { |
|
34 | - $functions = PhpStormStubsSingleton::getPhpStormStubs()->getFunctions(); |
|
35 | - foreach ($functions as $function) { |
|
36 | - if ($function->hasInternalMetaTag) { |
|
37 | - $reflectionFunctions = array_filter( |
|
38 | - ReflectionStubsSingleton::getReflectionStubs()->getFunctions(), |
|
39 | - fn ($refFunction) => $refFunction->name === $function->name |
|
40 | - ); |
|
41 | - $reflectionFunction = array_pop($reflectionFunctions); |
|
42 | - if ($reflectionFunction !== null && !$reflectionFunction->hasMutedProblem(StubProblemType::ABSENT_IN_META)) { |
|
43 | - self::checkInternalMetaInOverride($function->name); |
|
44 | - } |
|
45 | - } |
|
46 | - } |
|
47 | - } |
|
29 | + /** |
|
30 | + * @throws Exception |
|
31 | + */ |
|
32 | + public function testFunctionInternalMetaTag(): void |
|
33 | + { |
|
34 | + $functions = PhpStormStubsSingleton::getPhpStormStubs()->getFunctions(); |
|
35 | + foreach ($functions as $function) { |
|
36 | + if ($function->hasInternalMetaTag) { |
|
37 | + $reflectionFunctions = array_filter( |
|
38 | + ReflectionStubsSingleton::getReflectionStubs()->getFunctions(), |
|
39 | + fn ($refFunction) => $refFunction->name === $function->name |
|
40 | + ); |
|
41 | + $reflectionFunction = array_pop($reflectionFunctions); |
|
42 | + if ($reflectionFunction !== null && !$reflectionFunction->hasMutedProblem(StubProblemType::ABSENT_IN_META)) { |
|
43 | + self::checkInternalMetaInOverride($function->name); |
|
44 | + } |
|
45 | + } |
|
46 | + } |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @throws RuntimeException |
|
51 | - */ |
|
52 | - public function testMethodsInternalMetaTag(): void |
|
53 | - { |
|
54 | - foreach (PhpStormStubsSingleton::getPhpStormStubs()->getClasses() as $className => $class) { |
|
55 | - foreach ($class->methods as $methodName => $method) { |
|
56 | - if ($method->hasInternalMetaTag) { |
|
57 | - $refClass = ReflectionStubsSingleton::getReflectionStubs()->getClass($className); |
|
58 | - if ($refClass !== null) { |
|
59 | - $reflectionMethods = array_filter( |
|
60 | - $refClass->methods, |
|
61 | - fn ($refMethod) => $refMethod->name === $methodName |
|
62 | - ); |
|
63 | - /** @var PHPMethod $reflectionMethod */ |
|
64 | - $reflectionMethod = array_pop($reflectionMethods); |
|
65 | - if ($reflectionMethod->hasMutedProblem(StubProblemType::ABSENT_IN_META)) { |
|
66 | - static::markTestSkipped('method intentionally not added to meta'); |
|
67 | - } else { |
|
68 | - self::checkInternalMetaInOverride($className . '::' . $methodName); |
|
69 | - } |
|
70 | - } |
|
71 | - } else { |
|
72 | - $this->expectNotToPerformAssertions(); |
|
73 | - } |
|
74 | - } |
|
75 | - } |
|
76 | - } |
|
49 | + /** |
|
50 | + * @throws RuntimeException |
|
51 | + */ |
|
52 | + public function testMethodsInternalMetaTag(): void |
|
53 | + { |
|
54 | + foreach (PhpStormStubsSingleton::getPhpStormStubs()->getClasses() as $className => $class) { |
|
55 | + foreach ($class->methods as $methodName => $method) { |
|
56 | + if ($method->hasInternalMetaTag) { |
|
57 | + $refClass = ReflectionStubsSingleton::getReflectionStubs()->getClass($className); |
|
58 | + if ($refClass !== null) { |
|
59 | + $reflectionMethods = array_filter( |
|
60 | + $refClass->methods, |
|
61 | + fn ($refMethod) => $refMethod->name === $methodName |
|
62 | + ); |
|
63 | + /** @var PHPMethod $reflectionMethod */ |
|
64 | + $reflectionMethod = array_pop($reflectionMethods); |
|
65 | + if ($reflectionMethod->hasMutedProblem(StubProblemType::ABSENT_IN_META)) { |
|
66 | + static::markTestSkipped('method intentionally not added to meta'); |
|
67 | + } else { |
|
68 | + self::checkInternalMetaInOverride($className . '::' . $methodName); |
|
69 | + } |
|
70 | + } |
|
71 | + } else { |
|
72 | + $this->expectNotToPerformAssertions(); |
|
73 | + } |
|
74 | + } |
|
75 | + } |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @throws Exception |
|
80 | - */ |
|
81 | - private static function checkInternalMetaInOverride(string $elementName): void |
|
82 | - { |
|
83 | - self::assertContains( |
|
84 | - $elementName, |
|
85 | - self::$overriddenFunctionsInMeta, |
|
86 | - "$elementName contains @meta in phpdoc but isn't added to 'override()' functions in meta file" |
|
87 | - ); |
|
88 | - } |
|
78 | + /** |
|
79 | + * @throws Exception |
|
80 | + */ |
|
81 | + private static function checkInternalMetaInOverride(string $elementName): void |
|
82 | + { |
|
83 | + self::assertContains( |
|
84 | + $elementName, |
|
85 | + self::$overriddenFunctionsInMeta, |
|
86 | + "$elementName contains @meta in phpdoc but isn't added to 'override()' functions in meta file" |
|
87 | + ); |
|
88 | + } |
|
89 | 89 | } |
@@ -65,7 +65,7 @@ |
||
65 | 65 | if ($reflectionMethod->hasMutedProblem(StubProblemType::ABSENT_IN_META)) { |
66 | 66 | static::markTestSkipped('method intentionally not added to meta'); |
67 | 67 | } else { |
68 | - self::checkInternalMetaInOverride($className . '::' . $methodName); |
|
68 | + self::checkInternalMetaInOverride($className.'::'.$methodName); |
|
69 | 69 | } |
70 | 70 | } |
71 | 71 | } else { |
@@ -13,8 +13,7 @@ |
||
13 | 13 | use function array_filter; |
14 | 14 | use function array_pop; |
15 | 15 | |
16 | -class StubsMetaInternalTagTest extends BaseStubsTest |
|
17 | -{ |
|
16 | +class StubsMetaInternalTagTest extends BaseStubsTest { |
|
18 | 17 | /** |
19 | 18 | * @var string[] |
20 | 19 | */ |
@@ -14,259 +14,259 @@ |
||
14 | 14 | |
15 | 15 | class BaseClassesTest extends BaseStubsTest |
16 | 16 | { |
17 | - /** |
|
18 | - * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionClassesTestDataProviders::classWithParentProvider |
|
19 | - * @throws Exception|RuntimeException |
|
20 | - */ |
|
21 | - public function testClassesParent(PHPClass|PHPInterface $class) |
|
22 | - { |
|
23 | - $className = $class->name; |
|
24 | - if ($class instanceof PHPClass) { |
|
25 | - $stubClass = PhpStormStubsSingleton::getPhpStormStubs()->getClass($className); |
|
26 | - static::assertEquals( |
|
27 | - $class->parentClass, |
|
28 | - $stubClass->parentClass, |
|
29 | - empty($class->parentClass) ? "Class $className should not extend $stubClass->parentClass" : |
|
30 | - "Class $className should extend $class->parentClass" |
|
31 | - ); |
|
32 | - } else { |
|
33 | - $stubClass = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($className); |
|
34 | - foreach ($class->parentInterfaces as $parentInterface) { |
|
35 | - static::assertContains( |
|
36 | - $parentInterface, |
|
37 | - $stubClass->parentInterfaces, |
|
38 | - "Interface $className should extend $parentInterface" |
|
39 | - ); |
|
40 | - } |
|
41 | - } |
|
42 | - } |
|
17 | + /** |
|
18 | + * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionClassesTestDataProviders::classWithParentProvider |
|
19 | + * @throws Exception|RuntimeException |
|
20 | + */ |
|
21 | + public function testClassesParent(PHPClass|PHPInterface $class) |
|
22 | + { |
|
23 | + $className = $class->name; |
|
24 | + if ($class instanceof PHPClass) { |
|
25 | + $stubClass = PhpStormStubsSingleton::getPhpStormStubs()->getClass($className); |
|
26 | + static::assertEquals( |
|
27 | + $class->parentClass, |
|
28 | + $stubClass->parentClass, |
|
29 | + empty($class->parentClass) ? "Class $className should not extend $stubClass->parentClass" : |
|
30 | + "Class $className should extend $class->parentClass" |
|
31 | + ); |
|
32 | + } else { |
|
33 | + $stubClass = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($className); |
|
34 | + foreach ($class->parentInterfaces as $parentInterface) { |
|
35 | + static::assertContains( |
|
36 | + $parentInterface, |
|
37 | + $stubClass->parentInterfaces, |
|
38 | + "Interface $className should extend $parentInterface" |
|
39 | + ); |
|
40 | + } |
|
41 | + } |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionMethodsProvider::classMethodsProvider |
|
46 | - * @throws Exception|RuntimeException |
|
47 | - */ |
|
48 | - public function testClassesMethodsExist(PHPClass|PHPInterface $class, PHPMethod $method) |
|
49 | - { |
|
50 | - $className = $class->name; |
|
51 | - if ($class instanceof PHPClass) { |
|
52 | - $stubClass = PhpStormStubsSingleton::getPhpStormStubs()->getClass($className); |
|
53 | - } else { |
|
54 | - $stubClass = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($className); |
|
55 | - } |
|
56 | - static::assertNotEmpty($stubClass->getMethod($method->name), "Missing method $className::$method->name"); |
|
57 | - } |
|
44 | + /** |
|
45 | + * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionMethodsProvider::classMethodsProvider |
|
46 | + * @throws Exception|RuntimeException |
|
47 | + */ |
|
48 | + public function testClassesMethodsExist(PHPClass|PHPInterface $class, PHPMethod $method) |
|
49 | + { |
|
50 | + $className = $class->name; |
|
51 | + if ($class instanceof PHPClass) { |
|
52 | + $stubClass = PhpStormStubsSingleton::getPhpStormStubs()->getClass($className); |
|
53 | + } else { |
|
54 | + $stubClass = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($className); |
|
55 | + } |
|
56 | + static::assertNotEmpty($stubClass->getMethod($method->name), "Missing method $className::$method->name"); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionMethodsProvider::classFinalMethodsProvider |
|
61 | - * @throws RuntimeException |
|
62 | - */ |
|
63 | - public function testClassesFinalMethods(PHPClass|PHPInterface $class, PHPMethod $method) |
|
64 | - { |
|
65 | - $className = $class->name; |
|
66 | - if ($class instanceof PHPClass) { |
|
67 | - $stubMethod = PhpStormStubsSingleton::getPhpStormStubs()->getClass($className)->getMethod($method->name); |
|
68 | - } else { |
|
69 | - $stubMethod = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($className)->getMethod($method->name); |
|
70 | - } |
|
71 | - static::assertEquals( |
|
72 | - $method->isFinal, |
|
73 | - $stubMethod->isFinal, |
|
74 | - "Method $className::$method->name final modifier is incorrect" |
|
75 | - ); |
|
76 | - } |
|
59 | + /** |
|
60 | + * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionMethodsProvider::classFinalMethodsProvider |
|
61 | + * @throws RuntimeException |
|
62 | + */ |
|
63 | + public function testClassesFinalMethods(PHPClass|PHPInterface $class, PHPMethod $method) |
|
64 | + { |
|
65 | + $className = $class->name; |
|
66 | + if ($class instanceof PHPClass) { |
|
67 | + $stubMethod = PhpStormStubsSingleton::getPhpStormStubs()->getClass($className)->getMethod($method->name); |
|
68 | + } else { |
|
69 | + $stubMethod = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($className)->getMethod($method->name); |
|
70 | + } |
|
71 | + static::assertEquals( |
|
72 | + $method->isFinal, |
|
73 | + $stubMethod->isFinal, |
|
74 | + "Method $className::$method->name final modifier is incorrect" |
|
75 | + ); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionMethodsProvider::classStaticMethodsProvider |
|
80 | - * @throws RuntimeException |
|
81 | - */ |
|
82 | - public function testClassesStaticMethods(PHPClass|PHPInterface $class, PHPMethod $method) |
|
83 | - { |
|
84 | - $className = $class->name; |
|
85 | - if ($class instanceof PHPClass) { |
|
86 | - $stubMethod = PhpStormStubsSingleton::getPhpStormStubs()->getClass($className)->getMethod($method->name); |
|
87 | - } else { |
|
88 | - $stubMethod = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($className)->getMethod($method->name); |
|
89 | - } |
|
90 | - static::assertEquals( |
|
91 | - $method->isStatic, |
|
92 | - $stubMethod->isStatic, |
|
93 | - "Method $className::$method->name static modifier is incorrect" |
|
94 | - ); |
|
95 | - } |
|
78 | + /** |
|
79 | + * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionMethodsProvider::classStaticMethodsProvider |
|
80 | + * @throws RuntimeException |
|
81 | + */ |
|
82 | + public function testClassesStaticMethods(PHPClass|PHPInterface $class, PHPMethod $method) |
|
83 | + { |
|
84 | + $className = $class->name; |
|
85 | + if ($class instanceof PHPClass) { |
|
86 | + $stubMethod = PhpStormStubsSingleton::getPhpStormStubs()->getClass($className)->getMethod($method->name); |
|
87 | + } else { |
|
88 | + $stubMethod = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($className)->getMethod($method->name); |
|
89 | + } |
|
90 | + static::assertEquals( |
|
91 | + $method->isStatic, |
|
92 | + $stubMethod->isStatic, |
|
93 | + "Method $className::$method->name static modifier is incorrect" |
|
94 | + ); |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionMethodsProvider::classMethodsWithAccessProvider |
|
99 | - * @throws RuntimeException |
|
100 | - */ |
|
101 | - public function testClassesMethodsVisibility(PHPClass|PHPInterface $class, PHPMethod $method) |
|
102 | - { |
|
103 | - $className = $class->name; |
|
104 | - if ($class instanceof PHPClass) { |
|
105 | - $stubMethod = PhpStormStubsSingleton::getPhpStormStubs()->getClass($className)->getMethod($method->name); |
|
106 | - } else { |
|
107 | - $stubMethod = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($className)->getMethod($method->name); |
|
108 | - } |
|
109 | - static::assertEquals( |
|
110 | - $method->access, |
|
111 | - $stubMethod->access, |
|
112 | - "Method $className::$method->name access modifier is incorrect" |
|
113 | - ); |
|
114 | - } |
|
97 | + /** |
|
98 | + * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionMethodsProvider::classMethodsWithAccessProvider |
|
99 | + * @throws RuntimeException |
|
100 | + */ |
|
101 | + public function testClassesMethodsVisibility(PHPClass|PHPInterface $class, PHPMethod $method) |
|
102 | + { |
|
103 | + $className = $class->name; |
|
104 | + if ($class instanceof PHPClass) { |
|
105 | + $stubMethod = PhpStormStubsSingleton::getPhpStormStubs()->getClass($className)->getMethod($method->name); |
|
106 | + } else { |
|
107 | + $stubMethod = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($className)->getMethod($method->name); |
|
108 | + } |
|
109 | + static::assertEquals( |
|
110 | + $method->access, |
|
111 | + $stubMethod->access, |
|
112 | + "Method $className::$method->name access modifier is incorrect" |
|
113 | + ); |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionMethodsProvider::classMethodsWithParametersProvider |
|
118 | - * @throws Exception|RuntimeException |
|
119 | - */ |
|
120 | - public function testClassMethodsParametersCount(PHPClass|PHPInterface $class, PHPMethod $method) |
|
121 | - { |
|
122 | - $className = $class->name; |
|
123 | - if ($class instanceof PHPClass) { |
|
124 | - $stubMethod = PhpStormStubsSingleton::getPhpStormStubs()->getClass($className)->getMethod($method->name); |
|
125 | - } else { |
|
126 | - $stubMethod = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($className)->getMethod($method->name); |
|
127 | - } |
|
128 | - $filteredStubParameters = array_filter( |
|
129 | - $stubMethod->parameters, |
|
130 | - function ($parameter) { |
|
131 | - if (!empty($parameter->availableVersionsRangeFromAttribute)) { |
|
132 | - return $parameter->availableVersionsRangeFromAttribute['from'] <= (doubleval(getenv('PHP_VERSION') ?? PhpVersions::getFirst())) |
|
133 | - && $parameter->availableVersionsRangeFromAttribute['to'] >= (doubleval(getenv('PHP_VERSION')) ?? PhpVersions::getLatest()); |
|
134 | - } else { |
|
135 | - return true; |
|
136 | - } |
|
137 | - } |
|
138 | - ); |
|
139 | - static::assertSameSize( |
|
140 | - $method->parameters, |
|
141 | - $filteredStubParameters, |
|
142 | - "Parameter number mismatch for method $className::$method->name. |
|
116 | + /** |
|
117 | + * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionMethodsProvider::classMethodsWithParametersProvider |
|
118 | + * @throws Exception|RuntimeException |
|
119 | + */ |
|
120 | + public function testClassMethodsParametersCount(PHPClass|PHPInterface $class, PHPMethod $method) |
|
121 | + { |
|
122 | + $className = $class->name; |
|
123 | + if ($class instanceof PHPClass) { |
|
124 | + $stubMethod = PhpStormStubsSingleton::getPhpStormStubs()->getClass($className)->getMethod($method->name); |
|
125 | + } else { |
|
126 | + $stubMethod = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($className)->getMethod($method->name); |
|
127 | + } |
|
128 | + $filteredStubParameters = array_filter( |
|
129 | + $stubMethod->parameters, |
|
130 | + function ($parameter) { |
|
131 | + if (!empty($parameter->availableVersionsRangeFromAttribute)) { |
|
132 | + return $parameter->availableVersionsRangeFromAttribute['from'] <= (doubleval(getenv('PHP_VERSION') ?? PhpVersions::getFirst())) |
|
133 | + && $parameter->availableVersionsRangeFromAttribute['to'] >= (doubleval(getenv('PHP_VERSION')) ?? PhpVersions::getLatest()); |
|
134 | + } else { |
|
135 | + return true; |
|
136 | + } |
|
137 | + } |
|
138 | + ); |
|
139 | + static::assertSameSize( |
|
140 | + $method->parameters, |
|
141 | + $filteredStubParameters, |
|
142 | + "Parameter number mismatch for method $className::$method->name. |
|
143 | 143 | Expected: " . self::getParameterRepresentation($method) |
144 | - ); |
|
145 | - } |
|
144 | + ); |
|
145 | + } |
|
146 | 146 | |
147 | - /** |
|
148 | - * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionClassesTestDataProviders::classesWithInterfacesProvider |
|
149 | - * @throws Exception|RuntimeException |
|
150 | - */ |
|
151 | - public function testClassInterfaces(PHPClass $class) |
|
152 | - { |
|
153 | - $className = $class->name; |
|
154 | - $stubClass = PhpStormStubsSingleton::getPhpStormStubs()->getClass($class->name, shouldSuitCurrentPhpVersion: false); |
|
155 | - foreach ($class->interfaces as $interface) { |
|
156 | - static::assertContains( |
|
157 | - $interface, |
|
158 | - $stubClass->interfaces, |
|
159 | - "Class $className doesn't implement interface $interface" |
|
160 | - ); |
|
161 | - } |
|
162 | - } |
|
147 | + /** |
|
148 | + * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionClassesTestDataProviders::classesWithInterfacesProvider |
|
149 | + * @throws Exception|RuntimeException |
|
150 | + */ |
|
151 | + public function testClassInterfaces(PHPClass $class) |
|
152 | + { |
|
153 | + $className = $class->name; |
|
154 | + $stubClass = PhpStormStubsSingleton::getPhpStormStubs()->getClass($class->name, shouldSuitCurrentPhpVersion: false); |
|
155 | + foreach ($class->interfaces as $interface) { |
|
156 | + static::assertContains( |
|
157 | + $interface, |
|
158 | + $stubClass->interfaces, |
|
159 | + "Class $className doesn't implement interface $interface" |
|
160 | + ); |
|
161 | + } |
|
162 | + } |
|
163 | 163 | |
164 | - /** |
|
165 | - * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionPropertiesProvider::classPropertiesProvider |
|
166 | - * @throws Exception|RuntimeException |
|
167 | - */ |
|
168 | - public function testClassProperties(PHPClass $class, PHPProperty $property) |
|
169 | - { |
|
170 | - $className = $class->name; |
|
171 | - $stubClass = PhpStormStubsSingleton::getPhpStormStubs()->getClass($class->name); |
|
172 | - static::assertNotEmpty($stubClass->getProperty($property->name), "Missing property $property->access " |
|
173 | - . implode('|', $property->typesFromSignature) . |
|
174 | - "$className::$$property->name"); |
|
175 | - } |
|
164 | + /** |
|
165 | + * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionPropertiesProvider::classPropertiesProvider |
|
166 | + * @throws Exception|RuntimeException |
|
167 | + */ |
|
168 | + public function testClassProperties(PHPClass $class, PHPProperty $property) |
|
169 | + { |
|
170 | + $className = $class->name; |
|
171 | + $stubClass = PhpStormStubsSingleton::getPhpStormStubs()->getClass($class->name); |
|
172 | + static::assertNotEmpty($stubClass->getProperty($property->name), "Missing property $property->access " |
|
173 | + . implode('|', $property->typesFromSignature) . |
|
174 | + "$className::$$property->name"); |
|
175 | + } |
|
176 | 176 | |
177 | - /** |
|
178 | - * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionPropertiesProvider::classStaticPropertiesProvider |
|
179 | - * @throws RuntimeException |
|
180 | - */ |
|
181 | - public function testClassStaticProperties(PHPClass $class, PHPProperty $property) |
|
182 | - { |
|
183 | - $className = $class->name; |
|
184 | - $stubProperty = PhpStormStubsSingleton::getPhpStormStubs()->getClass($class->name)->getProperty($property->name); |
|
185 | - static::assertEquals( |
|
186 | - $property->is_static, |
|
187 | - $stubProperty->is_static, |
|
188 | - "Property $className::$property->name static modifier is incorrect" |
|
189 | - ); |
|
190 | - } |
|
177 | + /** |
|
178 | + * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionPropertiesProvider::classStaticPropertiesProvider |
|
179 | + * @throws RuntimeException |
|
180 | + */ |
|
181 | + public function testClassStaticProperties(PHPClass $class, PHPProperty $property) |
|
182 | + { |
|
183 | + $className = $class->name; |
|
184 | + $stubProperty = PhpStormStubsSingleton::getPhpStormStubs()->getClass($class->name)->getProperty($property->name); |
|
185 | + static::assertEquals( |
|
186 | + $property->is_static, |
|
187 | + $stubProperty->is_static, |
|
188 | + "Property $className::$property->name static modifier is incorrect" |
|
189 | + ); |
|
190 | + } |
|
191 | 191 | |
192 | - /** |
|
193 | - * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionPropertiesProvider::classPropertiesWithAccessProvider |
|
194 | - * @throws RuntimeException |
|
195 | - */ |
|
196 | - public function testClassPropertiesVisibility(PHPClass $class, PHPProperty $property) |
|
197 | - { |
|
198 | - $className = $class->name; |
|
199 | - $stubProperty = PhpStormStubsSingleton::getPhpStormStubs()->getClass($class->name)->getProperty($property->name); |
|
200 | - static::assertEquals( |
|
201 | - $property->access, |
|
202 | - $stubProperty->access, |
|
203 | - "Property $className::$property->name access modifier is incorrect" |
|
204 | - ); |
|
205 | - } |
|
192 | + /** |
|
193 | + * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionPropertiesProvider::classPropertiesWithAccessProvider |
|
194 | + * @throws RuntimeException |
|
195 | + */ |
|
196 | + public function testClassPropertiesVisibility(PHPClass $class, PHPProperty $property) |
|
197 | + { |
|
198 | + $className = $class->name; |
|
199 | + $stubProperty = PhpStormStubsSingleton::getPhpStormStubs()->getClass($class->name)->getProperty($property->name); |
|
200 | + static::assertEquals( |
|
201 | + $property->access, |
|
202 | + $stubProperty->access, |
|
203 | + "Property $className::$property->name access modifier is incorrect" |
|
204 | + ); |
|
205 | + } |
|
206 | 206 | |
207 | - /** |
|
208 | - * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionPropertiesProvider::classPropertiesWithTypeProvider |
|
209 | - * @throws RuntimeException |
|
210 | - */ |
|
211 | - public function testClassPropertiesType(PHPClass $class, PHPProperty $property) |
|
212 | - { |
|
213 | - $className = $class->name; |
|
214 | - $stubProperty = PhpStormStubsSingleton::getPhpStormStubs()->getClass($class->name)->getProperty($property->name); |
|
215 | - $propertyName = $stubProperty->name; |
|
216 | - $unifiedStubsPropertyTypes = []; |
|
217 | - $unifiedStubsAttributesPropertyTypes = []; |
|
218 | - $unifiedReflectionPropertyTypes = []; |
|
219 | - self::convertNullableTypesToUnion($property->typesFromSignature, $unifiedReflectionPropertyTypes); |
|
220 | - if (!empty($stubProperty->typesFromSignature)) { |
|
221 | - self::convertNullableTypesToUnion($stubProperty->typesFromSignature, $unifiedStubsPropertyTypes); |
|
222 | - } |
|
223 | - foreach ($stubProperty->typesFromAttribute as $languageVersion => $listOfTypes) { |
|
224 | - $unifiedStubsAttributesPropertyTypes[$languageVersion] = []; |
|
225 | - self::convertNullableTypesToUnion($listOfTypes, $unifiedStubsAttributesPropertyTypes[$languageVersion]); |
|
226 | - } |
|
227 | - $typesFromAttribute = []; |
|
228 | - $testCondition = self::isReflectionTypesMatchSignature($unifiedReflectionPropertyTypes, $unifiedStubsPropertyTypes); |
|
229 | - if (!$testCondition) { |
|
230 | - if (!empty($unifiedStubsAttributesPropertyTypes)) { |
|
231 | - $typesFromAttribute = !empty($unifiedStubsAttributesPropertyTypes[getenv('PHP_VERSION')]) ? |
|
232 | - $unifiedStubsAttributesPropertyTypes[getenv('PHP_VERSION')] : |
|
233 | - $unifiedStubsAttributesPropertyTypes['default']; |
|
234 | - $testCondition = self::isReflectionTypesExistInAttributes($unifiedReflectionPropertyTypes, $typesFromAttribute); |
|
235 | - } |
|
236 | - } |
|
237 | - self::assertTrue($testCondition, "Property $className::$propertyName has invalid typehint. |
|
207 | + /** |
|
208 | + * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionPropertiesProvider::classPropertiesWithTypeProvider |
|
209 | + * @throws RuntimeException |
|
210 | + */ |
|
211 | + public function testClassPropertiesType(PHPClass $class, PHPProperty $property) |
|
212 | + { |
|
213 | + $className = $class->name; |
|
214 | + $stubProperty = PhpStormStubsSingleton::getPhpStormStubs()->getClass($class->name)->getProperty($property->name); |
|
215 | + $propertyName = $stubProperty->name; |
|
216 | + $unifiedStubsPropertyTypes = []; |
|
217 | + $unifiedStubsAttributesPropertyTypes = []; |
|
218 | + $unifiedReflectionPropertyTypes = []; |
|
219 | + self::convertNullableTypesToUnion($property->typesFromSignature, $unifiedReflectionPropertyTypes); |
|
220 | + if (!empty($stubProperty->typesFromSignature)) { |
|
221 | + self::convertNullableTypesToUnion($stubProperty->typesFromSignature, $unifiedStubsPropertyTypes); |
|
222 | + } |
|
223 | + foreach ($stubProperty->typesFromAttribute as $languageVersion => $listOfTypes) { |
|
224 | + $unifiedStubsAttributesPropertyTypes[$languageVersion] = []; |
|
225 | + self::convertNullableTypesToUnion($listOfTypes, $unifiedStubsAttributesPropertyTypes[$languageVersion]); |
|
226 | + } |
|
227 | + $typesFromAttribute = []; |
|
228 | + $testCondition = self::isReflectionTypesMatchSignature($unifiedReflectionPropertyTypes, $unifiedStubsPropertyTypes); |
|
229 | + if (!$testCondition) { |
|
230 | + if (!empty($unifiedStubsAttributesPropertyTypes)) { |
|
231 | + $typesFromAttribute = !empty($unifiedStubsAttributesPropertyTypes[getenv('PHP_VERSION')]) ? |
|
232 | + $unifiedStubsAttributesPropertyTypes[getenv('PHP_VERSION')] : |
|
233 | + $unifiedStubsAttributesPropertyTypes['default']; |
|
234 | + $testCondition = self::isReflectionTypesExistInAttributes($unifiedReflectionPropertyTypes, $typesFromAttribute); |
|
235 | + } |
|
236 | + } |
|
237 | + self::assertTrue($testCondition, "Property $className::$propertyName has invalid typehint. |
|
238 | 238 | Reflection property has type " . implode('|', $unifiedReflectionPropertyTypes) . ' but stubs has type ' . |
239 | - implode('|', $unifiedStubsPropertyTypes) . ' in signature and attribute has types ' . |
|
240 | - implode('|', $typesFromAttribute)); |
|
241 | - } |
|
239 | + implode('|', $unifiedStubsPropertyTypes) . ' in signature and attribute has types ' . |
|
240 | + implode('|', $typesFromAttribute)); |
|
241 | + } |
|
242 | 242 | |
243 | - /** |
|
244 | - * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionClassesTestDataProviders::allClassesProvider |
|
245 | - * @throws Exception |
|
246 | - */ |
|
247 | - public function testClassesExist(PHPClass|PHPInterface $class): void |
|
248 | - { |
|
249 | - $className = $class->name; |
|
250 | - if ($class instanceof PHPClass) { |
|
251 | - $stubClass = PhpStormStubsSingleton::getPhpStormStubs()->getClass($className); |
|
252 | - } else { |
|
253 | - $stubClass = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($className); |
|
254 | - } |
|
255 | - static::assertNotEmpty($stubClass, "Missing class $className: class $className {}"); |
|
256 | - } |
|
243 | + /** |
|
244 | + * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionClassesTestDataProviders::allClassesProvider |
|
245 | + * @throws Exception |
|
246 | + */ |
|
247 | + public function testClassesExist(PHPClass|PHPInterface $class): void |
|
248 | + { |
|
249 | + $className = $class->name; |
|
250 | + if ($class instanceof PHPClass) { |
|
251 | + $stubClass = PhpStormStubsSingleton::getPhpStormStubs()->getClass($className); |
|
252 | + } else { |
|
253 | + $stubClass = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($className); |
|
254 | + } |
|
255 | + static::assertNotEmpty($stubClass, "Missing class $className: class $className {}"); |
|
256 | + } |
|
257 | 257 | |
258 | - /** |
|
259 | - * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionClassesTestDataProviders::finalClassesProvider |
|
260 | - * @throws Exception|RuntimeException |
|
261 | - */ |
|
262 | - public function testClassesFinal(PHPClass|PHPInterface $class): void |
|
263 | - { |
|
264 | - $className = $class->name; |
|
265 | - if ($class instanceof PHPClass) { |
|
266 | - $stubClass = PhpStormStubsSingleton::getPhpStormStubs()->getClass($className); |
|
267 | - } else { |
|
268 | - $stubClass = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($className); |
|
269 | - } |
|
270 | - static::assertEquals($class->isFinal, $stubClass->isFinal, "Final modifier of class $className is incorrect"); |
|
271 | - } |
|
258 | + /** |
|
259 | + * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionClassesTestDataProviders::finalClassesProvider |
|
260 | + * @throws Exception|RuntimeException |
|
261 | + */ |
|
262 | + public function testClassesFinal(PHPClass|PHPInterface $class): void |
|
263 | + { |
|
264 | + $className = $class->name; |
|
265 | + if ($class instanceof PHPClass) { |
|
266 | + $stubClass = PhpStormStubsSingleton::getPhpStormStubs()->getClass($className); |
|
267 | + } else { |
|
268 | + $stubClass = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($className); |
|
269 | + } |
|
270 | + static::assertEquals($class->isFinal, $stubClass->isFinal, "Final modifier of class $className is incorrect"); |
|
271 | + } |
|
272 | 272 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionClassesTestDataProviders::classWithParentProvider |
19 | 19 | * @throws Exception|RuntimeException |
20 | 20 | */ |
21 | - public function testClassesParent(PHPClass|PHPInterface $class) |
|
21 | + public function testClassesParent(PHPClass | PHPInterface $class) |
|
22 | 22 | { |
23 | 23 | $className = $class->name; |
24 | 24 | if ($class instanceof PHPClass) { |
@@ -26,8 +26,7 @@ discard block |
||
26 | 26 | static::assertEquals( |
27 | 27 | $class->parentClass, |
28 | 28 | $stubClass->parentClass, |
29 | - empty($class->parentClass) ? "Class $className should not extend $stubClass->parentClass" : |
|
30 | - "Class $className should extend $class->parentClass" |
|
29 | + empty($class->parentClass) ? "Class $className should not extend $stubClass->parentClass" : "Class $className should extend $class->parentClass" |
|
31 | 30 | ); |
32 | 31 | } else { |
33 | 32 | $stubClass = PhpStormStubsSingleton::getPhpStormStubs()->getInterface($className); |
@@ -45,7 +44,7 @@ discard block |
||
45 | 44 | * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionMethodsProvider::classMethodsProvider |
46 | 45 | * @throws Exception|RuntimeException |
47 | 46 | */ |
48 | - public function testClassesMethodsExist(PHPClass|PHPInterface $class, PHPMethod $method) |
|
47 | + public function testClassesMethodsExist(PHPClass | PHPInterface $class, PHPMethod $method) |
|
49 | 48 | { |
50 | 49 | $className = $class->name; |
51 | 50 | if ($class instanceof PHPClass) { |
@@ -60,7 +59,7 @@ discard block |
||
60 | 59 | * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionMethodsProvider::classFinalMethodsProvider |
61 | 60 | * @throws RuntimeException |
62 | 61 | */ |
63 | - public function testClassesFinalMethods(PHPClass|PHPInterface $class, PHPMethod $method) |
|
62 | + public function testClassesFinalMethods(PHPClass | PHPInterface $class, PHPMethod $method) |
|
64 | 63 | { |
65 | 64 | $className = $class->name; |
66 | 65 | if ($class instanceof PHPClass) { |
@@ -79,7 +78,7 @@ discard block |
||
79 | 78 | * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionMethodsProvider::classStaticMethodsProvider |
80 | 79 | * @throws RuntimeException |
81 | 80 | */ |
82 | - public function testClassesStaticMethods(PHPClass|PHPInterface $class, PHPMethod $method) |
|
81 | + public function testClassesStaticMethods(PHPClass | PHPInterface $class, PHPMethod $method) |
|
83 | 82 | { |
84 | 83 | $className = $class->name; |
85 | 84 | if ($class instanceof PHPClass) { |
@@ -98,7 +97,7 @@ discard block |
||
98 | 97 | * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionMethodsProvider::classMethodsWithAccessProvider |
99 | 98 | * @throws RuntimeException |
100 | 99 | */ |
101 | - public function testClassesMethodsVisibility(PHPClass|PHPInterface $class, PHPMethod $method) |
|
100 | + public function testClassesMethodsVisibility(PHPClass | PHPInterface $class, PHPMethod $method) |
|
102 | 101 | { |
103 | 102 | $className = $class->name; |
104 | 103 | if ($class instanceof PHPClass) { |
@@ -117,7 +116,7 @@ discard block |
||
117 | 116 | * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionMethodsProvider::classMethodsWithParametersProvider |
118 | 117 | * @throws Exception|RuntimeException |
119 | 118 | */ |
120 | - public function testClassMethodsParametersCount(PHPClass|PHPInterface $class, PHPMethod $method) |
|
119 | + public function testClassMethodsParametersCount(PHPClass | PHPInterface $class, PHPMethod $method) |
|
121 | 120 | { |
122 | 121 | $className = $class->name; |
123 | 122 | if ($class instanceof PHPClass) { |
@@ -127,7 +126,7 @@ discard block |
||
127 | 126 | } |
128 | 127 | $filteredStubParameters = array_filter( |
129 | 128 | $stubMethod->parameters, |
130 | - function ($parameter) { |
|
129 | + function($parameter) { |
|
131 | 130 | if (!empty($parameter->availableVersionsRangeFromAttribute)) { |
132 | 131 | return $parameter->availableVersionsRangeFromAttribute['from'] <= (doubleval(getenv('PHP_VERSION') ?? PhpVersions::getFirst())) |
133 | 132 | && $parameter->availableVersionsRangeFromAttribute['to'] >= (doubleval(getenv('PHP_VERSION')) ?? PhpVersions::getLatest()); |
@@ -140,7 +139,7 @@ discard block |
||
140 | 139 | $method->parameters, |
141 | 140 | $filteredStubParameters, |
142 | 141 | "Parameter number mismatch for method $className::$method->name. |
143 | - Expected: " . self::getParameterRepresentation($method) |
|
142 | + Expected: ".self::getParameterRepresentation($method) |
|
144 | 143 | ); |
145 | 144 | } |
146 | 145 | |
@@ -170,7 +169,7 @@ discard block |
||
170 | 169 | $className = $class->name; |
171 | 170 | $stubClass = PhpStormStubsSingleton::getPhpStormStubs()->getClass($class->name); |
172 | 171 | static::assertNotEmpty($stubClass->getProperty($property->name), "Missing property $property->access " |
173 | - . implode('|', $property->typesFromSignature) . |
|
172 | + . implode('|', $property->typesFromSignature). |
|
174 | 173 | "$className::$$property->name"); |
175 | 174 | } |
176 | 175 | |
@@ -229,14 +228,13 @@ discard block |
||
229 | 228 | if (!$testCondition) { |
230 | 229 | if (!empty($unifiedStubsAttributesPropertyTypes)) { |
231 | 230 | $typesFromAttribute = !empty($unifiedStubsAttributesPropertyTypes[getenv('PHP_VERSION')]) ? |
232 | - $unifiedStubsAttributesPropertyTypes[getenv('PHP_VERSION')] : |
|
233 | - $unifiedStubsAttributesPropertyTypes['default']; |
|
231 | + $unifiedStubsAttributesPropertyTypes[getenv('PHP_VERSION')] : $unifiedStubsAttributesPropertyTypes['default']; |
|
234 | 232 | $testCondition = self::isReflectionTypesExistInAttributes($unifiedReflectionPropertyTypes, $typesFromAttribute); |
235 | 233 | } |
236 | 234 | } |
237 | 235 | self::assertTrue($testCondition, "Property $className::$propertyName has invalid typehint. |
238 | - Reflection property has type " . implode('|', $unifiedReflectionPropertyTypes) . ' but stubs has type ' . |
|
239 | - implode('|', $unifiedStubsPropertyTypes) . ' in signature and attribute has types ' . |
|
236 | + Reflection property has type ".implode('|', $unifiedReflectionPropertyTypes).' but stubs has type '. |
|
237 | + implode('|', $unifiedStubsPropertyTypes).' in signature and attribute has types '. |
|
240 | 238 | implode('|', $typesFromAttribute)); |
241 | 239 | } |
242 | 240 | |
@@ -244,7 +242,7 @@ discard block |
||
244 | 242 | * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionClassesTestDataProviders::allClassesProvider |
245 | 243 | * @throws Exception |
246 | 244 | */ |
247 | - public function testClassesExist(PHPClass|PHPInterface $class): void |
|
245 | + public function testClassesExist(PHPClass | PHPInterface $class): void |
|
248 | 246 | { |
249 | 247 | $className = $class->name; |
250 | 248 | if ($class instanceof PHPClass) { |
@@ -259,7 +257,7 @@ discard block |
||
259 | 257 | * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionClassesTestDataProviders::finalClassesProvider |
260 | 258 | * @throws Exception|RuntimeException |
261 | 259 | */ |
262 | - public function testClassesFinal(PHPClass|PHPInterface $class): void |
|
260 | + public function testClassesFinal(PHPClass | PHPInterface $class): void |
|
263 | 261 | { |
264 | 262 | $className = $class->name; |
265 | 263 | if ($class instanceof PHPClass) { |
@@ -12,8 +12,7 @@ |
||
12 | 12 | use StubTests\Model\PhpVersions; |
13 | 13 | use StubTests\TestData\Providers\PhpStormStubsSingleton; |
14 | 14 | |
15 | -class BaseClassesTest extends BaseStubsTest |
|
16 | -{ |
|
15 | +class BaseClassesTest extends BaseStubsTest { |
|
17 | 16 | /** |
18 | 17 | * @dataProvider \StubTests\TestData\Providers\Reflection\ReflectionClassesTestDataProviders::classWithParentProvider |
19 | 18 | * @throws Exception|RuntimeException |
@@ -14,74 +14,74 @@ |
||
14 | 14 | |
15 | 15 | final class BracesOneLineFixer implements FixerInterface |
16 | 16 | { |
17 | - public function isCandidate(Tokens $tokens): bool |
|
18 | - { |
|
19 | - return true; |
|
20 | - } |
|
17 | + public function isCandidate(Tokens $tokens): bool |
|
18 | + { |
|
19 | + return true; |
|
20 | + } |
|
21 | 21 | |
22 | - public function isRisky(): bool |
|
23 | - { |
|
24 | - return false; |
|
25 | - } |
|
22 | + public function isRisky(): bool |
|
23 | + { |
|
24 | + return false; |
|
25 | + } |
|
26 | 26 | |
27 | - public function fix(SplFileInfo $file, Tokens $tokens): void |
|
28 | - { |
|
29 | - /** |
|
30 | - * @var Token $token |
|
31 | - */ |
|
32 | - foreach ($tokens as $index => $token) { |
|
33 | - if (!$token->equals('{')) { |
|
34 | - continue; |
|
35 | - } |
|
36 | - $braceStartIndex = $index; |
|
37 | - $braceEndIndex = $tokens->getNextMeaningfulToken($index); |
|
27 | + public function fix(SplFileInfo $file, Tokens $tokens): void |
|
28 | + { |
|
29 | + /** |
|
30 | + * @var Token $token |
|
31 | + */ |
|
32 | + foreach ($tokens as $index => $token) { |
|
33 | + if (!$token->equals('{')) { |
|
34 | + continue; |
|
35 | + } |
|
36 | + $braceStartIndex = $index; |
|
37 | + $braceEndIndex = $tokens->getNextMeaningfulToken($index); |
|
38 | 38 | |
39 | - $token = $tokens[$braceEndIndex]; |
|
40 | - if ($token->equals('}')) { |
|
41 | - $beforeBraceIndex = $tokens->getPrevNonWhitespace($braceStartIndex); |
|
42 | - for ($i = $beforeBraceIndex + 1; $i <= $braceEndIndex; $i++) { |
|
43 | - $tokens->clearAt($i); |
|
44 | - } |
|
45 | - if ($braceEndIndex - $beforeBraceIndex > 2) { |
|
46 | - $tokens[$beforeBraceIndex + 1] = new Token(' '); |
|
47 | - } else { |
|
48 | - $tokens->insertAt($beforeBraceIndex + 1, new Token(' ')); |
|
49 | - } |
|
50 | - $tokens[$beforeBraceIndex + 2] = new Token('{'); |
|
51 | - $tokens[$beforeBraceIndex + 3] = new Token('}'); |
|
52 | - } |
|
53 | - } |
|
54 | - } |
|
39 | + $token = $tokens[$braceEndIndex]; |
|
40 | + if ($token->equals('}')) { |
|
41 | + $beforeBraceIndex = $tokens->getPrevNonWhitespace($braceStartIndex); |
|
42 | + for ($i = $beforeBraceIndex + 1; $i <= $braceEndIndex; $i++) { |
|
43 | + $tokens->clearAt($i); |
|
44 | + } |
|
45 | + if ($braceEndIndex - $beforeBraceIndex > 2) { |
|
46 | + $tokens[$beforeBraceIndex + 1] = new Token(' '); |
|
47 | + } else { |
|
48 | + $tokens->insertAt($beforeBraceIndex + 1, new Token(' ')); |
|
49 | + } |
|
50 | + $tokens[$beforeBraceIndex + 2] = new Token('{'); |
|
51 | + $tokens[$beforeBraceIndex + 3] = new Token('}'); |
|
52 | + } |
|
53 | + } |
|
54 | + } |
|
55 | 55 | |
56 | - public function getName(): string |
|
57 | - { |
|
58 | - return 'PhpStorm/braces_one_line'; |
|
59 | - } |
|
56 | + public function getName(): string |
|
57 | + { |
|
58 | + return 'PhpStorm/braces_one_line'; |
|
59 | + } |
|
60 | 60 | |
61 | - public function getPriority(): int |
|
62 | - { |
|
63 | - return 0; |
|
64 | - } |
|
61 | + public function getPriority(): int |
|
62 | + { |
|
63 | + return 0; |
|
64 | + } |
|
65 | 65 | |
66 | - public function supports(SplFileInfo $file): bool |
|
67 | - { |
|
68 | - return true; |
|
69 | - } |
|
66 | + public function supports(SplFileInfo $file): bool |
|
67 | + { |
|
68 | + return true; |
|
69 | + } |
|
70 | 70 | |
71 | - #[Pure] |
|
72 | - public function getDefinition(): FixerDefinitionInterface |
|
73 | - { |
|
74 | - return new FixerDefinition( |
|
75 | - "Braces of empty function's body should be placed on the same line", |
|
76 | - [ |
|
77 | - new CodeSample( |
|
78 | - <<<PHP |
|
71 | + #[Pure] |
|
72 | + public function getDefinition(): FixerDefinitionInterface |
|
73 | + { |
|
74 | + return new FixerDefinition( |
|
75 | + "Braces of empty function's body should be placed on the same line", |
|
76 | + [ |
|
77 | + new CodeSample( |
|
78 | + <<<PHP |
|
79 | 79 | <?php |
80 | 80 | declare(strict_types=1); |
81 | 81 | function foo() {} |
82 | 82 | PHP |
83 | - ), |
|
84 | - ] |
|
85 | - ); |
|
86 | - } |
|
83 | + ), |
|
84 | + ] |
|
85 | + ); |
|
86 | + } |
|
87 | 87 | } |
@@ -12,8 +12,7 @@ |
||
12 | 12 | use PhpCsFixer\Tokenizer\Tokens; |
13 | 13 | use SplFileInfo; |
14 | 14 | |
15 | -final class BracesOneLineFixer implements FixerInterface |
|
16 | -{ |
|
15 | +final class BracesOneLineFixer implements FixerInterface { |
|
17 | 16 | public function isCandidate(Tokens $tokens): bool |
18 | 17 | { |
19 | 18 | return true; |