generated from psalm/psalm-plugin-skeleton
-
-
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
21d2d55
commit a9e5db4
Showing
8 changed files
with
140 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
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,38 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PsalmPlugin; | ||
|
||
class MethodAttributeTest extends BaseAttributeTestCase | ||
{ | ||
public function testClassMethodAttribute(): void | ||
{ | ||
$errors = $this->analyzeTestFile( '/data/Method/ClassMethodAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testInterfaceMethodAttribute(): void | ||
{ | ||
$errors = $this->analyzeTestFile( '/data/Method/InterfaceMethodAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testTraitMethodAttribute(): void | ||
{ | ||
$errors = $this->analyzeTestFile( '/data/Method/TraitMethodAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testInvalidClassMethodAttribute(): void | ||
{ | ||
$errors = $this->analyzeTestFile( '/data/Method/InvalidClassMethodAttribute.php'); | ||
|
||
$expectedErrors = [ | ||
'No @method entry specified in docblock for test\PhpStaticAnalysis\PsalmPlugin\data\Method\InvalidClassMethodAttribute' => 9, | ||
'Argument 1 of PhpStaticAnalysis\Attributes\Method::__construct expects string, but 0 provided' => 8, | ||
'Attribute Method cannot be used on a method' => 11, | ||
'string is not a valid method in docblock for test\PhpStaticAnalysis\PsalmPlugin\data\Method\AnotherInvalidClassMethodAttribute' => 29, | ||
]; | ||
|
||
$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,39 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PsalmPlugin\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; | ||
} | ||
|
||
#[Param(arguments: 'mixed[]')] | ||
public static function __callStatic(string $name, array $arguments): mixed | ||
{ | ||
$callable = [get_called_class(), $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\PsalmPlugin\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,34 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PsalmPlugin\data\Method; | ||
|
||
use PhpStaticAnalysis\Attributes\Method; | ||
use PhpStaticAnalysis\Attributes\Param; | ||
|
||
#[Method(0)] | ||
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; | ||
} | ||
} | ||
|
||
#[Method('string')] | ||
class AnotherInvalidClassMethodAttribute | ||
{ | ||
} | ||
|
||
$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\PsalmPlugin\data\Method; | ||
|
||
use PhpStaticAnalysis\Attributes\Method; | ||
|
||
#[Method('string getString()')] | ||
trait TraitMethodAttribute | ||
{ | ||
} |