Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ReadmeTest.php
Go to the documentation of this file.
1 <?php
11 
13 
14 class ReadmeTest extends \PHPUnit\Framework\TestCase
15 {
16  const README_FILENAME = 'README.md';
17 
18  const BLACKLIST_FILES_PATTERN = '_files/blacklist/*.txt';
19 
20  const SCAN_LIST_FILE = '_files/scan_list.txt';
21 
23  private $blacklist = [];
24 
26  private $scanList = [];
27 
28  protected function setUp()
29  {
30  $this->blacklist = $this->getPaths(__DIR__ . '/' . self::BLACKLIST_FILES_PATTERN);
31  $this->scanList = $this->getPaths(__DIR__ . '/' . self::SCAN_LIST_FILE);
32  }
33 
34  public function testReadmeFiles()
35  {
36  $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
37  $invoker(
41  function ($dir) {
42  $file = $dir . DIRECTORY_SEPARATOR . self::README_FILENAME;
43  $this->assertFileExists(
44  $file,
45  sprintf('File %s not found in %s', self::README_FILENAME, $dir)
46  );
47  },
48  $this->getDirectories()
49  );
50  }
51 
55  private function getDirectories()
56  {
57  $directories = [];
58  foreach ($this->scanList as $dir) {
59  if (!$this->isInBlacklist($dir)) {
60  $directories[][$dir] = $dir;
61  }
62  }
63 
64  return $directories;
65  }
66 
71  private function isInBlacklist($path)
72  {
73  return in_array($path, $this->blacklist);
74  }
75 
82  private function getPaths($patternsFile)
83  {
84  $result = [];
85  $files = Files::init()->readLists($patternsFile);
86  foreach ($files as $file) {
87  if (is_dir($file)) {
88  $result[] = rtrim($file, '/');
89  }
90  }
91  return $result;
92  }
93 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
foreach($appDirs as $dir) $files