create(ParserFactory::PREFER_PHP7); $config = \Psalm\Config::getInstance(); $config->throw_exception = true; self::$_file_filter = $filter; } public function setUp() { \Psalm\Checker\FileChecker::clearCache(); } /** * @expectedException Psalm\Exception\CodeException * @expectedExceptionMessage PossiblyUndefinedVariable - somefile.php:6 - Possibly undefined variable $b, first seen on line 3 */ public function testPossiblyUndefinedVarInIf() { $stmts = self::$_parser->parse('check(); } public function testNewVarInIf() { $stmts = self::$_parser->parse('check(); } public function testNewVarInIfWithElseReturn() { $stmts = self::$_parser->parse('check(); } /** * @expectedException Psalm\Exception\CodeException * @expectedExceptionMessage PossiblyUndefinedVariable - somefile.php:3 - Possibly undefined variable $array, first seen on line 3 */ public function testPossiblyUndefinedArrayInIf() { $stmts = self::$_parser->parse('check(); } /** * @expectedException Psalm\Exception\CodeException * @expectedExceptionMessage PossiblyUndefinedVariable - somefile.php:3 - Possibly undefined variable $array, first seen on line 3 */ public function testPossiblyUndefinedArrayInForeach() { $stmts = self::$_parser->parse('check(); } /** * @expectedException Psalm\Exception\CodeException * @expectedExceptionMessage PossiblyUndefinedVariable - somefile.php:4 - Possibly undefined variable $array, first seen on line 4 */ public function testPossiblyUndefinedArrayInWhileAndForeach() { $stmts = self::$_parser->parse('setIssueHandler('PossiblyUndefinedVariable', self::$_file_filter); $file_checker = new \Psalm\Checker\FileChecker('somefile.php', $stmts); $file_checker->check(); } /** * @expectedException Psalm\Exception\CodeException * @expectedExceptionMessage PossiblyUndefinedVariable - somefile.php:6 - Possibly undefined variable $car, first seen on line 3 */ public function testPossiblyUndefinedVariableInForeach() { $stmts = self::$_parser->parse('check(); } public function testSwitchVariableWithContinue() { $stmts = self::$_parser->parse('check(); } public function testSwitchVariableWithContinueAndIfs() { $stmts = self::$_parser->parse('check(); } public function testSwitchVariableWithFallthrough() { $stmts = self::$_parser->parse('check(); } public function testSwitchVariableWithFallthroughStatement() { $stmts = self::$_parser->parse('check(); } public function testTryCatchVar() { $stmts = self::$_parser->parse('check(); $conditional = $stmts[1]->cond; $this->assertSame('bool', (string) $conditional->inferredType); } public function testWhileVar() { $stmts = self::$_parser->parse('check(); $conditional = $stmts[2]->cond; $this->assertSame('bool', (string) $conditional->inferredType); } public function testDoWhileVar() { $stmts = self::$_parser->parse('check(); $conditional = $stmts[2]->cond; $this->assertSame('bool', (string) $conditional->inferredType); } public function testAssignmentInIf() { $stmts = self::$_parser->parse('check(); } public function testPassByRefInIf() { $stmts = self::$_parser->parse('check(); } public function testPassByRefInIfCheckAfter() { $stmts = self::$_parser->parse('check(); } public function testPassByRefInIfWithBoolean() { $stmts = self::$_parser->parse('check(); } /** * @expectedException Psalm\Exception\CodeException * @expectedExceptionMessage PossiblyUndefinedVariable - somefile.php:9 - Possibly undefined variable $a, first seen on line 4 */ public function testPossiblyUndefinedVariableInForeachAndIf() { $stmts = self::$_parser->parse('setIssueHandler('PossiblyUndefinedVariable', self::$_file_filter); $file_checker = new \Psalm\Checker\FileChecker('somefile.php', $stmts); $file_checker->check(); } public function testFunctionExists() { $stmts = self::$_parser->parse('check(); } public function testNestedPropertyFetchInElseif() { $stmts = self::$_parser->parse('foo) { echo $a; } '); $file_checker = new \Psalm\Checker\FileChecker('somefile.php', $stmts); $file_checker->check(); } }