create(ParserFactory::PREFER_PHP7); $config = Config::getInstance(); $config->throw_exception = true; self::$file_filter = null; } public function setUp() { 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 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 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 FileChecker('somefile.php', $stmts); $file_checker->check(); } public function testGlobalReturn() { $stmts = self::$parser->parse('check(); } public function testStatic() { $stmts = self::$parser->parse('check(); } }