Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
ObsoleteConnectionTest Class Reference
Inheritance diagram for ObsoleteConnectionTest:

Public Member Functions

 testObsoleteRegexp ()
 
 testObsoleteResponseMethods ()
 
 modulesFilesDataProvider ()
 

Protected Member Functions

 setUp ()
 
 getBlackList ()
 
 getFilesData ($filePattern)
 

Protected Attributes

 $obsoleteMethods = []
 
 $obsoleteRegexp = []
 
 $filesBlackList = []
 
 $appPath
 

Detailed Description

Temporary test Test verifies obsolete usages in modules that were refactored to work with getConnection.

Definition at line 14 of file ObsoleteConnectionTest.php.

Member Function Documentation

◆ getBlackList()

getBlackList ( )
protected
Returns
array

Definition at line 128 of file ObsoleteConnectionTest.php.

129  {
130  $blackListFiles = [];
131  $componentRegistrar = new ComponentRegistrar();
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  }
$componentRegistrar
Definition: bootstrap.php:23

◆ getFilesData()

getFilesData (   $filePattern)
protected
Parameters
string$filePattern
Returns
array

Definition at line 143 of file ObsoleteConnectionTest.php.

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  }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60

◆ modulesFilesDataProvider()

modulesFilesDataProvider ( )

Return refactored files

Returns
array

Definition at line 106 of file ObsoleteConnectionTest.php.

107  {
108  $filesList = [];
109  $componentRegistrar = new ComponentRegistrar();
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  }
$componentRegistrar
Definition: bootstrap.php:23
foreach($appDirs as $dir) $files

◆ setUp()

setUp ( )
protected

Definition at line 36 of file ObsoleteConnectionTest.php.

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  }

◆ testObsoleteRegexp()

testObsoleteRegexp ( )

Test verify that obsolete regexps do not appear in refactored folders

Definition at line 61 of file ObsoleteConnectionTest.php.

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  }

◆ testObsoleteResponseMethods()

testObsoleteResponseMethods ( )

Test verify that obsolete methods do not appear in refactored folders

Definition at line 82 of file ObsoleteConnectionTest.php.

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  }
$method
Definition: info.phtml:13

Field Documentation

◆ $appPath

$appPath
protected

Definition at line 34 of file ObsoleteConnectionTest.php.

◆ $filesBlackList

$filesBlackList = []
protected

Definition at line 29 of file ObsoleteConnectionTest.php.

◆ $obsoleteMethods

$obsoleteMethods = []
protected

Definition at line 19 of file ObsoleteConnectionTest.php.

◆ $obsoleteRegexp

$obsoleteRegexp = []
protected

Definition at line 24 of file ObsoleteConnectionTest.php.


The documentation for this class was generated from the following file: