create(ParserFactory::PREFER_PHP7); } /** * @return void */ public function setUp() { $config = new TestConfig(); FileChecker::clearCache(); $this->project_checker = new \Psalm\Checker\ProjectChecker(); } /** * @return void */ 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->visitAndAnalyzeMethods($context); } /** * @return void */ 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->visitAndAnalyzeMethods($context); } /** * @return void */ 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->visitAndAnalyzeMethods($context); } /** * @return void */ 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->visitAndAnalyzeMethods($context); } /** * @expectedException \Psalm\Exception\CodeException * @expectedExceptionMessage InvalidArrayAccess * @return void */ public function testInvalidArrayAccess() { $context = new Context('somefile.php'); $stmts = self::$parser->parse('project_checker, $stmts); $file_checker->visitAndAnalyzeMethods($context); } /** * @expectedException \Psalm\Exception\CodeException * @expectedExceptionMessage MixedArrayAccess * @return void */ public function testMixedArrayAccess() { Config::getInstance()->setCustomErrorLevel('MixedAssignment', Config::REPORT_SUPPRESS); $context = new Context('somefile.php'); $stmts = self::$parser->parse('project_checker, $stmts); $file_checker->visitAndAnalyzeMethods($context); } /** * @expectedException \Psalm\Exception\CodeException * @expectedExceptionMessage MixedArrayOffset * @return void */ public function testMixedArrayOffset() { Config::getInstance()->setCustomErrorLevel('MixedAssignment', Config::REPORT_SUPPRESS); $context = new Context('somefile.php'); $stmts = self::$parser->parse('project_checker, $stmts); $file_checker->visitAndAnalyzeMethods($context); } /** * @expectedException \Psalm\Exception\CodeException * @expectedExceptionMessage NullArrayAccess * @return void */ public function testNullArrayAccess() { $context = new Context('somefile.php'); $stmts = self::$parser->parse('project_checker, $stmts); $file_checker->visitAndAnalyzeMethods($context); } }