-
-
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
bc2e06a
commit 3394d5d
Showing
5 changed files
with
105 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,26 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension; | ||
|
||
class SelfOutAttributeTest extends BaseAttributeTestCase | ||
{ | ||
public function testMethodSelfOutAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/SelfOut/MethodSelfOutAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testInvalidMethodSelfOutAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/SelfOut/InvalidMethodSelfOutAttribute.php'); | ||
|
||
$expectedErrors = [ | ||
'PHPDoc tag @phpstan-self-out has invalid value (): Unexpected token "\n ", expected type at offset 75' => 12, | ||
'Parameter #1 $type of attribute class PhpStaticAnalysis\Attributes\SelfOut constructor expects string, int given.' => 14, | ||
'Attribute class PhpStaticAnalysis\Attributes\SelfOut is not repeatable but is already present above the method.' => 22, | ||
'Attribute class PhpStaticAnalysis\Attributes\SelfOut does not have the property target.' => 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,29 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension\data\SelfOut; | ||
|
||
use PhpStaticAnalysis\Attributes\Param; | ||
use PhpStaticAnalysis\Attributes\SelfOut; | ||
use PhpStaticAnalysis\Attributes\Template; | ||
|
||
#[Template('TValue')] | ||
class InvalidMethodSelfOutAttribute | ||
{ | ||
#[Template('TItemValue')] | ||
#[Param(item: 'TItemValue')] | ||
#[SelfOut(0)] | ||
public function add($item): void | ||
{ | ||
} | ||
|
||
#[Template('TItemValue')] | ||
#[Param(item: 'TItemValue')] | ||
#[SelfOut('self<TValue|TItemValue>')] | ||
#[SelfOut('self<TValue|TItemValue>')] | ||
public function addMore($item): void | ||
{ | ||
} | ||
|
||
#[SelfOut('self<TValue|TItemValue>')] | ||
public string $property; | ||
} |
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,47 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension\data\SelfOut; | ||
|
||
use PhpStaticAnalysis\Attributes\Param; | ||
use PhpStaticAnalysis\Attributes\SelfOut; | ||
use PhpStaticAnalysis\Attributes\Template; | ||
|
||
#[Template('TValue')] | ||
class MethodSelfOutAttribute | ||
{ | ||
#[Template('TItemValue')] | ||
#[Param(item: 'TItemValue')] | ||
#[SelfOut('self<TValue|TItemValue>')] // we specify the new type | ||
public function add($item): void | ||
{ | ||
} | ||
|
||
/** | ||
* @deprecated | ||
*/ | ||
#[Template('TItemValue')] | ||
#[Param(item: 'TItemValue')] | ||
#[SelfOut('self<TValue|TItemValue>')] | ||
public function addMore($item): void | ||
{ | ||
} | ||
|
||
/** | ||
* @self-out self<TValue> | ||
*/ | ||
#[Template('TItemValue')] | ||
#[Param(item: 'TItemValue')] | ||
#[SelfOut('self<TValue|TItemValue>')] | ||
public function addEvenMore($item): void | ||
{ | ||
} | ||
|
||
/** | ||
* @self-out self<TValue|TItemValue> | ||
*/ | ||
#[Template('TItemValue')] | ||
#[Param(item: 'TItemValue')] | ||
public function addMoreAndMore($item): void | ||
{ | ||
} | ||
} |