2018-12-02 00:37:49 +01:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
|
|
|
class DeprecatedAnnotationTest extends TestCase
|
|
|
|
{
|
|
|
|
use Traits\InvalidCodeAnalysisTestTrait;
|
|
|
|
use Traits\ValidCodeAnalysisTestTrait;
|
|
|
|
|
|
|
|
/**
|
2019-03-01 21:55:20 +01:00
|
|
|
* @return iterable<string,array{string,assertions?:array<string,string>,error_levels?:string[]}>
|
2018-12-02 00:37:49 +01:00
|
|
|
*/
|
|
|
|
public function providerValidCodeParse()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'deprecatedMethod' => [
|
|
|
|
'<?php
|
|
|
|
class Foo {
|
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
*/
|
|
|
|
public static function barBar(): void {
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
2019-06-27 19:36:39 +02:00
|
|
|
'deprecatedClassUsedInsideClass' => [
|
|
|
|
'<?php
|
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
*/
|
|
|
|
class Foo {
|
|
|
|
public static function barBar(): void {
|
|
|
|
new Foo();
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
],
|
2019-08-21 17:25:08 +02:00
|
|
|
'annotationOnStatement' => [
|
|
|
|
'<?php
|
|
|
|
/** @deprecated */
|
|
|
|
$a = "A";'
|
|
|
|
],
|
2018-12-02 00:37:49 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-01 21:55:20 +01:00
|
|
|
* @return iterable<string,array{string,error_message:string,2?:string[],3?:bool,4?:string}>
|
2018-12-02 00:37:49 +01:00
|
|
|
*/
|
|
|
|
public function providerInvalidCodeParse()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'deprecatedMethodWithCall' => [
|
|
|
|
'<?php
|
|
|
|
class Foo {
|
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
*/
|
|
|
|
public static function barBar(): void {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Foo::barBar();',
|
|
|
|
'error_message' => 'DeprecatedMethod',
|
|
|
|
],
|
|
|
|
'deprecatedClassWithStaticCall' => [
|
|
|
|
'<?php
|
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
*/
|
|
|
|
class Foo {
|
|
|
|
public static function barBar(): void {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Foo::barBar();',
|
|
|
|
'error_message' => 'DeprecatedClass',
|
|
|
|
],
|
|
|
|
'deprecatedClassWithNew' => [
|
|
|
|
'<?php
|
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
*/
|
|
|
|
class Foo { }
|
|
|
|
|
|
|
|
$a = new Foo();',
|
|
|
|
'error_message' => 'DeprecatedClass',
|
|
|
|
],
|
|
|
|
'deprecatedClassWithExtends' => [
|
|
|
|
'<?php
|
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
*/
|
|
|
|
class Foo { }
|
|
|
|
|
|
|
|
class Bar extends Foo {}',
|
|
|
|
'error_message' => 'DeprecatedClass',
|
|
|
|
],
|
|
|
|
'deprecatedPropertyGet' => [
|
|
|
|
'<?php
|
|
|
|
class A{
|
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
* @var ?int
|
|
|
|
*/
|
|
|
|
public $foo;
|
|
|
|
}
|
|
|
|
echo (new A)->foo;',
|
|
|
|
'error_message' => 'DeprecatedProperty',
|
|
|
|
],
|
|
|
|
'deprecatedPropertySet' => [
|
|
|
|
'<?php
|
|
|
|
class A{
|
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
* @var ?int
|
|
|
|
*/
|
|
|
|
public $foo;
|
|
|
|
}
|
|
|
|
$a = new A;
|
|
|
|
$a->foo = 5;',
|
|
|
|
'error_message' => 'DeprecatedProperty',
|
|
|
|
],
|
2019-06-18 22:21:04 +02:00
|
|
|
'deprecatedClassConstant' => [
|
|
|
|
'<?php
|
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
*/
|
|
|
|
class Foo {
|
|
|
|
public const FOO = 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
echo Foo::FOO;',
|
|
|
|
'error_message' => 'DeprecatedClass',
|
2019-06-19 18:42:51 +02:00
|
|
|
],
|
|
|
|
'deprecatedClassStringConstant' => [
|
|
|
|
'<?php
|
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
*/
|
|
|
|
class Foo {}
|
|
|
|
|
|
|
|
echo Foo::class;',
|
|
|
|
'error_message' => 'DeprecatedClass',
|
2019-07-05 22:24:00 +02:00
|
|
|
],
|
2019-08-22 17:21:31 +02:00
|
|
|
'deprecatedClassAsParam' => [
|
|
|
|
'<?php
|
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
*/
|
|
|
|
class DeprecatedClass{}
|
|
|
|
|
|
|
|
function foo(DeprecatedClass $deprecatedClass): void {}',
|
|
|
|
'error_message' => 'DeprecatedClass',
|
|
|
|
],
|
2018-12-02 00:37:49 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|