-
-
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
493630e
commit e1e3ea2
Showing
7 changed files
with
121 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,38 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension; | ||
|
||
class MixinAttributeTest extends BaseAttributeTestCase | ||
{ | ||
public function testClassMixinAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/Mixin/ClassMixinAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testInterfaceMixinAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/Mixin/InterfaceMixinAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testTraitMixinAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/Mixin/TraitMixinAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testInvalidClassMixinAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/Mixin/InvalidClassMixinAttribute.php'); | ||
|
||
$expectedErrors = [ | ||
'PHPDoc tag @mixin contains unknown class test\PhpStaticAnalysis\PHPStanExtension\data\Mixin\count.' => 7, | ||
'PHPDoc tag @mixin has invalid value (): Unexpected token "\n * ", expected type at offset 13' => 7, | ||
'Parameter #1 ...$params of attribute class PhpStaticAnalysis\Attributes\Mixin constructor expects string, int given.' => 7, | ||
'Attribute class PhpStaticAnalysis\Attributes\Mixin does not have the method target.' => 11, | ||
]; | ||
|
||
$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,36 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension\data\Mixin; | ||
|
||
use PhpStaticAnalysis\Attributes\Mixin; | ||
|
||
class ClassMixinAttribute | ||
{ | ||
public function proxied(): void | ||
{ | ||
} | ||
} | ||
|
||
class MyClass | ||
{ | ||
} | ||
|
||
class Another | ||
{ | ||
} | ||
|
||
#[Mixin('ClassMixinAttribute')] // this is the proxied class | ||
#[Mixin( | ||
'MyClass', | ||
'Another', | ||
)] | ||
class ClassMixinAttributeProxy | ||
{ | ||
public function __call(string $name, mixed ...$arguments): void | ||
{ | ||
(new ClassMixinAttribute())->$name(...$arguments); | ||
} | ||
} | ||
|
||
$proxy = new ClassMixinAttributeProxy(); | ||
$proxy->proxied(); |
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,14 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension\data\Mixin; | ||
|
||
use PhpStaticAnalysis\Attributes\Mixin; | ||
|
||
#[Mixin('AClass')] | ||
interface InterfaceMixinAttribute | ||
{ | ||
} | ||
|
||
class AClass | ||
{ | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension\data\Mixin; | ||
|
||
use PhpStaticAnalysis\Attributes\Mixin; | ||
|
||
#[Mixin(0)] | ||
#[Mixin('count($a)')] | ||
class InvalidClassMixinAttribute | ||
{ | ||
#[Mixin('A')] | ||
public function getName(): string | ||
{ | ||
return "John"; | ||
} | ||
} |
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,14 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension\data\Mixin; | ||
|
||
use PhpStaticAnalysis\Attributes\Mixin; | ||
|
||
class Other | ||
{ | ||
} | ||
|
||
#[Mixin('Other')] | ||
trait TraitMixinAttribute | ||
{ | ||
} |