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 testFunctionTypeHints() { $stmts = self::$_parser->parse('check(true, true, $context); $this->assertEquals('int', (string) $context->vars_in_scope['$a']); } public function testMethodTypeHints() { $stmts = self::$_parser->parse('check(true, true, $context); $this->assertEquals('int', (string) $context->vars_in_scope['$a']); } public function testNullCoalesce() { $stmts = self::$_parser->parse('check(true, true, $context); $this->assertEquals('mixed', (string) $context->vars_in_scope['$a']); } public function testSpaceship() { $stmts = self::$_parser->parse(' 1; '); $file_checker = new \Psalm\Checker\FileChecker('somefile.php', $stmts); $context = new Context('somefile.php'); $file_checker->check(true, true, $context); $this->assertEquals('int', (string) $context->vars_in_scope['$a']); } public function testDefineArray() { $stmts = self::$_parser->parse('check(true, true, $context); $this->assertEquals('string', (string) $context->vars_in_scope['$a']); } public function testAnonymousClass() { $stmts = self::$_parser->parse('logger; } public function setLogger(Logger $logger) { $this->logger = $logger; } } $app = new Application; $app->setLogger(new class implements Logger { public function log(string $msg) { echo $msg; } }); '); $file_checker = new \Psalm\Checker\FileChecker('somefile.php', $stmts); $context = new Context('somefile.php'); $file_checker->check(true, true, $context); } public function testClosureCall() { $stmts = self::$_parser->parse('x;}; $getX = $getXCB->bindTo(new A, "A"); // intermediate closure $a = $getX(); // PHP 7+ code $getX = function() {return $this->x;}; $b = $getX->call(new A); '); $file_checker = new \Psalm\Checker\FileChecker('somefile.php', $stmts); $context = new Context('somefile.php'); $file_checker->check(true, true, $context); $this->assertEquals('mixed', (string) $context->vars_in_scope['$a']); $this->assertEquals('mixed', (string) $context->vars_in_scope['$b']); } public function testGeneratorDelegation() { $stmts = self::$_parser->parse('check(true, true, $context); $this->assertEquals('mixed', (string) $context->vars_in_scope['$a']); $this->assertEquals('mixed', (string) $context->vars_in_scope['$b']); } }