Skip to content

Commit

Permalink
Integration test for parent/previous/next node attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Apr 14, 2022
1 parent d77a607 commit b60c8fb
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/other-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ jobs:
- |
cd e2e/attribute-74
../../phpstan analyse -l 9 test.php -c test.neon
- |
cd e2e/node-connecting
../../phpstan analyse -a Rule.php
include:
- php-version: 8.0
ini-values: memory_limit=256M
Expand Down
31 changes: 31 additions & 0 deletions e2e/node-connecting/Rule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace NodeConnectingRule;

use PhpParser\Node;
use PhpParser\Node\Stmt\Echo_;
use PHPStan\Analyser\Scope;

/** @implements \PHPStan\Rules\Rule<Echo_> */
class Rule implements \PHPStan\Rules\Rule
{

public function getNodeType(): string
{
return Echo_::class;
}

public function processNode(Node $node, Scope $scope): array
{
return [
sprintf(
'Parent: %s, previous: %s, next: %s',
get_class($node->getAttribute('parent')),
get_class($node->getAttribute('previous')),
get_class($node->getAttribute('next'))
),
];
}


}
7 changes: 7 additions & 0 deletions e2e/node-connecting/baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
parameters:
ignoreErrors:
-
message: "#^Parent\\: PhpParser\\\\Node\\\\Stmt\\\\ClassMethod, previous\\: PhpParser\\\\Node\\\\Stmt\\\\If_, next\\: PhpParser\\\\Node\\\\Stmt\\\\Do_$#"
count: 1
path: src/test.php

11 changes: 11 additions & 0 deletions e2e/node-connecting/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
includes:
- phar://phpstan.phar/conf/bleedingEdge.neon
- baseline.neon

parameters:
paths:
- src
level: 8

rules:
- NodeConnectingRule\Rule
19 changes: 19 additions & 0 deletions e2e/node-connecting/src/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace NodeConnecting;

class Foo
{

public function doFoo(bool $b): void
{
if ($b) {

}
echo 'bar';
do {
break;
} while ($b);
}

}

0 comments on commit b60c8fb

Please sign in to comment.