-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
cae6644
commit e16bdc9
Showing
6 changed files
with
114 additions
and
12 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
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
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,54 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\NodeVisitor; | ||
|
||
use Exception; | ||
use PhpParser\Node; | ||
use PhpParser\Node\Attribute; | ||
use PhpParser\Node\AttributeGroup; | ||
use PhpParser\Node\Name\FullyQualified; | ||
use PhpStaticAnalysis\Attributes\Throws; | ||
|
||
class ThrowsAttributeNodeVisitorTest extends AttributeNodeVisitorTestBase | ||
{ | ||
public function testAddsThrowsPHPDoc(): void | ||
{ | ||
$node = new Node\Stmt\ClassMethod('Test'); | ||
$this->addThrowsAttributesToNode($node); | ||
$this->nodeVisitor->enterNode($node); | ||
$docText = $this->getDocText($node); | ||
$this->assertEquals("/**\n * @throws Exception\n */", $docText); | ||
} | ||
|
||
public function testAddsSeveralThrowsPHPDocs(): void | ||
{ | ||
$node = new Node\Stmt\ClassMethod('Test'); | ||
$this->addThrowsAttributesToNode($node, 2); | ||
$this->nodeVisitor->enterNode($node); | ||
$docText = $this->getDocText($node); | ||
$this->assertEquals("/**\n * @throws Exception\n * @throws Exception\n */", $docText); | ||
} | ||
|
||
public function testAddsMultipleThrowsPHPDocs(): void | ||
{ | ||
$node = new Node\Stmt\ClassMethod('Test'); | ||
$this->addThrowsAttributesToNode($node); | ||
$this->addThrowsAttributesToNode($node); | ||
$this->nodeVisitor->enterNode($node); | ||
$docText = $this->getDocText($node); | ||
$this->assertEquals("/**\n * @throws Exception\n * @throws Exception\n */", $docText); | ||
} | ||
|
||
private function addThrowsAttributesToNode(Node\Stmt\ClassMethod $node, int $num = 1): void | ||
{ | ||
$exception = new Node\Name(Exception::class); | ||
$value = new Node\Expr\ClassConstFetch($exception, 'class'); | ||
$args = []; | ||
for ($i = 0; $i < $num; $i++) { | ||
$args[] = new Node\Arg($value); | ||
} | ||
$attributeName = new FullyQualified(Throws::class); | ||
$attribute = new Attribute($attributeName, $args); | ||
$node->attrGroups = array_merge($node->attrGroups, [new AttributeGroup([$attribute])]); | ||
} | ||
} |