-
-
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
af782fa
commit 66ad943
Showing
7 changed files
with
122 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
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,39 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension; | ||
|
||
class MethodAttributeTest extends BaseAttributeTestCase | ||
{ | ||
public function testClassMethodAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/Method/ClassMethodAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testInterfaceMethodAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/Method/InterfaceMethodAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testTraitMethodAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/Method/TraitMethodAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testInvalidClassMethodAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/Method/InvalidClassMethodAttribute.php'); | ||
|
||
$expectedErrors = [ | ||
'PHPDoc tag @method has invalid value (): Unexpected token "\n * ", expected type at offset 14' => 8, | ||
'PHPDoc tag @method has invalid value (string): Unexpected token "\n * ", expected \'(\' at offset 32' => 8, | ||
'Parameter #1 ...$params of attribute class PhpStaticAnalysis\Attributes\Method constructor expects string, int given.' => 8, | ||
'Attribute class PhpStaticAnalysis\Attributes\Method does not have the method target.' => 13, | ||
'Call to an undefined method test\PhpStaticAnalysis\PHPStanExtension\data\Method\InvalidClassMethodAttribute::badFunction().' => 31, | ||
]; | ||
|
||
$this->checkExpectedErrors($errors, $expectedErrors); | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension\data\Method; | ||
|
||
use PhpStaticAnalysis\Attributes\Method; | ||
use PhpStaticAnalysis\Attributes\Param; | ||
|
||
#[Method('string getString()')] | ||
#[Method( | ||
'void setString(string $text)', | ||
'static string staticGetter()', | ||
)] | ||
class ClassMethodAttribute | ||
{ | ||
#[Param(arguments: 'mixed[]')] | ||
public function __call(string $name, array $arguments): mixed | ||
{ | ||
$callable = [$this, $name]; | ||
if (is_callable($callable)) { | ||
return call_user_func_array($callable, $arguments); | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
$class = new ClassMethodAttribute(); | ||
$foo = $class->getString(); | ||
$class->setString($foo); | ||
$bar = ClassMethodAttribute::staticGetter(); |
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,10 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension\data\Method; | ||
|
||
use PhpStaticAnalysis\Attributes\Method; | ||
|
||
#[Method('string getString()')] | ||
interface InterfaceMethodAttribute | ||
{ | ||
} |
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,31 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension\data\Method; | ||
|
||
use PhpStaticAnalysis\Attributes\Method; | ||
use PhpStaticAnalysis\Attributes\Param; | ||
|
||
#[Method(0)] | ||
#[Method('string')] | ||
#[Method('count($a)')] | ||
class InvalidClassMethodAttribute | ||
{ | ||
#[Method('string getString()')] | ||
public function getName(): string | ||
{ | ||
return "John"; | ||
} | ||
|
||
#[Param(arguments: 'mixed[]')] | ||
public function __call(string $name, array $arguments): mixed | ||
{ | ||
$callable = [$this, $name]; | ||
if (is_callable($callable)) { | ||
return call_user_func_array($callable, $arguments); | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
$class = new InvalidClassMethodAttribute(); | ||
$class->badFunction(); |
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,10 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension\data\Method; | ||
|
||
use PhpStaticAnalysis\Attributes\Method; | ||
|
||
#[Method('string getString()')] | ||
trait TraitMethodAttribute | ||
{ | ||
} |