Skip to content

Commit 73a2234

Browse files
committed
MAGETWO-33064: Implement obsolete test for refactored controllers
1 parent 7e07209 commit 73a2234

File tree

3 files changed

+116
-0
lines changed

3 files changed

+116
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Test\Legacy;
8+
9+
/**
10+
* Temporary test that will be removed in scope of MAGETWO-28356.
11+
* Test verifies obsolete usages in modules that were refactored to work with ResultInterface.
12+
*/
13+
class ObsoleteResponseTest extends \PHPUnit_Framework_TestCase
14+
{
15+
/**
16+
* @var array
17+
*/
18+
protected $obsoleteMethods = [];
19+
20+
protected function setUp()
21+
{
22+
$this->obsoleteMethods = include __DIR__ . '/_files/obsolete_response_methods.php';
23+
}
24+
25+
/**
26+
* Test verify that obsolete methods do not appear in refactored folders
27+
*/
28+
public function testObsoleteResponseMethods()
29+
{
30+
$invoker = new \Magento\Framework\Test\Utility\AggregateInvoker($this);
31+
$invoker(
32+
function ($file) {
33+
$content = file_get_contents($file);
34+
foreach ($this->obsoleteMethods as $method) {
35+
$this->assertSame(
36+
0,
37+
preg_match('/(?<=[a-z\d_:]|->|function\s)' . $method . '\s*\(/iS', $content),
38+
"File: $file\nContains obsolete method: $method . "
39+
);
40+
}
41+
},
42+
$this->modulesFilesDataProvider()
43+
);
44+
}
45+
46+
/**
47+
* Return refactored files
48+
*
49+
* @return array
50+
*/
51+
public function modulesFilesDataProvider()
52+
{
53+
$result = [];
54+
$appPath = \Magento\Framework\Test\Utility\Files::init()->getPathToSource();
55+
$refactoredModules = $this->getRefactoredModules('refactored_modules*');
56+
foreach ($refactoredModules as $refactoredFolder) {
57+
$files = \Magento\Framework\Test\Utility\Files::init()->getFiles([$appPath . $refactoredFolder], '*.php');
58+
$result = array_merge($result, $files);
59+
}
60+
61+
return \Magento\Framework\Test\Utility\Files::composeDataSets($result);
62+
}
63+
64+
/**
65+
* @param string $filePattern
66+
* @return array
67+
*/
68+
protected function getRefactoredModules($filePattern)
69+
{
70+
$result = [];
71+
foreach (glob(__DIR__ . '/_files/response_whitelist/' . $filePattern) as $file) {
72+
$fileData = include $file;
73+
$result = array_merge($result, $fileData);
74+
}
75+
return $result;
76+
}
77+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/**
8+
* Temporary implementation that will be removed in scope of MAGETWO-28356.
9+
*
10+
* Obsolete methods for refactored modules
11+
*/
12+
return [
13+
'loadLayout',
14+
'renderLayout',
15+
'_redirect',
16+
'_setActiveMenu',
17+
'_addBreadcrumb',
18+
'_addContent',
19+
'_addLeft',
20+
'_addJs',
21+
'_moveBlockToContainer',
22+
];
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/**
8+
* Temporary implementation that will be removed in scope of MAGETWO-28356.
9+
*
10+
* Modules that were refactored and use ResultInterface
11+
*/
12+
return [
13+
'/app/code/Magento/Catalog',
14+
'/app/code/Magento/Backend',
15+
'/app/code/Magento/Sales',
16+
'/app/code/Magento/Customer',
17+
];

0 commit comments

Comments
 (0)