|
17 | 17 | use PHPStan\Php\PhpVersion;
|
18 | 18 | use PHPStan\PhpDoc\PhpDocInheritanceResolver;
|
19 | 19 | use PHPStan\PhpDoc\StubPhpDocProvider;
|
| 20 | +use PHPStan\PhpDoc\TypeStringResolver; |
20 | 21 | use PHPStan\Reflection\AttributeReflectionFactory;
|
21 | 22 | use PHPStan\Reflection\Deprecation\DeprecationProvider;
|
22 | 23 | use PHPStan\Reflection\InitializerExprTypeResolver;
|
@@ -203,12 +204,13 @@ public static function gatherAssertTypes(string $file): array
|
203 | 204 |
|
204 | 205 | $relativePathHelper = new SystemAgnosticSimpleRelativePathHelper($fileHelper);
|
205 | 206 | $reflectionProvider = self::getContainer()->getByType(ReflectionProvider::class);
|
| 207 | + $typeStringResolver = self::getContainer()->getByType(TypeStringResolver::class); |
206 | 208 |
|
207 | 209 | $file = $fileHelper->normalizePath($file);
|
208 | 210 |
|
209 | 211 | $asserts = [];
|
210 | 212 | $delayedErrors = [];
|
211 |
| - self::processFile($file, static function (Node $node, Scope $scope) use (&$asserts, &$delayedErrors, $file, $relativePathHelper, $reflectionProvider): void { |
| 213 | + self::processFile($file, static function (Node $node, Scope $scope) use (&$asserts, &$delayedErrors, $file, $relativePathHelper, $reflectionProvider, $typeStringResolver): void { |
212 | 214 | if ($node instanceof InClassNode) {
|
213 | 215 | if (!$reflectionProvider->hasClass($node->getClassReflection()->getName())) {
|
214 | 216 | $delayedErrors[] = sprintf(
|
@@ -270,16 +272,20 @@ public static function gatherAssertTypes(string $file): array
|
270 | 272 | $assert = ['type', $file, $expectedType->getValue(), $actualType->describe(VerbosityLevel::precise()), $node->getStartLine()];
|
271 | 273 | } elseif ($functionName === 'PHPStan\\Testing\\assertSuperType') {
|
272 | 274 | $expectedType = $scope->getType($node->getArgs()[0]->value);
|
273 |
| - if (!$expectedType instanceof ConstantScalarType) { |
| 275 | + $expectedTypeStrings = $expectedType->getConstantStrings(); |
| 276 | + if (count($expectedTypeStrings) !== 1) { |
274 | 277 | self::fail(sprintf(
|
275 | 278 | 'Expected super type must be a literal string, %s given in %s on line %d.',
|
276 | 279 | $expectedType->describe(VerbosityLevel::precise()),
|
277 | 280 | $relativePathHelper->getRelativePath($file),
|
278 | 281 | $node->getStartLine(),
|
279 | 282 | ));
|
280 | 283 | }
|
| 284 | + |
281 | 285 | $actualType = $scope->getType($node->getArgs()[1]->value);
|
282 |
| - $assert = ['superType', $file, $expectedType->getValue(), $actualType->describe(VerbosityLevel::precise()), $expectedType->isSuperTypeOf($actualType)->yes(), $node->getStartLine()]; |
| 286 | + $isCorrect = $typeStringResolver->resolve($expectedTypeStrings[0]->getValue())->isSuperTypeOf($actualType)->yes(); |
| 287 | + |
| 288 | + $assert = ['superType', $file, $expectedTypeStrings[0]->getValue(), $actualType->describe(VerbosityLevel::precise()), $isCorrect, $node->getStartLine()]; |
283 | 289 | } elseif ($functionName === 'PHPStan\\Testing\\assertVariableCertainty') {
|
284 | 290 | $certainty = $node->getArgs()[0]->value;
|
285 | 291 | if (!$certainty instanceof StaticCall) {
|
|
0 commit comments