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.
Add RequireExtends and RequireImplements attributes
- Loading branch information
1 parent
833e1b2
commit d726548
Showing
8 changed files
with
161 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,28 @@ | ||
<?php | ||
|
||
|
||
namespace test\PhpStaticAnalysis\PsalmPlugin; | ||
|
||
class RequireExtendsAttributeTest extends BaseAttributeTestCase | ||
{ | ||
public function testClassRequireExtendsAttribute(): void | ||
{ | ||
$errors = $this->analyzeTestFile('/data/RequireExtends/TraitRequireExtendsAttribute.php'); | ||
$expectedErrors = [ | ||
'test\PhpStaticAnalysis\PsalmPlugin\data\RequireExtends\TraitRequireExtendsAttribute requires using class to extend test\PhpStaticAnalysis\PsalmPlugin\data\RequireExtends\ClassRequireExtendsAttribute, but test\PhpStaticAnalysis\PsalmPlugin\data\RequireExtends\ClassRequireExtendsAttributeChild2 does not' => 23, | ||
]; | ||
|
||
$this->checkExpectedErrors($errors, $expectedErrors); | ||
} | ||
|
||
public function testInvalidClassRequireExtendsAttribute(): void | ||
{ | ||
$errors = $this->analyzeTestFile( '/data/RequireExtends/InvalidTraitRequireExtendsAttribute.php'); | ||
|
||
$expectedErrors = [ | ||
'Attribute RequireExtends cannot be used on a property' => 10, | ||
]; | ||
|
||
$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\PsalmPlugin; | ||
|
||
class RequireImplementsAttributeTest extends BaseAttributeTestCase | ||
{ | ||
public function testClassRequireImplementsAttribute(): void | ||
{ | ||
$errors = $this->analyzeTestFile('/data/RequireImplements/TraitRequireImplementsAttribute.php'); | ||
$expectedErrors = [ | ||
'test\PhpStaticAnalysis\PsalmPlugin\data\RequireImplements\TraitRequireImplementsAttribute requires using class to implement test\PhpStaticAnalysis\PsalmPlugin\data\RequireImplements\InterfaceRequireImplementsAttribute3, but test\PhpStaticAnalysis\PsalmPlugin\data\RequireImplements\ClassRequireImplementsAttribute2 does not' => 35, | ||
]; | ||
|
||
$this->checkExpectedErrors($errors, $expectedErrors); | ||
} | ||
|
||
public function testInvalidClassRequireImplementsAttribute(): void | ||
{ | ||
$errors = $this->analyzeTestFile( '/data/RequireImplements/InvalidTraitRequireImplementsAttribute.php'); | ||
|
||
$expectedErrors = [ | ||
'Attribute RequireImplements cannot be used on a property' => 10, | ||
]; | ||
|
||
$this->checkExpectedErrors($errors, $expectedErrors); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
tests/data/RequireExtends/InvalidTraitRequireExtendsAttribute.php
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,21 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PsalmPlugin\data\RequireExtends; | ||
|
||
use PhpStaticAnalysis\Attributes\RequireExtends; | ||
|
||
#[RequireExtends('InvalidClassRequireExtendsAttribute')] | ||
trait InvalidTraitRequireExtendsAttribute | ||
{ | ||
#[RequireExtends('InvalidClassRequireExtendsAttribute')] | ||
public string $name = ''; | ||
} | ||
|
||
class InvalidClassRequireExtendsAttribute | ||
{ | ||
} | ||
|
||
class InvalidClassRequireExtendsAttributeChild extends InvalidClassRequireExtendsAttribute | ||
{ | ||
use InvalidTraitRequireExtendsAttribute; | ||
} |
24 changes: 24 additions & 0 deletions
24
tests/data/RequireExtends/TraitRequireExtendsAttribute.php
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,24 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PsalmPlugin\data\RequireExtends; | ||
|
||
use PhpStaticAnalysis\Attributes\RequireExtends; | ||
|
||
#[RequireExtends('ClassRequireExtendsAttribute')] // the class using this trait needs to extend this class | ||
trait TraitRequireExtendsAttribute | ||
{ | ||
} | ||
|
||
class ClassRequireExtendsAttribute | ||
{ | ||
} | ||
|
||
class ClassRequireExtendsAttributeChild extends ClassRequireExtendsAttribute | ||
{ | ||
use TraitRequireExtendsAttribute; | ||
} | ||
|
||
class ClassRequireExtendsAttributeChild2 | ||
{ | ||
use TraitRequireExtendsAttribute; | ||
} |
21 changes: 21 additions & 0 deletions
21
tests/data/RequireImplements/InvalidTraitRequireImplementsAttribute.php
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,21 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PsalmPlugin\data\RequireImplements; | ||
|
||
use PhpStaticAnalysis\Attributes\RequireImplements; | ||
|
||
#[RequireImplements('InvalidInterfaceRequireImplementsAttribute')] | ||
trait InvalidTraitRequireImplementsAttribute | ||
{ | ||
#[RequireImplements('InvalidInterfaceRequireImplementsAttribute')] | ||
public string $name = ''; | ||
} | ||
|
||
interface InvalidInterfaceRequireImplementsAttribute | ||
{ | ||
} | ||
|
||
class InvalidClassRequireImplementsAttribute implements InvalidInterfaceRequireImplementsAttribute | ||
{ | ||
use InvalidTraitRequireImplementsAttribute; | ||
} |
36 changes: 36 additions & 0 deletions
36
tests/data/RequireImplements/TraitRequireImplementsAttribute.php
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\PsalmPlugin\data\RequireImplements; | ||
|
||
use PhpStaticAnalysis\Attributes\RequireImplements; | ||
|
||
#[RequireImplements('InterfaceRequireImplementsAttribute')] // the class that uses this trait needs to implement these interfaces | ||
#[RequireImplements( | ||
'InterfaceRequireImplementsAttribute2', | ||
'InterfaceRequireImplementsAttribute3' | ||
)] | ||
trait TraitRequireImplementsAttribute | ||
{ | ||
} | ||
|
||
interface InterfaceRequireImplementsAttribute | ||
{ | ||
} | ||
|
||
interface InterfaceRequireImplementsAttribute2 | ||
{ | ||
} | ||
|
||
interface InterfaceRequireImplementsAttribute3 | ||
{ | ||
} | ||
|
||
class ClassRequireImplementsAttribute implements InterfaceRequireImplementsAttribute, InterfaceRequireImplementsAttribute2, InterfaceRequireImplementsAttribute3 | ||
{ | ||
use TraitRequireImplementsAttribute; | ||
} | ||
|
||
class ClassRequireImplementsAttribute2 implements InterfaceRequireImplementsAttribute, InterfaceRequireImplementsAttribute2 | ||
{ | ||
use TraitRequireImplementsAttribute; | ||
} |