Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 26 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,32 @@ jobs:
OUTPUT=$(../bashunit assert exit_code "1" "../../bin/phpstan analyse -c cycle.neon --fix")
echo "$OUTPUT"
../bashunit assert contains 'Fixing stopped after 10 rounds' "$OUTPUT"
- script: |
cd e2e/fix-baseline
composer install
mkdir -p vendor/acme/rules && cp vendor-baseline.php vendor/acme/rules/baseline.php
rm -rf tmp && cp baseline-original.php baseline.php
OUTPUT=$(AI_AGENT=1 ../bashunit assert exit_code "1" "../../bin/phpstan analyse --error-format raw")
echo "$OUTPUT"
# two unmatched messages and an unmatched entry of the PHP baseline, and a count higher than the occurrences;
# not the entries in NEON and in vendor/, and not a count lower than the occurrences (--generate-baseline does that)
../bashunit assert contains '4 of the errors can be fixed automatically. Run PHPStan again with --fix' "$OUTPUT"
OUTPUT=$(../bashunit assert exit_code "1" "../../bin/phpstan analyse --fix --generate-baseline")
echo "$OUTPUT"
../bashunit assert contains 'Errors cannot be fixed when generating the baseline.' "$OUTPUT"
OUTPUT=$(../bashunit assert exit_code "0" "../../bin/phpstan analyse --fix")
echo "$OUTPUT"
# removing the last two messages of the list conflicts, the second one goes in the next round
../bashunit assert contains 'Round 2: fixed 1 error in 1 file' "$OUTPUT"
../bashunit assert contains '[OK] 4 errors fixed in 1 file' "$OUTPUT"
diff -u baseline-expected.php baseline.php
OUTPUT=$(../bashunit assert exit_code "1" "../../bin/phpstan analyse --error-format raw")
echo "$OUTPUT"
../bashunit assert contains 'Ignored error pattern #^Unmatched in NEON$#' "$OUTPUT"
../bashunit assert contains 'Ignored error pattern #^Unmatched in vendor$#' "$OUTPUT"
../bashunit assert contains 'is expected to occur 1 time, but occurred 2 times.' "$OUTPUT"
../bashunit assert not_contains 'Unmatched one' "$OUTPUT"
../bashunit assert not_contains 'occurred only' "$OUTPUT"
- script: |
cd e2e/editor-mode
OUTPUT=$(../bashunit assert exit_code "1" "../../bin/phpstan analyse -vv --error-format raw")
Expand Down
4 changes: 4 additions & 0 deletions e2e/fix-baseline/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/vendor
/composer.lock
/tmp
/baseline.php
35 changes: 35 additions & 0 deletions e2e/fix-baseline/baseline-expected.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php declare(strict_types = 1);

$ignoreErrors = [];
$ignoreErrors[] = [
'message' => '#^Undefined variable\: \$[abc]$#',
'identifier' => 'variable.undefined',
'count' => 3,
'path' => __DIR__ . '/src/Foo.php',
];
$ignoreErrors[] = [
'message' => '#^Function FixBaselineE2E\\\\bar\(\) should return string but returns int\.$#',
'identifier' => 'return.type',
'count' => 1,
'path' => __DIR__ . '/src/Foo.php',
];
$ignoreErrors[] = [
'messages' => [
'#^Undefined variable\: \$d$#',
],
'path' => __DIR__ . '/src/Foo.php',
];
$ignoreErrors[] = [
'message' => '#^Undefined variable\: \$e$#',
'identifier' => 'variable.undefined',
'count' => 1,
'path' => __DIR__ . '/src/Foo.php',
];
$ignoreErrors[] = [
'message' => '#^Undefined variable\: \$f$#',
'identifier' => 'variable.undefined',
'count' => 1,
'path' => __DIR__ . '/src/Foo.php',
];

return ['parameters' => ['ignoreErrors' => $ignoreErrors]];
43 changes: 43 additions & 0 deletions e2e/fix-baseline/baseline-original.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php declare(strict_types = 1);

$ignoreErrors = [];
$ignoreErrors[] = [
'message' => '#^Variable \$\w+ might not be defined\.$#',
'identifier' => 'variable.undefined',
'count' => 2,
'path' => __DIR__ . '/src/Foo.php',
];
$ignoreErrors[] = [
'message' => '#^Undefined variable\: \$[abc]$#',
'identifier' => 'variable.undefined',
'count' => 5,
'path' => __DIR__ . '/src/Foo.php',
];
$ignoreErrors[] = [
'message' => '#^Function FixBaselineE2E\\\\bar\(\) should return string but returns int\.$#',
'identifier' => 'return.type',
'count' => 1,
'path' => __DIR__ . '/src/Foo.php',
];
$ignoreErrors[] = [
'messages' => [
'#^Undefined variable\: \$d$#',
'#^Unmatched one$#',
'#^Unmatched two$#',
],
'path' => __DIR__ . '/src/Foo.php',
];
$ignoreErrors[] = [
'message' => '#^Undefined variable\: \$e$#',
'identifier' => 'variable.undefined',
'count' => 1,
'path' => __DIR__ . '/src/Foo.php',
];
$ignoreErrors[] = [
'message' => '#^Undefined variable\: \$f$#',
'identifier' => 'variable.undefined',
'count' => 1,
'path' => __DIR__ . '/src/Foo.php',
];

return ['parameters' => ['ignoreErrors' => $ignoreErrors]];
7 changes: 7 additions & 0 deletions e2e/fix-baseline/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"autoload": {
"psr-4": {
"FixBaselineE2E\\": "src/"
}
}
}
15 changes: 15 additions & 0 deletions e2e/fix-baseline/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
includes:
- baseline.php
# a config file of an installed package is never fixed
- vendor/acme/rules/baseline.php

parameters:
level: 8
paths:
- src
tmpDir: tmp
ignoreErrors:
# NEON config files are not fixed yet
-
message: '#^Unmatched in NEON$#'
path: src/Foo.php
27 changes: 27 additions & 0 deletions e2e/fix-baseline/src/Foo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php declare(strict_types = 1);

namespace FixBaselineE2E;

function foo(): void
{
echo $a;
echo $b;
echo $c;
}

function bar(int $i): string
{
return $i;
}

function baz(): void
{
echo $d;
echo $e;
}

function qux(): void
{
echo $f;
echo $f;
}
8 changes: 8 additions & 0 deletions e2e/fix-baseline/vendor-baseline.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php declare(strict_types = 1);

return ['parameters' => ['ignoreErrors' => [
[
'message' => '#^Unmatched in vendor$#',
'path' => __DIR__ . '/../../../src/Foo.php',
],
]]];
6 changes: 6 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ parameters:
count: 1
path: src/Analyser/ExprHandler/Helper/IncDecTypeHelper.php

-
rawMessage: 'Call to static method expand() of internal class Nette\DI\Helpers from outside its root namespace Nette.'
identifier: staticMethod.internalClass
count: 1
path: src/Analyser/Ignore/IgnoreErrorsConfigFixer.php

-
rawMessage: Casting to string something that's already string.
identifier: cast.useless
Expand Down
Loading
Loading