-
-
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
d18e6ea
commit bc532d5
Showing
4 changed files
with
73 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,27 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension; | ||
|
||
class PropertyAttributeTest extends BaseAttributeTestCase | ||
{ | ||
public function testClassPropertyAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/ClassPropertyAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testInvalidClassPropertyAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/InvalidClassPropertyAttribute.php'); | ||
|
||
$expectedErrors = [ | ||
'PHPDoc tag @property has invalid value (): Unexpected token "\n * ", expected type at offset 16' => 7, | ||
'PHPDoc tag @property has invalid value (count($a) $name): Unexpected token "(", expected variable at offset 55' => 7, | ||
'PHPDoc tag @property has invalid value (string): Unexpected token "\n * ", expected variable at offset 36' => 7, | ||
'Parameter #1 ...$params of attribute class PhpStaticAnalysis\Attributes\Property constructor expects string, int given.' => 7, | ||
'Attribute class PhpStaticAnalysis\Attributes\Property does not have the method target.' => 12, | ||
]; | ||
|
||
$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,27 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension\data; | ||
|
||
use PhpStaticAnalysis\Attributes\Property; | ||
|
||
#[Property(name: 'string')] | ||
#[Property('int $age')] | ||
#[Property( | ||
index1: 'string[]', | ||
index2: 'string[]', | ||
)] | ||
class ClassPropertyAttribute | ||
{ | ||
#[Property('int[]')] | ||
public array $nums; | ||
|
||
public function __get(string $name): mixed | ||
{ | ||
return $name; | ||
} | ||
} | ||
|
||
$class = new ClassPropertyAttribute(); | ||
$foo = $class->name; | ||
$bar = $class->age; | ||
$indexes = $class->index1 + $class->index2; |
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,17 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension\data; | ||
|
||
use PhpStaticAnalysis\Attributes\Property; | ||
|
||
#[Property(0)] | ||
#[Property('string')] | ||
#[Property(name: 'count($a)')] | ||
class InvalidClassPropertyAttribute | ||
{ | ||
#[Property('string')] | ||
public function getNane(): string | ||
{ | ||
return "John"; | ||
} | ||
} |