2021-10-28 10:44:37 +02:00
|
|
|
<?php
|
2021-12-15 04:58:32 +01:00
|
|
|
|
2021-10-28 10:44:37 +02:00
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
2021-12-04 21:55:53 +01:00
|
|
|
use Psalm\Tests\Traits\ValidCodeAnalysisTestTrait;
|
|
|
|
|
2021-10-28 10:44:37 +02:00
|
|
|
class ThisOutTest extends TestCase
|
|
|
|
{
|
2021-12-04 21:55:53 +01:00
|
|
|
use ValidCodeAnalysisTestTrait;
|
2021-10-28 10:44:37 +02:00
|
|
|
|
|
|
|
/**
|
2022-11-05 22:34:42 +01:00
|
|
|
*
|
2021-10-28 10:44:37 +02:00
|
|
|
*/
|
|
|
|
public function providerValidCodeParse(): iterable
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'changeInterface' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2021-10-28 10:44:37 +02:00
|
|
|
interface Foo {
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function far() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class Bar {
|
|
|
|
/**
|
|
|
|
* @psalm-this-out Foo
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function baz() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$bar = new Bar();
|
|
|
|
$bar->baz();
|
|
|
|
$bar->far();
|
|
|
|
'
|
|
|
|
],
|
|
|
|
'changeTemplateArguments' => [
|
2022-01-13 19:49:37 +01:00
|
|
|
'code' => '<?php
|
2021-10-28 10:44:37 +02:00
|
|
|
/**
|
|
|
|
* @template-covariant T as int
|
|
|
|
*/
|
|
|
|
class container {
|
|
|
|
/** @var list<T> */
|
|
|
|
public array $data;
|
|
|
|
/**
|
|
|
|
* @param T $data
|
|
|
|
*/
|
|
|
|
public function __construct($data) { $this->data = [$data]; }
|
|
|
|
/**
|
|
|
|
* @template NewT as int
|
|
|
|
* @param NewT $data
|
|
|
|
*
|
|
|
|
* @psalm-this-out self<NewT>
|
|
|
|
*/
|
|
|
|
public function setData($data): void {
|
|
|
|
$this->data = [$data];
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @template NewT as int
|
|
|
|
* @param NewT $data
|
|
|
|
*
|
|
|
|
* @psalm-this-out self<T|NewT>
|
|
|
|
*/
|
|
|
|
public function addData($data): void {
|
|
|
|
$this->data []= $data;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @return list<T>
|
|
|
|
*/
|
|
|
|
public function getData(): array { return $this->data; }
|
|
|
|
}
|
2021-12-04 21:55:53 +01:00
|
|
|
|
2021-10-28 10:44:37 +02:00
|
|
|
$a = new container(1);
|
|
|
|
$data1 = $a->getData();
|
|
|
|
$a->setData(2);
|
|
|
|
$data2 = $a->getData();
|
|
|
|
$a->addData(3);
|
|
|
|
$data3 = $a->getData();
|
|
|
|
',
|
|
|
|
'assertions' => [
|
|
|
|
'$data1===' => 'list<1>',
|
|
|
|
'$data2===' => 'list<2>',
|
|
|
|
'$data3===' => 'list<2|3>',
|
2022-12-04 18:05:36 +01:00
|
|
|
],
|
|
|
|
'ignored_issues' => [
|
|
|
|
'PropertyTypeCoercion',
|
|
|
|
'InvalidPropertyAssignmentValue'
|
2021-10-28 10:44:37 +02:00
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|