-
-
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
69c03bb
commit 3f1c657
Showing
7 changed files
with
92 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,40 @@ | ||
<?php | ||
|
||
|
||
use test\PhpStaticAnalysis\PHPStanExtension\BaseAttributeTestCase; | ||
|
||
class ImmutableAttributeTest extends BaseAttributeTestCase | ||
{ | ||
public function testClassImmutableAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/Immutable/ClassImmutableAttribute.php'); | ||
$expectedErrors = [ | ||
]; | ||
|
||
$this->checkExpectedErrors($errors, $expectedErrors); | ||
} | ||
|
||
public function testTraitImmutableAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/Immutable/TraitImmutableAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testInterfaceImmutableAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/Immutable/InterfaceImmutableAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testInvalidClassImmutableAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/Immutable/InvalidClassImmutableAttribute.php'); | ||
|
||
$expectedErrors = [ | ||
'Attribute class PhpStaticAnalysis\Attributes\Immutable is not repeatable but is already present above the class.' => 10, | ||
'Attribute class PhpStaticAnalysis\Attributes\Immutable does not have the property target.' => 13, | ||
]; | ||
|
||
$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,14 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension\data\Immutable; | ||
|
||
use PhpStaticAnalysis\Attributes\Immutable; | ||
|
||
#[Immutable] // All properties are read only | ||
class ClassImmutableAttribute | ||
{ | ||
public string $name = ''; | ||
} | ||
|
||
$class = new ClassImmutableAttribute(); | ||
$class->name = '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,10 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension\data\Immutable; | ||
|
||
use PhpStaticAnalysis\Attributes\Immutable; | ||
|
||
#[Immutable] | ||
interface InterfaceImmutableAttribute | ||
{ | ||
} |
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,15 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension\data\Immutable; | ||
|
||
use PhpStaticAnalysis\Attributes\Immutable; | ||
use PhpStaticAnalysis\Attributes\Param; | ||
use PhpStaticAnalysis\Attributes\Returns; | ||
|
||
#[Immutable] | ||
#[Immutable] | ||
class InvalidClassImmutableAttribute | ||
{ | ||
#[Immutable] | ||
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,10 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension\data\Immutable; | ||
|
||
use PhpStaticAnalysis\Attributes\Immutable; | ||
|
||
#[Immutable] | ||
trait TraitImmutableAttribute | ||
{ | ||
} |