Skip to content

Commit

Permalink
TypeInferenceTestCase - potential fix for performance problem with PH…
Browse files Browse the repository at this point in the history
…PUnit 11

See phpstan/phpstan#10757
  • Loading branch information
ondrejmirtes committed Mar 28, 2024
1 parent fd2e0a6 commit da87a65
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/Testing/TypeInferenceTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use PHPStan\TrinaryLogic;
use PHPStan\Type\ConstantScalarType;
use PHPStan\Type\FileTypeMapper;
use PHPStan\Type\Type;
use PHPStan\Type\VerbosityLevel;
use function array_map;
use function array_merge;
Expand Down Expand Up @@ -95,11 +96,18 @@ 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());
if ($args[0] instanceof Type) {
// backward compatibility
$expectedType = $args[0];
$this->assertInstanceOf(ConstantScalarType::class, $expectedType);
$expected = $expectedType->getValue();
$actualType = $args[1];
$actual = $actualType->describe(VerbosityLevel::precise());

Check failure on line 105 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.2, ubuntu-latest)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.

Check failure on line 105 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.2, windows-latest)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.
} else {
$expected = $args[0];
$actual = $args[1];
}

$this->assertSame(
$expected,

Check failure on line 112 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.2, ubuntu-latest)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.

Check failure on line 112 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.2, windows-latest)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.
$actual,
Expand Down Expand Up @@ -142,12 +150,19 @@ public static function gatherAssertTypes(string $file): array
));

Check failure on line 150 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, ubuntu-latest)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.

Check failure on line 150 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, windows-latest)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.
} elseif ($functionName === 'PHPStan\\Testing\\assertType') {
$expectedType = $scope->getType($node->getArgs()[0]->value);

Check failure on line 152 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.3, ubuntu-latest)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.

Check failure on line 152 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.3, windows-latest)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.
if (!$expectedType instanceof ConstantScalarType) {

Check failure on line 153 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.2)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.

Check failure on line 153 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.3)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.

Check failure on line 153 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.1)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.

Check failure on line 153 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, ubuntu-latest)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.

Check failure on line 153 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, ubuntu-latest)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.

Check failure on line 153 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, ubuntu-latest)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.

Check failure on line 153 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, ubuntu-latest)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.

Check failure on line 153 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, windows-latest)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.

Check failure on line 153 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, windows-latest)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.

Check failure on line 153 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, windows-latest)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.

Check failure on line 153 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, windows-latest)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.
self::fail(sprintf('Expected type must be a literal string, %s given on line %d.', $expectedType->describe(VerbosityLevel::precise()), $node->getLine()));
}
$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) {

Check failure on line 160 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.2)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.

Check failure on line 160 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.3)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.

Check failure on line 160 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.1)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.

Check failure on line 160 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, ubuntu-latest)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.

Check failure on line 160 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, ubuntu-latest)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.

Check failure on line 160 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, ubuntu-latest)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.

Check failure on line 160 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, ubuntu-latest)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.

Check failure on line 160 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, windows-latest)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.

Check failure on line 160 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, windows-latest)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.

Check failure on line 160 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, windows-latest)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.

Check failure on line 160 in src/Testing/TypeInferenceTestCase.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, windows-latest)

Doing instanceof PHPStan\Type\ConstantScalarType is error-prone and deprecated. Use Type::isConstantScalarValue() or Type::getConstantScalarTypes() or Type::getConstantScalarValues() instead.
self::fail(sprintf('Expected type must be a literal string, %s given on line %d.', $expectedType->describe(VerbosityLevel::precise()), $node->getLine()));
}

$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 da87a65

Please sign in to comment.