コード例 #1
0
 /**
  * @depends testPhpCsAvailability
  */
 public function testRule()
 {
     $invoker = new \Magento\TestFramework\Utility\AggregateInvoker($this);
     $invoker(function ($inputFile, $expectedResultFile) {
         $expectedXml = simplexml_load_file($expectedResultFile);
         // rule is not implemented
         $elements = $expectedXml->xpath('/config/incomplete');
         if ($elements) {
             $message = (string) $elements[0];
             $this->markTestIncomplete("Rule for the fixture '{$inputFile}' is not implemented. {$message}");
         }
         // run additional methods before making test
         $elements = $expectedXml->xpath('/config/run');
         foreach ($elements as $element) {
             $method = (string) $element->attributes()->method;
             $this->{$method}();
         }
         self::$_cmd->run(array($inputFile));
         $resultXml = simplexml_load_file(self::$_reportFile);
         $this->_assertTotalErrorsAndWarnings($resultXml, $expectedXml);
         $this->_assertErrors($resultXml, $expectedXml);
         $this->_assertWarnings($resultXml, $expectedXml);
         // verify that there has been at least one assertion performed
         if ($this->getCount() == 0) {
             $this->fail("Broken test: there has no assertions been performed for the fixture '{$inputFile}'.");
         }
     }, $this->ruleDataProvider());
 }
コード例 #2
0
 public function testRun()
 {
     $whiteList = ['test' . rand(), 'test' . rand()];
     $extensions = ['test' . rand(), 'test' . rand()];
     $this->_wrapper->expects($this->once())->method('getDefaults')->will($this->returnValue([]));
     $expectedCliEmulation = ['files' => $whiteList, 'standard' => [self::RULE_SET], 'extensions' => $extensions, 'reportFile' => self::REPORT_FILE, 'warningSeverity' => 0, 'reports' => ['checkstyle' => null]];
     $this->_tool->setExtensions($extensions);
     $this->_wrapper->expects($this->once())->method('setValues')->with($this->equalTo($expectedCliEmulation));
     $this->_wrapper->expects($this->once())->method('process');
     $this->_tool->run($whiteList);
 }
コード例 #3
0
 /**
  * Run the magento specific coding standards on the code
  *
  * @return void
  */
 public function testCodeStyle()
 {
     $reportFile = self::$reportDir . '/less_report.txt';
     $wrapper = new LessWrapper();
     $codeSniffer = new CodeSniffer(realpath(__DIR__ . '/_files/lesscs'), $reportFile, $wrapper);
     if (!$codeSniffer->canRun()) {
         $this->markTestSkipped('PHP Code Sniffer is not installed.');
     }
     $codeSniffer->setExtensions([LessWrapper::LESS_FILE_EXTENSION]);
     $fileList = PHPCodeTest::getWhitelist([LessWrapper::LESS_FILE_EXTENSION], __DIR__, __DIR__);
     $result = $codeSniffer->run($this->filterFiles($fileList));
     $this->assertEquals(0, $result, "PHP Code Sniffer has found {$result} error(s): See detailed report in {$reportFile}");
 }
コード例 #4
0
 /**
  * Run the annotations sniffs on the code
  *
  * @return void
  * @todo Combine with normal code style at some point.
  */
 public function testAnnotationStandard()
 {
     $reportFile = self::$reportDir . '/phpcs_annotations_report.txt';
     $wrapper = new Wrapper();
     $codeSniffer = new CodeSniffer(realpath(__DIR__ . '/../../../../framework/Magento/ruleset.xml'), $reportFile, $wrapper);
     if (!$codeSniffer->canRun()) {
         $this->markTestSkipped('PHP Code Sniffer is not installed.');
     }
     $result = $codeSniffer->run(self::getWhitelist(['php']));
     $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);
 }
コード例 #5
0
 /**
  * Run the annotations sniffs on the code
  *
  * @return void
  * @todo Combine with normal code style at some point.
  */
 public function testAnnotationStandard()
 {
     $reportFile = self::$reportDir . '/phpcs_annotations_report.xml';
     $wrapper = new Wrapper();
     $codeSniffer = new CodeSniffer(realpath(__DIR__ . '/../../../../framework/Magento/ruleset.xml'), $reportFile, $wrapper);
     if (!$codeSniffer->canRun()) {
         $this->markTestSkipped('PHP Code Sniffer is not installed.');
     }
     self::setupFileLists('phpcs');
     $severity = 0;
     // Change to 5 to see the warnings
     $this->assertEquals(0, $result = $codeSniffer->run(self::$whiteList, self::$blackList, array('php'), $severity), "PHP Code Sniffer has found {$result} error(s): See detailed report in {$reportFile}");
 }
コード例 #6
0
 /**
  * Run the annotations sniffs on the code
  *
  * @return void
  * @todo Combine with normal code style at some point.
  */
 public function testAnnotationStandard()
 {
     $reportFile = self::$reportDir . '/phpcs_annotations_report.xml';
     $warningSeverity = 5;
     $wrapper = new Wrapper();
     $codeSniffer = new CodeSniffer(realpath(__DIR__ . '/../../../../framework/Magento/ruleset.xml'), $reportFile, $wrapper);
     if (!$codeSniffer->canRun()) {
         $this->markTestSkipped('PHP Code Sniffer is not installed.');
     }
     self::setupFileLists('phpcs');
     // Scan for error amount
     $result = $codeSniffer->run(self::$whiteList, self::$blackList, array('php'), 0);
     // Rescan to generate report with warnings.
     $codeSniffer->run(self::$whiteList, self::$blackList, array('php'), $warningSeverity);
     // Fail if there are errors in report.
     $this->assertEquals(0, $result, "PHP Code Sniffer has found {$result} error(s): See detailed report in {$reportFile}");
 }
コード例 #7
0
 public function testGetReportFile()
 {
     $this->assertEquals(self::REPORT_FILE, $this->_tool->getReportFile());
 }