1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Test\Legacy;
use Magento\Framework\Component\ComponentRegistrar;
/**
* Temporary test that will be removed in scope of MAGETWO-28356.
* Test verifies obsolete usages in modules that were refactored to work with ResultInterface.
*/
class ObsoleteResponseTest extends \PHPUnit\Framework\TestCase
{
/**
* @var array
*/
protected $obsoleteMethods = [];
/**
* @var array
*/
protected $filesBlackList = [];
/**
* @var string
*/
protected $appPath;
protected function setUp()
{
$this->obsoleteMethods = include __DIR__ . '/_files/response/obsolete_response_methods.php';
$this->filesBlackList = $this->getBlackList();
}
/**
* Test verify that obsolete methods do not appear in refactored folders
*/
public function testObsoleteResponseMethods()
{
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
$invoker(
function ($file) {
$content = file_get_contents($file);
foreach ($this->obsoleteMethods as $method) {
$quotedMethod = preg_quote($method, '/');
$this->assertSame(
0,
preg_match('/(?<=[a-z\\d_:]|->|function\\s)' . $quotedMethod . '\\s*\\(/iS', $content),
"File: $file\nContains obsolete method: $method . "
);
}
},
$this->modulesFilesDataProvider()
);
}
/**
* Return refactored files
*
* @return array
*/
public function modulesFilesDataProvider()
{
$filesList = [];
$componentRegistrar = new ComponentRegistrar();
foreach ($this->getFilesData('whitelist/refactored_modules*') as $refactoredModule) {
if ($componentRegistrar->getPath(ComponentRegistrar::MODULE, $refactoredModule)) {
$files = \Magento\Framework\App\Utility\Files::init()->getFiles(
[$componentRegistrar->getPath(ComponentRegistrar::MODULE, $refactoredModule)],
'*.php'
);
$filesList = array_merge($filesList, $files);
}
}
$result = array_map('realpath', $filesList);
$result = array_diff($result, $this->filesBlackList);
return \Magento\Framework\App\Utility\Files::composeDataSets($result);
}
/**
* @return array
*/
protected function getBlackList()
{
$blackListFiles = [];
$componentRegistrar = new ComponentRegistrar();
foreach ($this->getFilesData('blacklist/files_list*') as $fileInfo) {
$blackListFiles[] = $componentRegistrar->getPath(ComponentRegistrar::MODULE, $fileInfo[0])
. DIRECTORY_SEPARATOR . $fileInfo[1];
}
return $blackListFiles;
}
/**
* @param string $filePattern
* @return array
*/
protected function getFilesData($filePattern)
{
$result = [];
foreach (glob(__DIR__ . '/_files/response/' . $filePattern) as $file) {
$fileData = include $file;
$result = array_merge($result, $fileData);
}
return $result;
}
}