Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ObsoleteConnectionTest.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Test\Legacy;
7 
9 
14 class ObsoleteConnectionTest extends \PHPUnit\Framework\TestCase
15 {
19  protected $obsoleteMethods = [];
20 
24  protected $obsoleteRegexp = [];
25 
29  protected $filesBlackList = [];
30 
34  protected $appPath;
35 
36  protected function setUp()
37  {
38  $this->obsoleteMethods = [
39  '_getReadConnection',
40  '_getWriteConnection',
41  '_getReadAdapter',
42  '_getWriteAdapter',
43  'getReadConnection',
44  'getWriteConnection',
45  'getReadAdapter',
46  'getWriteAdapter',
47  ];
48 
49  $this->obsoleteRegexp = [
50  // 'getConnection\\(\'\\w*_*(read|write)',
51  '\\$_?(read|write)(Connection|Adapter)',
52  '\\$write([A-Z]\\w*|\\s)',
53  ];
54 
55  $this->filesBlackList = $this->getBlackList();
56  }
57 
61  public function testObsoleteRegexp()
62  {
63  $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
64  $invoker(
65  function ($file) {
66  $content = file_get_contents($file);
67  foreach ($this->obsoleteRegexp as $regexp) {
68  $this->assertSame(
69  0,
70  preg_match('/' . $regexp . '/iS', $content),
71  "File: $file\nContains obsolete regexp: $regexp. "
72  );
73  }
74  },
76  );
77  }
78 
82  public function testObsoleteResponseMethods()
83  {
84  $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
85  $invoker(
86  function ($file) {
87  $content = file_get_contents($file);
88  foreach ($this->obsoleteMethods as $method) {
89  $quotedMethod = preg_quote($method, '/');
90  $this->assertSame(
91  0,
92  preg_match('/(?<=[a-z\\d_:]|->|function\\s)' . $quotedMethod . '\\s*\\(/iS', $content),
93  "File: $file\nContains obsolete method: $method . "
94  );
95  }
96  },
98  );
99  }
100 
106  public function modulesFilesDataProvider()
107  {
108  $filesList = [];
110  foreach ($this->getFilesData('whitelist/refactored_modules*') as $refactoredModule) {
111  if ($componentRegistrar->getPath(ComponentRegistrar::MODULE, $refactoredModule)) {
113  [$componentRegistrar->getPath(ComponentRegistrar::MODULE, $refactoredModule)],
114  '*.php'
115  );
116  $filesList = array_merge($filesList, $files);
117  }
118  }
119 
120  $result = array_map('realpath', $filesList);
121  $result = array_diff($result, $this->filesBlackList);
122  return \Magento\Framework\App\Utility\Files::composeDataSets($result);
123  }
124 
128  protected function getBlackList()
129  {
130  $blackListFiles = [];
132  foreach ($this->getFilesData('blacklist/files_list*') as $fileInfo) {
133  $blackListFiles[] = $componentRegistrar->getPath(ComponentRegistrar::MODULE, $fileInfo[0])
134  . DIRECTORY_SEPARATOR . $fileInfo[1];
135  }
136  return $blackListFiles;
137  }
138 
143  protected function getFilesData($filePattern)
144  {
145  $result = [];
146  foreach (glob(__DIR__ . '/_files/connection/' . $filePattern) as $file) {
147  $fileData = include $file;
148  $result = array_merge($result, $fileData);
149  }
150  return $result;
151  }
152 }
$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