file_provider = new Provider\FakeFileProvider(); $this->project_checker = new \Psalm\Checker\ProjectChecker( $this->file_provider, new Provider\FakeCacheProvider() ); $this->project_checker->setConfig(Config::loadFromXML( 'psalm.xml', dirname(__DIR__), ' ' )); $this->project_checker->collect_references = true; } /** * @dataProvider providerTestUnusedCodeWithClassReferences * * @param string $code * @param string $error_message * * @return void */ public function testUnusedCodeWithClassReferences($code, $error_message) { $this->expectException('\Psalm\Exception\CodeException'); $this->expectExceptionMessage($error_message); $this->addFile( self::$project_dir . 'somefile.php', $code ); $file_checker = new FileChecker(self::$project_dir . 'somefile.php', $this->project_checker); $file_checker->visitAndAnalyzeMethods(); $this->project_checker->checkClassReferences(); } /** * @return array */ public function providerFileCheckerValidCodeParse() { return [ 'unset' => [ ' [ ' 'UnusedVariable', ], 'ifInFunction' => [ ' 'UnusedVariable', ], ]; } /** * @return array */ public function providerTestUnusedCodeWithClassReferences() { return [ 'unusedClass' => [ ' 'UnusedClass', ], 'publicUnusedMethod' => [ ' 'PossiblyUnusedMethod', ], 'privateUnusedMethod' => [ ' 'UnusedMethod', ], ]; } }