create(ParserFactory::PREFER_PHP7); } public function setUp() { $config = new TestConfig(); FileChecker::clearCache(); } public function testInstanceOfStringOffset() { $stmts = self::$parser->parse('foo(); } } '); $file_checker = new \Psalm\Checker\FileChecker('somefile.php', $stmts); $context = new Context('somefile.php'); $file_checker->check(true, true, $context); } public function testInstanceOfIntOffset() { $context = new Context('somefile.php'); $stmts = self::$parser->parse('foo(); } } '); $file_checker = new \Psalm\Checker\FileChecker('somefile.php', $stmts); $file_checker->check(true, true, $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 \Psalm\Checker\FileChecker('somefile.php', $stmts); $file_checker->check(true, true, $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 \Psalm\Checker\FileChecker('somefile.php', $stmts); $file_checker->check(true, true, $context); } /** * @expectedException \Psalm\Exception\CodeException * @expectedExceptionMessage InvalidArrayAccess */ public function testInvalidArrayAccess() { $context = new Context('somefile.php'); $stmts = self::$parser->parse('check(true, true, $context); } /** * @expectedException \Psalm\Exception\CodeException * @expectedExceptionMessage MixedArrayAccess */ public function testMixedArrayAccess() { $filter = new Config\FileFilter(false); $filter->addIgnoreFile('somefile.php'); Config::getInstance()->setIssueHandler('MixedAssignment', $filter); $context = new Context('somefile.php'); $stmts = self::$parser->parse('check(true, true, $context); } /** * @expectedException \Psalm\Exception\CodeException * @expectedExceptionMessage MixedArrayOffset */ public function testMixedArrayOffset() { $filter = new Config\FileFilter(false); $filter->addIgnoreFile('somefile.php'); Config::getInstance()->setIssueHandler('MixedAssignment', $filter); $context = new Context('somefile.php'); $stmts = self::$parser->parse('check(true, true, $context); } /** * @expectedException \Psalm\Exception\CodeException * @expectedExceptionMessage NullArrayAccess */ public function testNullArrayAccess() { $context = new Context('somefile.php'); $stmts = self::$parser->parse('check(true, true, $context); } }