1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00
psalm/tests/UnsupportedPropertyReferenceUsage.php

78 lines
2.2 KiB
PHP
Raw Normal View History

2023-05-10 15:43:22 +02:00
<?php
declare(strict_types=1);
namespace Psalm\Tests;
use Psalm\Tests\Traits\InvalidCodeAnalysisTestTrait;
2023-05-26 23:52:09 +02:00
use Psalm\Tests\Traits\ValidCodeAnalysisTestTrait;
2023-05-10 15:43:22 +02:00
class UnsupportedPropertyReferenceUsage extends TestCase
{
2023-05-26 23:52:09 +02:00
use ValidCodeAnalysisTestTrait;
2023-05-10 15:43:22 +02:00
use InvalidCodeAnalysisTestTrait;
2023-05-26 23:52:09 +02:00
public function providerValidCodeParse(): iterable
{
return [
'can be suppressed' => [
'code' => <<<'PHP'
<?php
class A {
public int $b = 0;
}
$a = new A();
/** @psalm-suppress UnsupportedPropertyReferenceUsage */
$b = &$a->b;
PHP,
],
];
}
2023-05-10 15:43:22 +02:00
public function providerInvalidCodeParse(): iterable
{
return [
'instance property' => [
'code' => <<<'PHP'
<?php
class A {
public int $b = 0;
}
$a = new A();
$b = &$a->b;
$b = ''; // Fatal error
PHP,
'error_message' => 'UnsupportedPropertyReferenceUsage',
],
'static property' => [
'code' => <<<'PHP'
<?php
class A {
public static int $b = 0;
}
$b = &A::$b;
$b = ''; // Fatal error
PHP,
'error_message' => 'UnsupportedPropertyReferenceUsage',
],
'readonly property' => [
'code' => <<<'PHP'
<?php
class A {
public function __construct(
public readonly int $b,
) {
}
}
$a = new A(0);
$b = &$a->b;
$b = 1; // Fatal error
PHP,
'error_message' => 'UnsupportedPropertyReferenceUsage',
'error_levels' => [],
'php_version' => '8.1',
],
];
}
}