Skip to content

Commit

Permalink
Reduce memory consumption of TypeInferenceTestCase
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Sep 25, 2023
1 parent 3334735 commit e2662c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,11 @@ parameters:
count: 1
path: src/Testing/PHPStanTestCase.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\ConstantScalarType is error\\-prone and deprecated\\. Use Type\\:\\:isConstantScalarValue\\(\\) or Type\\:\\:getConstantScalarTypes\\(\\) or Type\\:\\:getConstantScalarValues\\(\\) instead\\.$#"
count: 2
path: src/Testing/TypeInferenceTestCase.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\IntersectionType is error\\-prone and deprecated\\.$#"
count: 1
Expand Down
19 changes: 12 additions & 7 deletions src/Testing/TypeInferenceTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,8 @@ public function assertFileAsserts(
): void
{
if ($assertType === 'type') {
$expectedType = $args[0];
$this->assertInstanceOf(ConstantScalarType::class, $expectedType);
$expected = $expectedType->getValue();
$actualType = $args[1];
$actual = $actualType->describe(VerbosityLevel::precise());
$expected = $args[0];
$actual = $args[1];
$this->assertSame(
$expected,
$actual,
Expand Down Expand Up @@ -138,12 +135,20 @@ public static function gatherAssertTypes(string $file): array
));
} elseif ($functionName === 'PHPStan\\Testing\\assertType') {
$expectedType = $scope->getType($node->getArgs()[0]->value);
if (!$expectedType instanceof ConstantScalarType) {
self::fail(sprintf('First argument of %s() must be a constant scalar type', $functionName));
}

$actualType = $scope->getType($node->getArgs()[1]->value);
$assert = ['type', $file, $expectedType, $actualType, $node->getLine()];
$assert = ['type', $file, $expectedType->getValue(), $actualType->describe(VerbosityLevel::precise()), $node->getLine()];
} elseif ($functionName === 'PHPStan\\Testing\\assertNativeType') {
$expectedType = $scope->getType($node->getArgs()[0]->value);
if (!$expectedType instanceof ConstantScalarType) {
self::fail(sprintf('First argument of %s() must be a constant scalar type', $functionName));
}

$actualType = $scope->getNativeType($node->getArgs()[1]->value);
$assert = ['type', $file, $expectedType, $actualType, $node->getLine()];
$assert = ['type', $file, $expectedType->getValue(), $actualType->describe(VerbosityLevel::precise()), $node->getLine()];
} elseif ($functionName === 'PHPStan\\Testing\\assertVariableCertainty') {
$certainty = $node->getArgs()[0]->value;
if (!$certainty instanceof StaticCall) {
Expand Down

0 comments on commit e2662c4

Please sign in to comment.