Skip to content

Commit 2316791

Browse files
committed
add StmtsIterableTest
1 parent b39f510 commit 2316791

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace PhpParser\Node;
4+
5+
use PhpParser\Node\Stmt\Foreach_;
6+
use PhpParser\Node\Stmt\Function_;
7+
use PhpParser\NodeFinder;
8+
use PhpParser\ParserFactory;
9+
10+
class StmtsIterableTest extends \PHPUnit\Framework\TestCase
11+
{
12+
public function test()
13+
{
14+
$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
15+
$nodes = $parser->parse(<<<'CODE_SAMPLE'
16+
<?php
17+
18+
function clearItemList($items)
19+
{
20+
foreach ($items as $key => $value) {
21+
$value = 100;
22+
$value = 100;
23+
}
24+
}
25+
CODE_SAMPLE
26+
);
27+
28+
$nodeFinder = new NodeFinder();
29+
$stmtsIterables = $nodeFinder->findInstanceOf($nodes, StmtsIterable::class);
30+
31+
$this->assertCount(2, $stmtsIterables);
32+
$this->assertInstanceOf(Function_::class, $stmtsIterables[0]);
33+
$this->assertInstanceOf(Foreach_::class, $stmtsIterables[1]);
34+
}
35+
}

0 commit comments

Comments
 (0)