create(ParserFactory::PREFER_PHP7); $config = Config::getInstance(); $config->throw_exception = true; } public function setUp() { FileChecker::clearCache(); } public function testNewVarInIf() { $stmts = self::$parser->parse('foo = []; } if (!is_array($this->foo)) { // do something } } } '); $file_checker = new FileChecker('somefile.php', $stmts); $file_checker->check(); } public function testSharedPropertyInIf() { $stmts = self::$parser->parse('foo; } '); $file_checker = new 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('foo; } '); $file_checker = new 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']); } }