Skip to content

Commit

Permalink
Indicate file on TypeInferenceTestCase validation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Jun 19, 2024
1 parent 1bce0b4 commit 81e5c42
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/Testing/TypeInferenceTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,22 @@ public static function gatherAssertTypes(string $file): array
$functionName = $nameNode->toString();
if (in_array(strtolower($functionName), ['asserttype', 'assertnativetype', 'assertvariablecertainty'], true)) {
self::fail(sprintf(
'Missing use statement for %s() on line %d.',
'Missing use statement for %s() in %s on line %d.',
$functionName,
$file,
$node->getStartLine(),
));
} elseif ($functionName === 'PHPStan\\Testing\\assertType') {
$expectedType = $scope->getType($node->getArgs()[0]->value);
if (!$expectedType instanceof ConstantScalarType) {
self::fail(sprintf('Expected type must be a literal string, %s given on line %d.', $expectedType->describe(VerbosityLevel::precise()), $node->getLine()));
self::fail(sprintf('Expected type must be a literal string, %s given in %s on line %d.', $expectedType->describe(VerbosityLevel::precise()), $file, $node->getLine()));
}
$actualType = $scope->getType($node->getArgs()[1]->value);
$assert = ['type', $file, $expectedType->getValue(), $actualType->describe(VerbosityLevel::precise()), $node->getStartLine()];
} elseif ($functionName === 'PHPStan\\Testing\\assertNativeType') {
$expectedType = $scope->getType($node->getArgs()[0]->value);
if (!$expectedType instanceof ConstantScalarType) {
self::fail(sprintf('Expected type must be a literal string, %s given on line %d.', $expectedType->describe(VerbosityLevel::precise()), $node->getLine()));
self::fail(sprintf('Expected type must be a literal string, %s given in %s on line %d.', $expectedType->describe(VerbosityLevel::precise()), $file, $node->getLine()));
}

$actualType = $scope->getNativeType($node->getArgs()[1]->value);
Expand Down Expand Up @@ -224,17 +225,19 @@ public static function gatherAssertTypes(string $file): array
}

self::fail(sprintf(
'Function %s imported with wrong namespace %s called on line %d.',
'Function %s imported with wrong namespace %s called in %s on line %d.',
$correctFunction,
$functionName,
$file,
$node->getStartLine(),
));
}

if (count($node->getArgs()) !== 2) {
self::fail(sprintf(
'ERROR: Wrong %s() call on line %d.',
'ERROR: Wrong %s() call in %s on line %d.',
$functionName,
$file,
$node->getStartLine(),
));
}
Expand Down

0 comments on commit 81e5c42

Please sign in to comment.