2021-01-31 17:32:24 +01:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
|
|
|
class PropertyTypeInvariance extends TestCase
|
|
|
|
{
|
|
|
|
use Traits\InvalidCodeAnalysisTestTrait;
|
|
|
|
use Traits\ValidCodeAnalysisTestTrait;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return iterable<string,array{string,assertions?:array<string,string>,error_levels?:string[]}>
|
|
|
|
*/
|
|
|
|
public function providerValidCodeParse(): iterable
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'validcode' =>
|
|
|
|
['<?php
|
|
|
|
|
|
|
|
class ParentClass
|
|
|
|
{
|
|
|
|
/** @var null|string */
|
|
|
|
protected $mightExist;
|
|
|
|
|
|
|
|
protected ?string $mightExistNative = null;
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
protected $doesExist = "";
|
|
|
|
|
|
|
|
protected string $doesExistNative = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
class ChildClass extends ParentClass
|
|
|
|
{
|
|
|
|
/** @var null|string */
|
|
|
|
protected $mightExist = "";
|
|
|
|
|
|
|
|
protected ?string $mightExistNative = null;
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
protected $doesExist = "";
|
|
|
|
|
|
|
|
protected string $doesExistNative = "";
|
|
|
|
}
|
|
|
|
'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return iterable<string,array{string,error_message:string,2?:string[],3?:bool,4?:string}>
|
|
|
|
*/
|
|
|
|
public function providerInvalidCodeParse(): iterable
|
|
|
|
{
|
|
|
|
return [
|
2021-02-07 06:52:29 +01:00
|
|
|
'variantDocblockProperties' => [
|
|
|
|
'<?php
|
|
|
|
class ParentClass
|
|
|
|
{
|
|
|
|
/** @var null|string */
|
|
|
|
protected $mightExist;
|
|
|
|
}
|
|
|
|
|
|
|
|
class ChildClass extends ParentClass
|
|
|
|
{
|
|
|
|
/** @var string */
|
|
|
|
protected $mightExist = "";
|
|
|
|
}',
|
|
|
|
'error_message' => 'NonInvariantDocblockPropertyType',
|
|
|
|
],
|
2021-01-31 17:32:24 +01:00
|
|
|
'variantProperties' => [
|
2021-02-07 06:52:29 +01:00
|
|
|
'<?php
|
|
|
|
class ParentClass
|
|
|
|
{
|
|
|
|
protected ?string $mightExist = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
class ChildClass extends ParentClass
|
|
|
|
{
|
|
|
|
protected string $mightExist = "";
|
|
|
|
}',
|
2021-01-31 17:32:24 +01:00
|
|
|
'error_message' => 'NonInvariantPropertyType',
|
2021-02-07 06:52:29 +01:00
|
|
|
],
|
2021-01-31 17:32:24 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|