-
-
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
56df0e9
commit e2bcf3a
Showing
11 changed files
with
188 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,72 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension; | ||
|
||
class DeprecatedAttributeTest extends BaseAttributeTestCase | ||
{ | ||
public function testClassDeprecatedAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/Deprecated/ClassDeprecatedAttribute.php'); | ||
$expectedErrors = [ | ||
'Instantiation of deprecated class test\PhpStaticAnalysis\PHPStanExtension\data\Deprecated\ClassDeprecatedAttribute.' => 12, | ||
]; | ||
|
||
$this->checkExpectedErrors($errors, $expectedErrors); | ||
} | ||
|
||
public function testTraitDeprecatedAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/Deprecated/TraitDeprecatedAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testInterfaceDeprecatedAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/Deprecated/InterfaceDeprecatedAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testMethodDeprecatedAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/Deprecated/MethodDeprecatedAttribute.php'); | ||
$expectedErrors = [ | ||
'Call to deprecated method returnDeprecated() of class test\PhpStaticAnalysis\PHPStanExtension\data\Deprecated\MethodDeprecatedAttribute.' => 31, | ||
]; | ||
|
||
$this->checkExpectedErrors($errors, $expectedErrors); | ||
} | ||
|
||
public function testFunctionDeprecatedAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/Deprecated/FunctionDeprecatedAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testProperyDeprecatedAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/Deprecated/PropertyDeprecatedAttribute.php'); | ||
$this->assertCount(0, $errors); | ||
} | ||
|
||
public function testInvalidMethodDeprecatedAttribute(): void | ||
{ | ||
$errors = $this->analyse(__DIR__ . '/data/Deprecated/InvalidMethodDeprecatedAttribute.php'); | ||
|
||
$expectedErrors = [ | ||
'Attribute class PhpStaticAnalysis\Attributes\Deprecated does not have the parameter target.' => 12, | ||
'Attribute class PhpStaticAnalysis\Attributes\Deprecated is not repeatable but is already present above the method.' => 19, | ||
]; | ||
|
||
$this->checkExpectedErrors($errors, $expectedErrors); | ||
} | ||
|
||
public static function getAdditionalConfigFiles(): array | ||
{ | ||
return array_merge( | ||
parent::getAdditionalConfigFiles(), | ||
[ | ||
__DIR__ . '/conf/deprecated.neon', | ||
] | ||
); | ||
} | ||
} |
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,2 @@ | ||
includes: | ||
- ../../vendor/phpstan/phpstan-deprecation-rules/rules.neon |
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,12 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension\data\Deprecated; | ||
|
||
use PhpStaticAnalysis\Attributes\Deprecated; | ||
|
||
#[Deprecated] // Use NotDeprecatedClassInstead | ||
class ClassDeprecatedAttribute | ||
{ | ||
} | ||
|
||
$class = new ClassDeprecatedAttribute(); |
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; | ||
|
||
use PhpStaticAnalysis\Attributes\Deprecated; | ||
|
||
#[Deprecated] | ||
function returnDeprecated(): void | ||
{ | ||
} |
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\Deprecated; | ||
|
||
use PhpStaticAnalysis\Attributes\Deprecated; | ||
|
||
#[Deprecated] | ||
interface InterfaceDeprecatedAttribute | ||
{ | ||
} |
23 changes: 23 additions & 0 deletions
23
tests/data/Deprecated/InvalidMethodDeprecatedAttribute.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\PHPStanExtension\data\Deprecated; | ||
|
||
use PhpStaticAnalysis\Attributes\Deprecated; | ||
use PhpStaticAnalysis\Attributes\Param; | ||
use PhpStaticAnalysis\Attributes\Returns; | ||
|
||
class InvalidMethodDeprecatedAttribute | ||
{ | ||
public function getName( | ||
#[Deprecated] | ||
string $name | ||
): string { | ||
return $name; | ||
} | ||
|
||
#[Deprecated] | ||
#[Deprecated] | ||
public function getMoreName(): void | ||
{ | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
namespace test\PhpStaticAnalysis\PHPStanExtension\data\Deprecated; | ||
|
||
use PhpStaticAnalysis\Attributes\Deprecated; | ||
|
||
class MethodDeprecatedAttribute | ||
{ | ||
#[Deprecated] | ||
public function returnDeprecated(): void | ||
{ | ||
} | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
#[Deprecated] | ||
public function returnAnotherDeprecated(): void | ||
{ | ||
} | ||
|
||
/** | ||
* @deprecated | ||
*/ | ||
public function returnMoreDeprecateds(): void | ||
{ | ||
} | ||
} | ||
|
||
$class = new MethodDeprecatedAttribute(); | ||
$class->returnDeprecated(); |
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\Deprecated; | ||
|
||
use PhpStaticAnalysis\Attributes\Deprecated; | ||
|
||
class PropertyDeprecatedAttribute | ||
{ | ||
#[Deprecated] | ||
public const NAME = 'name'; | ||
|
||
#[Deprecated] | ||
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\Deprecated; | ||
|
||
use PhpStaticAnalysis\Attributes\Deprecated; | ||
|
||
#[Deprecated] | ||
trait TraitDeprecatedAttribute | ||
{ | ||
} |