/** * Run the PSR2 code sniffs on the code * * @TODO: combine with testCodeStyle * @return void */ public function testCodeStylePsr2() { $reportFile = self::$reportDir . '/phpcs_psr2_report.xml'; $wrapper = new Wrapper(); $codeSniffer = new CodeSniffer('PSR2', $reportFile, $wrapper); if (!$codeSniffer->canRun()) { $this->markTestSkipped('PHP Code Sniffer is not installed.'); } if (version_compare($wrapper->version(), '1.4.7') === -1) { $this->markTestSkipped('PHP Code Sniffer Build Too Old.'); } self::setupFileLists('phpcs'); $result = $codeSniffer->run(self::$whiteList, self::$blackList, ['php']); $this->assertFileExists($reportFile, 'Expected ' . $reportFile . ' to be created by phpcs run with PSR2 standard'); $this->assertEquals(0, $result, "PHP Code Sniffer has found {$result} error(s): See detailed report in {$reportFile}"); }
/** * {@inheritdoc} */ public function run(array $whiteList) { if (empty($whiteList)) { return 0; } $this->wrapper->checkRequirements(); $settings = $this->wrapper->getDefaults(); $settings['files'] = $whiteList; $settings['standard'] = [$this->rulesetDir]; $settings['extensions'] = $this->extensions; $settings['warningSeverity'] = 0; $settings['reports']['full'] = $this->reportFile; $this->wrapper->setValues($settings); ob_start(); $result = $this->wrapper->process(); ob_end_clean(); return $result; }
/** * Run tool for files specified * * @param array $whiteList Files/directories to be inspected * @param array $blackList Files/directories to be excluded from the inspection * @param array $extensions Array of alphanumeric strings, for example: 'php', 'xml', 'phtml', 'css'... * @param int $warningSeverity Severity level of warnings, default is 0 * * @return int */ public function run(array $whiteList, array $blackList = array(), array $extensions = array(), $warningSeverity = 0) { $whiteList = array_map(function ($item) { return $item; }, $whiteList); $blackList = array_map(function ($item) { return preg_quote($item); }, $blackList); $this->wrapper->checkRequirements(); $settings = $this->wrapper->getDefaults(); $settings['files'] = $whiteList; $settings['standard'] = [$this->rulesetDir]; $settings['ignored'] = $blackList; $settings['extensions'] = $extensions; $settings['reportFile'] = $this->reportFile; $settings['warningSeverity'] = $warningSeverity; $settings['reports']['checkstyle'] = null; $this->wrapper->setValues($settings); ob_start(); $result = $this->wrapper->process(); ob_end_clean(); return $result; }
/** * Run the PSR2 code sniffs on the code * * @TODO: combine with testCodeStyle * @return void */ public function testCodeStylePsr2() { $reportFile = self::$reportDir . '/phpcs_psr2_report.txt'; $wrapper = new Wrapper(); $codeSniffer = new CodeSniffer('PSR2', $reportFile, $wrapper); if (!$codeSniffer->canRun()) { $this->markTestSkipped('PHP Code Sniffer is not installed.'); } if (version_compare($wrapper->version(), '1.4.7') === -1) { $this->markTestSkipped('PHP Code Sniffer Build Too Old.'); } $result = $codeSniffer->run(self::getWhitelist()); $output = ""; if (file_exists($reportFile)) { $output = file_get_contents($reportFile); } $this->assertEquals(0, $result, "PHP Code Sniffer has found {$result} error(s): " . PHP_EOL . $output); }
/** * Run the PSR2 code sniffs on the code * * @TODO: combine with testCodeStyle * @return void */ public function testCodeStylePsr2() { $reportFile = self::$reportDir . '/phpcs_psr2_report.xml'; $wrapper = new Wrapper(); $codeSniffer = new CodeSniffer('PSR2', $reportFile, $wrapper); if (!$codeSniffer->canRun()) { $this->markTestSkipped('PHP Code Sniffer is not installed.'); } if (version_compare($wrapper->version(), '1.4.7') === -1) { $this->markTestSkipped('PHP Code Sniffer Build Too Old.'); } $result = $codeSniffer->run(self::getWhitelist()); $this->assertEquals(0, $result, "PHP Code Sniffer has found {$result} error(s): See detailed report in {$reportFile}"); }