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
29992c6
commit 2c65f4e
Showing
7 changed files
with
116 additions
and
26 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,41 @@ | ||
<?php | ||
|
||
|
||
namespace test\PhpStaticAnalysis\PsalmPlugin; | ||
|
||
class ImmutableAttributeTest extends BaseAttributeTestCase | ||
{ | ||
public function testClassImmutableAttribute(): void | ||
{ | ||
$errors = $this->analyzeTestFile( '/data/Immutable/ClassImmutableAttribute.php'); | ||
$expectedErrors = [ | ||
'test\PhpStaticAnalysis\PsalmPlugin\data\Immutable\ClassImmutableAttribute::$name is marked readonly' => 14, | ||
]; | ||
|
||
$this->checkExpectedErrors($errors, $expectedErrors); | ||
} | ||
|
||
public function testTraitImmutableAttribute(): void | ||
{ | ||
$errors = $this->analyzeTestFile( '/data/Immutable/TraitImmutableAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testInterfaceImmutableAttribute(): void | ||
{ | ||
$errors = $this->analyzeTestFile( '/data/Immutable/InterfaceImmutableAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testInvalidClassImmutableAttribute(): void | ||
{ | ||
$errors = $this->analyzeTestFile( '/data/Immutable/InvalidClassImmutableAttribute.php'); | ||
|
||
$expectedErrors = [ | ||
'Attribute Immutable is not repeatable' => 10, | ||
'Attribute Immutable cannot be used on a property' => 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\PsalmPlugin\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\PsalmPlugin\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\PsalmPlugin\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\PsalmPlugin\data\Immutable; | ||
|
||
use PhpStaticAnalysis\Attributes\Immutable; | ||
|
||
#[Immutable] | ||
trait TraitImmutableAttribute | ||
{ | ||
} |