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 the TemplateExtends, TemplateImplements and TemplateUse attributes
- Loading branch information
1 parent
1a0052e
commit 9403aa4
Showing
11 changed files
with
245 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,29 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PsalmPlugin; | ||
|
||
class TemplateExtendsAttributeTest extends BaseAttributeTestCase | ||
{ | ||
public function testClassTemplateExtendsAttribute(): void | ||
{ | ||
$errors = $this->analyzeTestFile( '/data/TemplateExtends/ClassTemplateExtendsAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testInvalidClassTemplateExtendsAttribute(): void | ||
{ | ||
$errors = $this->analyzeTestFile( '/data/TemplateExtends/InvalidClassTemplateExtendsAttribute.php'); | ||
|
||
$expectedErrors = [ | ||
'Extended class cannot be empty in docblock for test\PhpStaticAnalysis\PsalmPlugin\data\TemplateExtends\InvalidClassTemplateExtendsAttributeChild' => 13, | ||
'test\PhpStaticAnalysis\PsalmPlugin\data\TemplateExtends\InvalidClassTemplateExtendsAttributeChild has missing template params when extending test\PhpStaticAnalysis\PsalmPlugin\data\TemplateExtends\InvalidClassTemplateExtendsAttribute, expecting 1' => 14, | ||
'Argument 1 of PhpStaticAnalysis\Attributes\TemplateExtends::__construct expects string, but 0 provided' => 13, | ||
'Invalid type \'test\PhpStaticAnalysis\PsalmPlugin\data\TemplateExtends\+5\' in docblock for test\PhpStaticAnalysis\PsalmPlugin\data\TemplateExtends\InvalidClassTemplateExtendsAttributeChild2' => 18, | ||
'test\PhpStaticAnalysis\PsalmPlugin\data\TemplateExtends\InvalidClassTemplateExtendsAttributeChild2 has missing template params when extending test\PhpStaticAnalysis\PsalmPlugin\data\TemplateExtends\InvalidClassTemplateExtendsAttribute, expecting 1' => 19, | ||
'Attribute TemplateExtends is not repeatable' => 24, | ||
'Attribute TemplateExtends cannot be used on a property' => 27, | ||
]; | ||
|
||
$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,28 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PsalmPlugin; | ||
|
||
class TemplateImplementsAttributeTest extends BaseAttributeTestCase | ||
{ | ||
public function testInterfaceTemplateImplementsAttribute(): void | ||
{ | ||
$errors = $this->analyzeTestFile('/data/TemplateImplements/InterfaceTemplateImplementsAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testInvalidInterfaceTemplateImplementsAttribute(): void | ||
{ | ||
$errors = $this->analyzeTestFile('/data/TemplateImplements/InvalidInterfaceTemplateImplementsAttribute.php'); | ||
|
||
$expectedErrors = [ | ||
'Extended class cannot be empty in docblock for test\PhpStaticAnalysis\PsalmPlugin\data\TemplateImplements\InvalidClassTemplateImplementsAttribute' => 13, | ||
'test\PhpStaticAnalysis\PsalmPlugin\data\TemplateImplements\InvalidClassTemplateImplementsAttribute has missing template params when extending test\PhpStaticAnalysis\PsalmPlugin\data\TemplateImplements\InvalidInterfaceTemplateImplementsAttribute, expecting 1' => 14, | ||
'Argument 1 of PhpStaticAnalysis\Attributes\TemplateImplements::__construct expects string, but 0 provided' => 13, | ||
'Invalid type \'test\PhpStaticAnalysis\PsalmPlugin\data\TemplateImplements\+5\' in docblock for test\PhpStaticAnalysis\PsalmPlugin\data\TemplateImplements\InvalidClassTemplateImplementsAttribute2' => 18, | ||
'test\PhpStaticAnalysis\PsalmPlugin\data\TemplateImplements\InvalidClassTemplateImplementsAttribute2 has missing template params when extending test\PhpStaticAnalysis\PsalmPlugin\data\TemplateImplements\InvalidInterfaceTemplateImplementsAttribute, expecting 1' => 19, | ||
'Attribute TemplateImplements cannot be used on a property' => 21, | ||
]; | ||
|
||
$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,26 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PsalmPlugin; | ||
|
||
class TemplateUseAttributeTest extends BaseAttributeTestCase | ||
{ | ||
public function testTraitTemplateUseAttribute(): void | ||
{ | ||
$errors = $this->analyzeTestFile('/data/TemplateUse/TraitTemplateUseAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testInvalidTraitTemplateUseAttribute(): void | ||
{ | ||
$errors = $this->analyzeTestFile('/data/TemplateUse/InvalidTraitTemplateUseAttribute.php'); | ||
|
||
$expectedErrors = [ | ||
'Argument 1 of PhpStaticAnalysis\Attributes\TemplateUse::__construct expects string, but 0 provided' => 13, | ||
'test\PhpStaticAnalysis\PsalmPlugin\data\TemplateUse\InvalidClassTemplateUseAttribute has missing template params when extending test\PhpStaticAnalysis\PsalmPlugin\data\TemplateUse\InvalidTraitTemplateUseAttribute, expecting 1' => 16, | ||
'test\PhpStaticAnalysis\PsalmPlugin\data\TemplateUse\InvalidClassTemplateUseAttribute2 has missing template params when extending test\PhpStaticAnalysis\PsalmPlugin\data\TemplateUse\InvalidTraitTemplateUseAttribute, expecting 1' => 22, | ||
'Attribute TemplateUse cannot be used on a property' => 24, | ||
]; | ||
|
||
$this->checkExpectedErrors($errors, $expectedErrors); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/data/TemplateExtends/ClassTemplateExtendsAttribute.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,16 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PsalmPlugin\data\TemplateExtends; | ||
|
||
use PhpStaticAnalysis\Attributes\Template; | ||
use PhpStaticAnalysis\Attributes\TemplateExtends; | ||
|
||
#[Template('T')] | ||
class ClassTemplateExtendsAttribute | ||
{ | ||
} | ||
|
||
#[TemplateExtends('ClassTemplateExtendsAttribute<int>')] // this class extends the base template | ||
class ClassTemplateExtendsAttributeChild extends ClassTemplateExtendsAttribute | ||
{ | ||
} |
29 changes: 29 additions & 0 deletions
29
tests/data/TemplateExtends/InvalidClassTemplateExtendsAttribute.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,29 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PsalmPlugin\data\TemplateExtends; | ||
|
||
use PhpStaticAnalysis\Attributes\Template; | ||
use PhpStaticAnalysis\Attributes\TemplateExtends; | ||
|
||
#[Template('T')] | ||
class InvalidClassTemplateExtendsAttribute | ||
{ | ||
} | ||
|
||
#[TemplateExtends(0)] | ||
class InvalidClassTemplateExtendsAttributeChild extends InvalidClassTemplateExtendsAttribute | ||
{ | ||
} | ||
|
||
#[TemplateExtends('+5')] | ||
class InvalidClassTemplateExtendsAttributeChild2 extends InvalidClassTemplateExtendsAttribute | ||
{ | ||
} | ||
|
||
#[TemplateExtends('InvalidClassTemplateExtendsAttribute<int>')] | ||
#[TemplateExtends('InvalidClassTemplateExtendsAttribute<int>')] | ||
class InvalidClassTemplateExtendsAttributeChild3 extends InvalidClassTemplateExtendsAttribute | ||
{ | ||
#[TemplateExtends('InvalidClassTemplateExtendsAttribute<int>')] | ||
public string $name = ''; | ||
} |
30 changes: 30 additions & 0 deletions
30
tests/data/TemplateImplements/InterfaceTemplateImplementsAttribute.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,30 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PsalmPlugin\data\TemplateImplements; | ||
|
||
use PhpStaticAnalysis\Attributes\Template; | ||
use PhpStaticAnalysis\Attributes\TemplateImplements; | ||
|
||
#[Template('T')] | ||
interface InterfaceTemplateImplementsAttribute | ||
{ | ||
} | ||
|
||
#[Template('T')] | ||
interface InterfaceTemplateImplementsAttribute2 | ||
{ | ||
} | ||
|
||
#[Template('T')] | ||
interface InterfaceTemplateImplementsAttribute3 | ||
{ | ||
} | ||
|
||
#[TemplateImplements('InterfaceTemplateImplementsAttribute<int>')] // this class implements the base interface | ||
#[TemplateImplements( | ||
'InterfaceTemplateImplementsAttribute2<int>', | ||
'InterfaceTemplateImplementsAttribute3<int>' | ||
)] | ||
class ClassTemplateImplementsAttribute implements InterfaceTemplateImplementsAttribute, InterfaceTemplateImplementsAttribute2, InterfaceTemplateImplementsAttribute3 | ||
{ | ||
} |
23 changes: 23 additions & 0 deletions
23
tests/data/TemplateImplements/InvalidInterfaceTemplateImplementsAttribute.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,23 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PsalmPlugin\data\TemplateImplements; | ||
|
||
use PhpStaticAnalysis\Attributes\Template; | ||
use PhpStaticAnalysis\Attributes\TemplateImplements; | ||
|
||
#[Template('T')] | ||
interface InvalidInterfaceTemplateImplementsAttribute | ||
{ | ||
} | ||
|
||
#[TemplateImplements(0)] | ||
class InvalidClassTemplateImplementsAttribute implements InvalidInterfaceTemplateImplementsAttribute | ||
{ | ||
} | ||
|
||
#[TemplateImplements('+5')] | ||
class InvalidClassTemplateImplementsAttribute2 implements InvalidInterfaceTemplateImplementsAttribute | ||
{ | ||
#[TemplateImplements('InvalidInterfaceTemplateImplementsAttribute<int>')] | ||
public string $name = ''; | ||
} |
26 changes: 26 additions & 0 deletions
26
tests/data/TemplateUse/InvalidTraitTemplateUseAttribute.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,26 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PsalmPlugin\data\TemplateUse; | ||
|
||
use PhpStaticAnalysis\Attributes\Template; | ||
use PhpStaticAnalysis\Attributes\TemplateUse; | ||
|
||
#[Template('T')] | ||
trait InvalidTraitTemplateUseAttribute | ||
{ | ||
} | ||
|
||
#[TemplateUse(0)] | ||
class InvalidClassTemplateUseAttribute | ||
{ | ||
use InvalidTraitTemplateUseAttribute; | ||
} | ||
|
||
#[TemplateUse('+5')] | ||
class InvalidClassTemplateUseAttribute2 | ||
{ | ||
use InvalidTraitTemplateUseAttribute; | ||
|
||
#[TemplateUse('InvalidTraitTemplateUseAttribute<int>')] | ||
public string $name = ''; | ||
} |
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,33 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PsalmPlugin\data\TemplateUse; | ||
|
||
use PhpStaticAnalysis\Attributes\Template; | ||
use PhpStaticAnalysis\Attributes\TemplateUse; | ||
|
||
#[Template('T')] | ||
trait TraitTemplateUseAttribute | ||
{ | ||
} | ||
|
||
#[Template('T')] | ||
trait TraitTemplateUseAttribute2 | ||
{ | ||
} | ||
|
||
#[Template('T')] | ||
trait TraitTemplateUseAttribute3 | ||
{ | ||
} | ||
|
||
#[TemplateUse('TraitTemplateUseAttribute<int>')] // this class uses the base trait | ||
#[TemplateUse( | ||
'TraitTemplateUseAttribute2<int>', | ||
'TraitTemplateUseAttribute3<int>' | ||
)] | ||
class ClassTemplateUseAttribute | ||
{ | ||
use TraitTemplateUseAttribute; | ||
use TraitTemplateUseAttribute2; | ||
use TraitTemplateUseAttribute3; | ||
} |