Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
LiveCodeTest.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Test\Less;
8 
13 use Magento\Test\Php\LiveCodeTest as PHPCodeTest;
14 
18 class LiveCodeTest extends \PHPUnit\Framework\TestCase
19 {
23  private static $reportDir = '';
24 
30  public static function setUpBeforeClass()
31  {
32  self::$reportDir = BP . '/dev/tests/static/report';
33  if (!is_dir(self::$reportDir)) {
34  mkdir(self::$reportDir, 0770);
35  }
36  }
37 
43  public function testCodeStyle()
44  {
45  $reportFile = self::$reportDir . '/csless_report.txt';
46  $wrapper = new LessWrapper();
47  $codeSniffer = new CodeSniffer(realpath(__DIR__ . '/_files/lesscs'), $reportFile, $wrapper);
48 
49  if (!$codeSniffer->canRun()) {
50  $this->markTestSkipped('PHP Code Sniffer is not installed.');
51  }
52 
53  $codeSniffer->setExtensions([LessWrapper::LESS_FILE_EXTENSION]);
54 
55  $fileList = PHPCodeTest::getWhitelist([LessWrapper::LESS_FILE_EXTENSION], __DIR__, __DIR__);
56 
57  $result = $codeSniffer->run($this->filterFiles($fileList));
58 
59  $report = file_exists($reportFile) ? file_get_contents($reportFile) : "";
60  $this->assertEquals(
61  0,
62  $result,
63  "PHP Code Sniffer has found {$result} error(s): " . PHP_EOL . $report
64  );
65  }
66 
74  private function filterFiles(array $fileList)
75  {
76  $blackListFiles = Files::init()->readLists(__DIR__ . '/_files/blacklist/*.txt');
77 
78  $filter = function ($value) use ($blackListFiles) {
79  return !in_array($value, $blackListFiles);
80  };
81 
82  return array_filter($fileList, $filter);
83  }
84 }
$fileList
Definition: export.php:13
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
$value
Definition: gender.phtml:16
const BP
Definition: autoload.php:14
mkdir($pathname, $mode=0777, $recursive=false, $context=null)
Definition: ioMock.php:25