public function testRun() { $expectedQuoteChar = substr(escapeshellarg(' '), 0, 1); $expectedCmd = 'phpmd' . ' "some/test/dir with space,some/test/file with space.php"' . ' xml' . ' "some/ruleset/file.xml"' . ' --reportfile "some/report/file.xml"'; $expectedCmd = str_replace('"', $expectedQuoteChar, $expectedCmd); $this->_cmd->expects($this->once())->method('_execShellCmd')->with($expectedCmd); $this->_cmd->run(array('some/test/dir with space', 'some/test/file with space.php')); }
public function testCodeMess() { $reportFile = self::$_reportDir . '/phpmd_report.xml'; $cmd = new Inspection_MessDetector_Command(realpath(__DIR__ . '/_files/phpmd/ruleset.xml'), $reportFile); if (!$cmd->canRun()) { $this->markTestSkipped('PHP Mess Detector command line is not available.'); } $this->assertTrue($cmd->run(self::$_whiteList, self::$_blackList), "See detailed report in '{$reportFile}'."); }
/** * @param string $inputFile * @param string|array $expectedXpaths * @depends testRulesetFormat * @depends testPhpMdAvailability * @dataProvider ruleViolationDataProvider */ public function testRuleViolation($inputFile, $expectedXpaths) { $this->assertFalse(self::$_cmd->run(array($inputFile)), "PHP Mess Detector has failed to identify problem at the erroneous file {$inputFile}"); $actualReportXml = simplexml_load_file(self::$_cmd->getReportFile()); $expectedXpaths = (array) $expectedXpaths; foreach ($expectedXpaths as $expectedXpath) { $this->assertNotEmpty($actualReportXml->xpath($expectedXpath), "Expected xpath: '{$expectedXpath}' for file: '{$inputFile}'"); } }
/** * @param string $inputFile * @param string|array $expectedXpaths * @depends testRulesetFormat * @depends testPhpMdAvailability * @dataProvider ruleViolationDataProvider */ public function testRuleViolation($inputFile, $expectedXpaths) { $this->assertNotEquals(PHP_PMD_TextUI_Command::EXIT_SUCCESS, self::$_messDetector->run(array($inputFile)), "PHP Mess Detector has failed to identify problem at the erroneous file {$inputFile}"); $actualReportXml = simplexml_load_file(self::$_reportFile); $expectedXpaths = (array) $expectedXpaths; foreach ($expectedXpaths as $expectedXpath) { $this->assertNotEmpty($actualReportXml->xpath($expectedXpath), "Expected xpath: '{$expectedXpath}' for file: '{$inputFile}'"); } }
/** * @param string $inputFile * @param string $expectedReportFile * @depends testRulesetFormat * @depends testPhpMdAvailability * @dataProvider ruleViolationDataProvider */ public function testRuleViolation($inputFile, $expectedReportFile) { $this->assertFalse(self::$_cmd->run(array($inputFile)), "PHP Mess Detector has failed to identify problem at the erroneous file {$inputFile}"); /* Cleanup report from the variable information */ $actualReportXml = file_get_contents(self::$_cmd->getReportFile()); $actualReportXml = preg_replace('/(?<!\\?xml)\\s+version=".+?"/', '', $actualReportXml, 1); $actualReportXml = preg_replace('/\\s+(?:timestamp|externalInfoUrl)=".+?"/', '', $actualReportXml); $actualReportXml = str_replace(realpath($inputFile), basename($inputFile), $actualReportXml); $this->assertXmlStringEqualsXmlFile($expectedReportFile, $actualReportXml); }