mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Add tests for elseif reconciliation
This commit is contained in:
parent
936630892e
commit
e14cadd32e
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Psalm\Tests;
|
||||
|
||||
use Psalm\Context;
|
||||
use Psalm\Type;
|
||||
|
||||
use PhpParser;
|
||||
@ -51,4 +52,59 @@ class PropertyTypeTest extends PHPUnit_Framework_TestCase
|
||||
$file_checker = new \Psalm\Checker\FileChecker('somefile.php', $stmts);
|
||||
$file_checker->check();
|
||||
}
|
||||
|
||||
public function testSharedPropertyInIf()
|
||||
{
|
||||
$stmts = self::$_parser->parse('<?php
|
||||
class A {
|
||||
/** @var int */
|
||||
public $foo;
|
||||
}
|
||||
class B {
|
||||
/** @var string */
|
||||
public $foo;
|
||||
}
|
||||
|
||||
$a = null;
|
||||
$b = null;
|
||||
|
||||
if ($a instanceof A || $a instanceof B) {
|
||||
$b = $a->foo;
|
||||
}
|
||||
');
|
||||
|
||||
$file_checker = new \Psalm\Checker\FileChecker('somefile.php', $stmts);
|
||||
$context = new Context('somefile.php');
|
||||
$file_checker->check(true, true, $context);
|
||||
$this->assertEquals('null|string|int', (string) $context->vars_in_scope['b']);
|
||||
}
|
||||
|
||||
public function testSharedPropertyInElseIf()
|
||||
{
|
||||
$stmts = self::$_parser->parse('<?php
|
||||
class A {
|
||||
/** @var int */
|
||||
public $foo;
|
||||
}
|
||||
class B {
|
||||
/** @var string */
|
||||
public $foo;
|
||||
}
|
||||
|
||||
$a = null;
|
||||
$b = null;
|
||||
|
||||
if (rand(0, 10) === 4) {
|
||||
// do nothing
|
||||
}
|
||||
elseif ($a instanceof A || $a instanceof B) {
|
||||
$b = $a->foo;
|
||||
}
|
||||
');
|
||||
|
||||
$file_checker = new \Psalm\Checker\FileChecker('somefile.php', $stmts);
|
||||
$context = new Context('somefile.php');
|
||||
$file_checker->check(true, true, $context);
|
||||
$this->assertEquals('null|string|int', (string) $context->vars_in_scope['b']);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user