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
1582a2d
commit 21d2d55
Showing
16 changed files
with
216 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
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,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace test\PhpStaticAnalysis\PsalmPlugin; | ||
|
||
class TemplateCovariantAttributeTest extends BaseAttributeTestCase | ||
{ | ||
public function testClassTemplateCovariantAttribute(): void | ||
{ | ||
$errors = $this->analyzeTestFile('/data/TemplateCovariant/ClassTemplateCovariantAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testInterfaceTemplateCovariantAttribute(): void | ||
{ | ||
$errors = $this->analyzeTestFile('/data/TemplateCovariant/InterfaceTemplateCovariantAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testTraitTemplateCovariantAttribute(): void | ||
{ | ||
$errors = $this->analyzeTestFile('/data/TemplateCovariant/TraitTemplateCovariantAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testInvalidClassTemplateCovariantAttribute(): void | ||
{ | ||
$errors = $this->analyzeTestFile('/data/TemplateCovariant/InvalidClassTemplateCovariantAttribute.php'); | ||
$this->checkExpectedErrors($errors,[ | ||
'Empty @template-covariant tag in docblock for test\PhpStaticAnalysis\PsalmPlugin\data\TemplateCovariant\InvalidClassTemplateCovariantAttribute' => 10, | ||
'Argument 1 of PhpStaticAnalysis\Attributes\TemplateCovariant::__construct expects string, but 0 provided' => 7, | ||
'Argument 2 of PhpStaticAnalysis\Attributes\TemplateCovariant::__construct expects null|string, but 0 provided' => 9, | ||
'Attribute TemplateCovariant cannot be used on a property' => 12, | ||
]); | ||
} | ||
} |
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\Property; | ||
|
||
use PhpStaticAnalysis\Attributes\Property; | ||
|
||
#[Property(name: 'string')] | ||
interface InterfacePropertyAttribute | ||
{ | ||
} |
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\Property; | ||
|
||
use PhpStaticAnalysis\Attributes\Property; | ||
|
||
#[Property(name: 'string')] | ||
trait TraitPropertyAttribute | ||
{ | ||
} |
10 changes: 10 additions & 0 deletions
10
tests/data/PropertyRead/InterfacePropertyReadAttribute.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,10 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PsalmPlugin\data\PropertyRead; | ||
|
||
use PhpStaticAnalysis\Attributes\PropertyRead; | ||
|
||
#[PropertyRead(name: 'string')] | ||
interface InterfacePropertyReadAttribute | ||
{ | ||
} |
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\PropertyRead; | ||
|
||
use PhpStaticAnalysis\Attributes\PropertyRead; | ||
|
||
#[PropertyRead(name: 'string')] | ||
trait TraitPropertyReadAttribute | ||
{ | ||
} |
10 changes: 10 additions & 0 deletions
10
tests/data/PropertyWrite/InterfacePropertyWriteAttribute.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,10 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PsalmPlugin\data\PropertyWrite; | ||
|
||
use PhpStaticAnalysis\Attributes\PropertyWrite; | ||
|
||
#[PropertyWrite(name: 'string')] | ||
interface InterfacePropertyWriteAttribute | ||
{ | ||
} |
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\PropertyWrite; | ||
|
||
use PhpStaticAnalysis\Attributes\PropertyWrite; | ||
|
||
#[PropertyWrite(name: 'string')] | ||
trait TraitPropertyWriteAttribute | ||
{ | ||
} |
35 changes: 35 additions & 0 deletions
35
tests/data/TemplateCovariant/ClassTemplateCovariantAttribute.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,35 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PsalmPlugin\data\TemplateCovariant; | ||
|
||
use PhpStaticAnalysis\Attributes\Param; | ||
use PhpStaticAnalysis\Attributes\Returns; | ||
use PhpStaticAnalysis\Attributes\TemplateCovariant; | ||
use PhpStaticAnalysis\Attributes\Type; | ||
|
||
abstract class ClassTemplateCovariantAttribute | ||
{ | ||
abstract public function getName() : string; | ||
} | ||
class ClassTemplateCovariantAttributeChild extends ClassTemplateCovariantAttribute | ||
{ | ||
public function getName() : string { return "child"; } | ||
} | ||
|
||
#[TemplateCovariant('T')] | ||
class Collection { | ||
#[Type('array<int, T>')] | ||
public array $list = []; | ||
} | ||
|
||
#[Param(collection: 'Collection<ClassTemplateCovariantAttribute>')] | ||
function getNames(Collection $collection) : void { | ||
foreach ($collection->list as $item) { | ||
echo $item->getName(); | ||
} | ||
} | ||
|
||
#[Param(children: 'Collection<ClassTemplateCovariantAttributeChild>')] | ||
function listChildNames(Collection $children) : void { | ||
getNames($children); | ||
} |
13 changes: 13 additions & 0 deletions
13
tests/data/TemplateCovariant/InterfaceTemplateCovariantAttribute.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,13 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PsalmPlugin\data\TemplateCovariant; | ||
|
||
use PhpStaticAnalysis\Attributes\Returns; | ||
use PhpStaticAnalysis\Attributes\TemplateCovariant; | ||
|
||
#[TemplateCovariant('T')] | ||
interface InterfaceTemplateCovariantAttribute | ||
{ | ||
#[Returns('T')] | ||
public function returnTemplateCovariant(); | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/data/TemplateCovariant/InvalidClassTemplateCovariantAttribute.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,14 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PsalmPlugin\data\TemplateCovariant; | ||
|
||
use PhpStaticAnalysis\Attributes\TemplateCovariant; | ||
|
||
#[TemplateCovariant(0)] | ||
#[TemplateCovariant('')] | ||
#[TemplateCovariant('T', 0)] | ||
class InvalidClassTemplateCovariantAttribute | ||
{ | ||
#[TemplateCovariant('T')] | ||
public string $property = ''; | ||
} |
18 changes: 18 additions & 0 deletions
18
tests/data/TemplateCovariant/TraitTemplateCovariantAttribute.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,18 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PsalmPlugin\data\TemplateCovariant; | ||
|
||
use PhpStaticAnalysis\Attributes\Param; | ||
use PhpStaticAnalysis\Attributes\Returns; | ||
use PhpStaticAnalysis\Attributes\TemplateCovariant; | ||
|
||
#[TemplateCovariant('T')] | ||
trait TraitTemplateCovariantAttribute | ||
{ | ||
#[Param(param: 'T')] | ||
#[Returns('T')] | ||
public function returnTemplateCovariant($param) | ||
{ | ||
return $param; | ||
} | ||
} |