-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eff8976
commit 6d53c47
Showing
2 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of PHP-CFG, a Control flow graph implementation for PHP | ||
* | ||
* @copyright 2015 Anthony Ferrara. All rights reserved | ||
* @license MIT See LICENSE at the root of the project for more info | ||
*/ | ||
|
||
namespace PHPCfg; | ||
|
||
use PHPCfg\AstVisitor\NameResolver; | ||
use PHPCfg\AstVisitor\MagicStringResolver; | ||
use PhpParser\NodeTraverser; | ||
use PhpParser\Parser; | ||
use PhpParser\ParserFactory; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class MagicStringResolverTest extends TestCase | ||
{ | ||
/** @var Parser */ | ||
private $astParser; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->astParser = (new ParserFactory())->createForNewestSupportedVersion(); | ||
} | ||
|
||
public function testIgnoresInvalidParamTypeInDocComment() | ||
{ | ||
$doccomment = <<<'DOC' | ||
/** | ||
* @param Foo\foo bar | ||
*/ | ||
DOC; | ||
|
||
$code = <<<'DOC' | ||
<?php | ||
namespace Foo { | ||
class Test { | ||
/** | ||
* @param foo bar | ||
*/ | ||
public function test($foo) { | ||
echo __LINE__; | ||
} | ||
} | ||
} | ||
DOC; | ||
|
||
$ast = $this->astParser->parse($code); | ||
$traverser = new NodeTraverser(); | ||
$traverser->addVisitor(new NameResolver()); | ||
$traverser->addVisitor(new MagicStringResolver()); | ||
$traverser->traverse($ast); | ||
|
||
$this->assertEquals($doccomment, $ast[0]->stmts[0]->stmts[0]->getDocComment()->getText()); | ||
$this->assertEquals(9, $ast[0]->stmts[0]->stmts[0]->stmts[0]->exprs[0]->value); | ||
} | ||
} |