create(ParserFactory::PREFER_PHP7); $config = \Psalm\Config::getInstance(); $config->throw_exception = true; $config->use_docblock_types = true; } public function setUp() { \Psalm\Checker\FileChecker::clearCache(); } public function testGenerator() { $stmts = self::$_parser->parse(' */ function xrange($start, $limit, $step = 1) { for ($i = $start; $i <= $limit; $i += $step) { yield $i; } } $a = null; /* * Note that an array is never created or returned, * which saves memory. */ foreach (xrange(1, 9, 2) as $number) { $a = $number; } '); $file_checker = new \Psalm\Checker\FileChecker('somefile.php', $stmts); $context = new Context('somefile.php'); $file_checker->check(true, true, $context); $this->assertEquals('null|int', (string) $context->vars_in_scope['$a']); } public function testFinally() { $stmts = self::$_parser->parse('check(true, true, $context); } public function testForeachList() { $stmts = self::$_parser->parse('check(true, true, $context); } public function testArrayStringDereferencing() { $stmts = self::$_parser->parse('check(true, true, $context);$file_checker->check(true, true, $context); $this->assertEquals('int', (string) $context->vars_in_scope['$a']); $this->assertEquals('string', (string) $context->vars_in_scope['$b']); } public function testClassString() { $stmts = self::$_parser->parse(' '); $file_checker = new \Psalm\Checker\FileChecker('somefile.php', $stmts); $context = new Context('somefile.php'); $file_checker->check(true, true, $context); $this->assertEquals('string', (string) $context->vars_in_scope['$a']); } }