project_checker = new \Psalm\Checker\ProjectChecker(); } /** * @return string[] * @psalm-return array */ public static function getAllIssues() { return array_filter( array_map( /** * @param string $file_name * @return string */ function ($file_name) { return substr($file_name, 0, -4); }, scandir(dirname(__DIR__) . '/src/Psalm/Issue') ), /** * @param string $issue_name * @return bool */ function ($issue_name) { return !empty($issue_name) && $issue_name !== 'CodeError' && $issue_name !== 'CodeIssue'; } ); } /** * @return void */ public function testBarebonesConfig() { $config = Config::loadFromXML('psalm.xml', ' '); $this->assertTrue($config->isInProjectDirs(realpath('src/Psalm/Type.php'))); $this->assertFalse($config->isInProjectDirs(realpath('examples/StringChecker.php'))); } /** * @return void */ public function testIgnoreProjectDirectory() { $config = Config::loadFromXML('psalm.xml', ' '); $this->assertTrue($config->isInProjectDirs(realpath('src/Psalm/Type.php'))); $this->assertFalse($config->isInProjectDirs(realpath('src/Psalm/Checker/FileChecker.php'))); $this->assertFalse($config->isInProjectDirs(realpath('examples/StringChecker.php'))); } /** * @return void */ public function testIssueHandler() { $config = Config::loadFromXML('psalm.xml', ' '); $this->assertTrue($config->excludeIssueInFile('MissingReturnType', realpath('tests/ConfigTest.php'))); $this->assertTrue($config->excludeIssueInFile('MissingReturnType', realpath('src/Psalm/Type.php'))); } /** * @return void */ public function testIssueHandlerWithCustomErrorLevels() { $config = Config::loadFromXML('psalm.xml', ' '); $this->assertTrue($config->excludeIssueInFile('MissingReturnType', realpath('tests/ConfigTest.php'))); $this->assertFalse($config->excludeIssueInFile('MissingReturnType', realpath('src/Psalm/Type.php'))); $this->assertFalse($config->excludeIssueInFile('MissingReturnType', realpath('src/Psalm/Checker/FileChecker.php'))); $this->assertSame('info', $config->getReportingLevelForFile('MissingReturnType', realpath('src/Psalm/Type.php'))); $this->assertSame('error', $config->getReportingLevelForFile('MissingReturnType', realpath('src/Psalm/Checker/FileChecker.php'))); } /** * @return void */ public function testAllPossibleIssues() { $all_possible_handlers = implode( ' ', array_map( /** * @param string $issue_name * @return string */ function ($issue_name) { return '<' . $issue_name . ' errorLevel="suppress" />' . PHP_EOL; }, self::getAllIssues() ) ); $config = Config::loadFromXML('psalm.xml', ' ' . $all_possible_handlers . ' '); } /** * @expectedException \Psalm\Exception\ConfigException * @expectedExceptionMessage This element is not expected * @return void */ public function testImpossibleIssue() { $config = Config::loadFromXML('psalm.xml', ' '); } }