Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ObsoleteResponseTest.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Test\Legacy;
7 
9 
14 class ObsoleteResponseTest extends \PHPUnit\Framework\TestCase
15 {
19  protected $obsoleteMethods = [];
20 
24  protected $filesBlackList = [];
25 
29  protected $appPath;
30 
31  protected function setUp()
32  {
33  $this->obsoleteMethods = include __DIR__ . '/_files/response/obsolete_response_methods.php';
34  $this->filesBlackList = $this->getBlackList();
35  }
36 
40  public function testObsoleteResponseMethods()
41  {
42  $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
43  $invoker(
44  function ($file) {
45  $content = file_get_contents($file);
46  foreach ($this->obsoleteMethods as $method) {
47  $quotedMethod = preg_quote($method, '/');
48  $this->assertSame(
49  0,
50  preg_match('/(?<=[a-z\\d_:]|->|function\\s)' . $quotedMethod . '\\s*\\(/iS', $content),
51  "File: $file\nContains obsolete method: $method . "
52  );
53  }
54  },
56  );
57  }
58 
64  public function modulesFilesDataProvider()
65  {
66  $filesList = [];
68  foreach ($this->getFilesData('whitelist/refactored_modules*') as $refactoredModule) {
69  if ($componentRegistrar->getPath(ComponentRegistrar::MODULE, $refactoredModule)) {
71  [$componentRegistrar->getPath(ComponentRegistrar::MODULE, $refactoredModule)],
72  '*.php'
73  );
74  $filesList = array_merge($filesList, $files);
75  }
76  }
77 
78  $result = array_map('realpath', $filesList);
79  $result = array_diff($result, $this->filesBlackList);
80  return \Magento\Framework\App\Utility\Files::composeDataSets($result);
81  }
82 
86  protected function getBlackList()
87  {
88  $blackListFiles = [];
90  foreach ($this->getFilesData('blacklist/files_list*') as $fileInfo) {
91  $blackListFiles[] = $componentRegistrar->getPath(ComponentRegistrar::MODULE, $fileInfo[0])
92  . DIRECTORY_SEPARATOR . $fileInfo[1];
93  }
94  return $blackListFiles;
95  }
96 
101  protected function getFilesData($filePattern)
102  {
103  $result = [];
104  foreach (glob(__DIR__ . '/_files/response/' . $filePattern) as $file) {
105  $fileData = include $file;
106  $result = array_merge($result, $fileData);
107  }
108  return $result;
109  }
110 }
$componentRegistrar
Definition: bootstrap.php:23
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
$method
Definition: info.phtml:13
foreach($appDirs as $dir) $files