create(ParserFactory::PREFER_PHP7); } public function setUp() { $config = new TestConfig(); FileChecker::clearCache(); $this->project_checker = new \Psalm\Checker\ProjectChecker(); } public function testInstanceOfStringOffset() { $stmts = self::$parser->parse('fooFoo(); } } '); $file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts); $context = new Context('somefile.php'); $file_checker->visitAndCheckMethods($context); } public function testInstanceOfIntOffset() { $context = new Context('somefile.php'); $stmts = self::$parser->parse('fooFoo(); } } '); $file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts); $file_checker->visitAndCheckMethods($context); } public function testNotEmptyStringOffset() { $context = new Context('somefile.php'); $stmts = self::$parser->parse(' $a */ function bar (array $a) : string { if ($a["bat"]) { return $a["bat"]; } return "blah"; } '); $file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts); $file_checker->visitAndCheckMethods($context); } public function testNotEmptyIntOffset() { $context = new Context('somefile.php'); $stmts = self::$parser->parse(' $a */ function bar (array $a) : string { if ($a[0]) { return $a[0]; } return "blah"; } '); $file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts); $file_checker->visitAndCheckMethods($context); } /** * @expectedException \Psalm\Exception\CodeException * @expectedExceptionMessage InvalidArrayAccess */ public function testInvalidArrayAccess() { $context = new Context('somefile.php'); $stmts = self::$parser->parse('project_checker, $stmts); $file_checker->visitAndCheckMethods($context); } /** * @expectedException \Psalm\Exception\CodeException * @expectedExceptionMessage MixedArrayAccess */ public function testMixedArrayAccess() { Config::getInstance()->setCustomErrorLevel('MixedAssignment', Config::REPORT_SUPPRESS); $context = new Context('somefile.php'); $stmts = self::$parser->parse('project_checker, $stmts); $file_checker->visitAndCheckMethods($context); } /** * @expectedException \Psalm\Exception\CodeException * @expectedExceptionMessage MixedArrayOffset */ public function testMixedArrayOffset() { Config::getInstance()->setCustomErrorLevel('MixedAssignment', Config::REPORT_SUPPRESS); $context = new Context('somefile.php'); $stmts = self::$parser->parse('project_checker, $stmts); $file_checker->visitAndCheckMethods($context); } /** * @expectedException \Psalm\Exception\CodeException * @expectedExceptionMessage NullArrayAccess */ public function testNullArrayAccess() { $context = new Context('somefile.php'); $stmts = self::$parser->parse('project_checker, $stmts); $file_checker->visitAndCheckMethods($context); } }