1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Add @psalm-property and @psalm-method override tests

This commit is contained in:
bugreportuser 2019-02-23 08:37:37 -06:00 committed by Matthew Brown
parent 68a135f434
commit 51493b552a
2 changed files with 87 additions and 0 deletions

View File

@ -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' => [

View File

@ -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);',
],
];
}