Skip to content

Commit f561de0

Browse files
committed
MAGETWO-66696: Expand the Dependency static test to validate reports.xml dependencies
1 parent ed9edb1 commit f561de0

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\TestFramework\Dependency;
7+
8+
/**
9+
* Class provides dependency rule for reports.xml config file.
10+
*/
11+
class ReportsConfigRule implements RuleInterface
12+
{
13+
/**
14+
* Map of tables and modules
15+
*
16+
* @var array
17+
*/
18+
private $moduleTableMap;
19+
20+
/**
21+
* @param array $tables
22+
*/
23+
public function __construct(array $tables)
24+
{
25+
$this->moduleTableMap = $tables;
26+
}
27+
28+
/**
29+
* @inheritdoc
30+
*/
31+
public function getDependencyInfo($currentModule, $fileType, $file, &$contents)
32+
{
33+
if ('config' != $fileType || !preg_match('#.*/reports\.xml$#', $file)) {
34+
return [];
35+
}
36+
37+
$dependenciesInfo = [];
38+
if (preg_match_all('#<source[^>]*name=[\'"]([^\'"]+)[\'"]#i', $contents, $matches)) {
39+
$tables = array_pop($matches);
40+
foreach ($tables as $table) {
41+
if (!isset($this->moduleTableMap[$table])) {
42+
continue;
43+
}
44+
if (strtolower($currentModule) !== strtolower($this->moduleTableMap[$table])) {
45+
$dependenciesInfo[] = [
46+
'module' => $this->moduleTableMap[$table],
47+
'type' => RuleInterface::TYPE_HARD,
48+
'source' => $table,
49+
];
50+
}
51+
}
52+
}
53+
54+
return $dependenciesInfo;
55+
}
56+
}

dev/tests/static/testsuite/Magento/Test/Integrity/DependencyTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\TestFramework\Dependency\DiRule;
1515
use Magento\TestFramework\Dependency\LayoutRule;
1616
use Magento\TestFramework\Dependency\PhpRule;
17+
use Magento\TestFramework\Dependency\ReportsConfigRule;
1718
use Magento\TestFramework\Dependency\VirtualType\VirtualTypeMapper;
1819

1920
/**
@@ -222,7 +223,8 @@ protected static function _initRules()
222223
self::$_mapLayoutBlocks,
223224
self::$_mapLayoutHandles
224225
),
225-
new DiRule(new VirtualTypeMapper())
226+
new DiRule(new VirtualTypeMapper()),
227+
new ReportsConfigRule($dbRuleTables),
226228
];
227229
}
228230

0 commit comments

Comments
 (0)