/**
  * @depends testRulesetFormat
  * @depends testPhpMdAvailability
  */
 public function testRuleViolation()
 {
     $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
     $invoker(function ($inputFile, $expectedXpaths) {
         $this->assertNotEquals(\PHP_PMD_TextUI_Command::EXIT_SUCCESS, self::$_messDetector->run([$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}'");
         }
     }, include __DIR__ . '/_files/phpmd/data.php');
 }
Example #2
0
 /**
  * Run mess detector on code
  *
  * @return void
  */
 public function testCodeMess()
 {
     $reportFile = self::$reportDir . '/phpmd_report.txt';
     $codeMessDetector = new CodeMessDetector(realpath(__DIR__ . '/_files/phpmd/ruleset.xml'), $reportFile);
     if (!$codeMessDetector->canRun()) {
         $this->markTestSkipped('PHP Mess Detector is not available.');
     }
     $result = $codeMessDetector->run(self::getWhitelist(['php']));
     $output = "";
     if (file_exists($reportFile)) {
         $output = file_get_contents($reportFile);
     }
     $this->assertEquals(Command::EXIT_SUCCESS, $result, "PHP Code Mess has found error(s):" . PHP_EOL . $output);
     // delete empty reports
     if (file_exists($reportFile)) {
         unlink($reportFile);
     }
 }
 /**
  * Run mess detector on code
  *
  * @param array $whiteList
  * @return void
  * @dataProvider whiteListDataProvider
  */
 public function testCodeMess($whiteList)
 {
     if (count($whiteList) == 1) {
         $formattedPath = preg_replace('~/~', '_', preg_replace('~' . self::$pathToSource . '~', '', $whiteList[0]));
     } else {
         $formattedPath = '_app_lib';
     }
     $reportFile = self::$reportDir . '/phpmd_report' . $formattedPath . '.xml';
     $codeMessDetector = new CodeMessDetector(realpath(__DIR__ . '/_files/phpmd/ruleset.xml'), $reportFile);
     if (!$codeMessDetector->canRun()) {
         $this->markTestSkipped('PHP Mess Detector is not available.');
     }
     $this->assertEquals(PHP_PMD_TextUI_Command::EXIT_SUCCESS, $codeMessDetector->run($whiteList, self::$blackList), "PHP Code Mess has found error(s): See detailed report in {$reportFile}");
     // delete empty reports
     unlink($reportFile);
 }
Example #4
0
 /**
  * Run mess detector on code
  *
  * @return void
  */
 public function testCodeMess()
 {
     $reportFile = self::$reportDir . '/phpmd_report.xml';
     $codeMessDetector = new CodeMessDetector(realpath(__DIR__ . '/_files/phpmd/ruleset.xml'), $reportFile);
     if (!$codeMessDetector->canRun()) {
         $this->markTestSkipped('PHP Mess Detector is not available.');
     }
     self::setupFileLists();
     $this->assertEquals(Command::EXIT_SUCCESS, $codeMessDetector->run(self::$whiteList), "PHP Code Mess has found error(s): See detailed report in {$reportFile}");
     // delete empty reports
     unlink($reportFile);
 }