create(ParserFactory::PREFER_PHP7); } /** * @return void */ public function setUp() { FileChecker::clearCache(); $this->project_checker = new \Psalm\Checker\ProjectChecker(); $this->project_checker->setConfig(new TestConfig()); } /** * @return void */ public function testIsset() { Config::getInstance()->setCustomErrorLevel('MixedAssignment', Config::REPORT_SUPPRESS); $file_checker = new FileChecker( 'somefile.php', $this->project_checker, self::$parser->parse('vars_in_scope['$foo'] = \Psalm\Type::getArray(); $file_checker->visitAndAnalyzeMethods($context); $this->assertEquals('mixed', (string) $context->vars_in_scope['$a']); } /** * @return void */ public function testNullCoalesce() { Config::getInstance()->setCustomErrorLevel('MixedAssignment', Config::REPORT_SUPPRESS); $file_checker = new FileChecker( 'somefile.php', $this->project_checker, self::$parser->parse('vars_in_scope['$foo'] = \Psalm\Type::getArray(); $file_checker->visitAndAnalyzeMethods($context); $this->assertEquals('mixed', (string) $context->vars_in_scope['$a']); } /** * @return void */ public function testNullCoalesceWithGoodVariable() { $file_checker = new FileChecker( 'somefile.php', $this->project_checker, self::$parser->parse('vars_in_scope['$foo'] = \Psalm\Type::getArray(); $file_checker->visitAndAnalyzeMethods($context); $this->assertEquals('false|null', (string) $context->vars_in_scope['$a']); } /** * @return void */ public function testIssetKeyedOffset() { $file_checker = new FileChecker( 'somefile.php', $this->project_checker, self::$parser->parse('vars_in_scope['$foo'] = \Psalm\Type::getArray(); $file_checker->visitAndAnalyzeMethods($context); $this->assertEquals('mixed', (string) $context->vars_in_scope['$foo[\'a\']']); } /** * @return void */ public function testNullCoalesceKeyedOffset() { Config::getInstance()->setCustomErrorLevel('MixedAssignment', Config::REPORT_SUPPRESS); $file_checker = new FileChecker( 'somefile.php', $this->project_checker, self::$parser->parse('vars_in_scope['$foo'] = \Psalm\Type::getArray(); $file_checker->visitAndAnalyzeMethods($context); $this->assertEquals('mixed', (string) $context->vars_in_scope['$foo[\'a\']']); } }