From 88081d61b3736cb0a160a45445b76e9500a79913 Mon Sep 17 00:00:00 2001 From: Olle Date: Sun, 12 Jul 2020 20:06:03 +0000 Subject: [PATCH] Add more tests (interface contained by still faulty) --- tests/IfThisIsTest.php | 138 +++++++++++++++++++++++++++++++++++------ 1 file changed, 120 insertions(+), 18 deletions(-) diff --git a/tests/IfThisIsTest.php b/tests/IfThisIsTest.php index adeb30012..4316021f2 100644 --- a/tests/IfThisIsTest.php +++ b/tests/IfThisIsTest.php @@ -27,23 +27,86 @@ class IfThisIsTest extends TestCase * @psalm-self-out I * @return void */ - public function convert() - { - } + public function convert() {} /** * @psalm-if-this-is I * @return void */ - public function test() - { - } + public function test() {} } $f = new F(); $f->convert(); $f->test(); ' + ], + 'withTemplate' => [ + 'state = $state; + } + + /** + * @param string $name + * @param mixed $val + * @psalm-if-this-is Foo + * @return void + */ + public function set($name, $val) + { + } + + /** + * @return Foo + */ + public function freeze() + { + /** @var Foo */ + $f = clone $this; + return $f; + } + } + + $f = new Foo(new Unfrozen()); + $f->set("asd", 10); + ' + ], + 'subclass' => [ + 'test(); + ' ] ]; } @@ -65,28 +128,67 @@ class IfThisIsTest extends TestCase class F implements I { - /** - * @psalm-self-out I - * @return void - */ - public function convert() - { - } - /** * @psalm-if-this-is I * @return void */ - public function test() - { - } + public function test() {} } $f = new F(); $f->test(); ', 'error_message' => 'IfThisIsMismatch' - ] + ], + 'failsWithWrongTemplate' => [ + 'state = $state; + } + + /** + * @param string $name + * @param mixed $val + * @psalm-if-this-is Foo + * @return void + */ + public function set($name, $val) {} + + /** + * @return Foo + */ + public function freeze() + { + /** @var Foo */ + $f = clone $this; + return $f; + } + } + + $f = new Foo(new Unfrozen()); + $f->set("asd", 10); + $g = $f->freeze(); + $g->set("asd", 20); // Fails + ', + 'error_message' => 'IfThisIsMismatch' + ], ]; } }