mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Add @psalm-property and @psalm-method override tests
This commit is contained in:
parent
68a135f434
commit
51493b552a
@ -400,6 +400,28 @@ class MagicMethodAnnotationTest extends TestCase
|
||||
|
||||
$child = new Child();
|
||||
|
||||
$a = $child->getString();
|
||||
$child->setInteger(4);',
|
||||
'assertions' => [
|
||||
'$a' => 'string',
|
||||
],
|
||||
],
|
||||
'overrideMethodAnnotations' => [
|
||||
'<?php
|
||||
class ParentClass {
|
||||
public function __call(string $name, array $args) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* @method int getString() dsa sada
|
||||
* @method void setInteger(string $integer) dsa sada
|
||||
* @psalm-method string getString() dsa sada
|
||||
* @psalm-method void setInteger(int $integer) dsa sada
|
||||
*/
|
||||
class Child extends ParentClass {}
|
||||
|
||||
$child = new Child();
|
||||
|
||||
$a = $child->getString();
|
||||
$child->setInteger(4);',
|
||||
'assertions' => [
|
||||
|
@ -434,6 +434,71 @@ class MagicPropertyTest extends TestCase
|
||||
$a->foo = "hello";
|
||||
$a->bar = "hello"; // not a property',
|
||||
],
|
||||
'overridePropertyAnnotations' => [
|
||||
'<?php
|
||||
namespace Bar;
|
||||
|
||||
/**
|
||||
* @property int $foo
|
||||
* @psalm-property string $foo
|
||||
*/
|
||||
class A {
|
||||
/** @param string $name */
|
||||
public function __get($name): ?string {
|
||||
if ($name === "foo") {
|
||||
return "hello";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function __set($name, $value): void {
|
||||
}
|
||||
}
|
||||
|
||||
$a = new A();
|
||||
$a->foo = "hello";
|
||||
$a->bar = "hello"; // not a property',
|
||||
],
|
||||
'overrideWithReadWritePropertyAnnotations' => [
|
||||
'<?php
|
||||
namespace Bar;
|
||||
|
||||
/**
|
||||
* @psalm-property int $foo
|
||||
* @property-read string $foo
|
||||
* @property-write array $foo
|
||||
*/
|
||||
class A {
|
||||
/** @param string $name */
|
||||
public function __get($name): ?string {
|
||||
if ($name === "foo") {
|
||||
return "hello";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function __set($name, $value): void {
|
||||
}
|
||||
|
||||
public function takesString(string $s): void {}
|
||||
}
|
||||
|
||||
$a = new A();
|
||||
$a->foo = [];
|
||||
|
||||
$a = new A();
|
||||
$a->takesString($a->foo);',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user