Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .claude/skills/regression-test/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ Use when the bug is about **wrong inferred type, missing type narrowing, or inco
Example (`tests/PHPStan/Analyser/nsrt/bug-12875.php`):

```php
<?php declare(strict_types = 1); // lint >= 8.0
<?php // lint >= 8.0

declare(strict_types = 1);

namespace Bug12875;

Expand Down
13 changes: 11 additions & 2 deletions .github/workflows/tests-levels-matrix.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
<?php declare(strict_types = 1);

shell_exec('php vendor/bin/phpunit --group levels --list-tests-xml test-list.xml');
exec('php vendor/bin/phpunit --group levels --list-tests-xml test-list.xml', $output, $return);
if ($return !== 0) {
throw new RuntimeException(implode("\n", $output));
}

libxml_use_internal_errors(true);
$simpleXml = simplexml_load_file('test-list.xml');
if ($simpleXml === false) {
throw new RuntimeException('Error loading test-list.xml');
$errors = [];
foreach (libxml_get_errors() as $error) {
$errors[] = $error->message;
}

throw new RuntimeException('Error loading test-list.xml: ' . implode(', ', $errors));
Comment on lines +3 to +16
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure when a underlying error occurs we see a meaningful error with hints for the root-cause

}

$testFilters = [];
Expand Down
12 changes: 10 additions & 2 deletions src/Testing/TypeInferenceTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PHPStan\Testing;

use LogicException;
use PhpParser\Node;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Name;
Expand Down Expand Up @@ -44,6 +45,7 @@
use function is_string;
use function preg_match;
use function sprintf;
use function str_contains;
use function str_starts_with;
use function stripos;
use function strtolower;
Expand Down Expand Up @@ -432,8 +434,12 @@ public static function findTestDataFilesFromDirectory(string $directory): array
$files = [];
foreach ($finder->files()->name('*.php')->in($directory) as $fileInfo) {
$path = $fileInfo->getPathname();
if (self::isFileLintSkipped($path)) {
continue;
try {
if (self::isFileLintSkipped($path)) {
continue;
}
} catch (LogicException $e) {
self::fail($e->getMessage());
}
$files[] = $path;
}
Expand Down Expand Up @@ -467,6 +473,8 @@ private static function isFileLintSkipped(string $file): bool

if (preg_match('~<?php\\s*\\/\\/\s*lint\s*([^\d\s]+)\s*([^\s]+)\s*~i', $firstLine, $m) === 1) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here we can see that for TypeInferenceTestCase to work properly, we expect <?php // lint at the very start

return version_compare(PHP_VERSION, $m[2], $m[1]) === false;
} elseif (str_contains($firstLine, 'lint')) {
throw new LogicException(sprintf('// lint comment must immediately follow the php starting tag in %s', $file));
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the new error which will be triggered

}
}

Expand Down
4 changes: 3 additions & 1 deletion tests/PHPStan/Analyser/nsrt/bug-11472.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types = 1); // lint >= 8.1
<?php // lint >= 8.1

declare(strict_types = 1);

namespace Bug11472;

Expand Down
4 changes: 3 additions & 1 deletion tests/PHPStan/Analyser/nsrt/bug-12866.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types = 1); // lint >= 8.0
<?php // lint >= 8.0

declare(strict_types = 1);

namespace Bug12866;

Expand Down
4 changes: 3 additions & 1 deletion tests/PHPStan/Analyser/nsrt/bug-12875.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types = 1); // lint >= 8.0
<?php // lint >= 8.0

declare(strict_types = 1);

namespace Bug12875a;

Expand Down
Loading