Skip to content

Commit

Permalink
Merge pull request #3964 from magento-trigger/MC-5421
Browse files Browse the repository at this point in the history
- Added test to check dependencies between modules in Declarative Schema
  • Loading branch information
irenelagno authored Apr 1, 2019
2 parents 2bca2aa + 048de9c commit b95f28b
Show file tree
Hide file tree
Showing 9 changed files with 1,029 additions and 257 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
*/
namespace Magento\TestFramework\Dependency;

use DOMDocument;
use DOMXPath;
use Magento\Framework\App\Utility\Classes;
use Magento\Framework\App\Utility\Files;
use Magento\TestFramework\Dependency\VirtualType\VirtualTypeMapper;

/**
* Class provide dependency rule for di.xml config files.
*/
class DiRule implements RuleInterface
{
/**
Expand All @@ -33,6 +35,8 @@ public function __construct(VirtualTypeMapper $mapper)
}

/**
* Get class name pattern.
*
* @return string
* @throws \Exception
*/
Expand Down Expand Up @@ -73,6 +77,7 @@ private function getPattern()
*/
public function getDependencyInfo($currentModule, $fileType, $file, &$contents)
{
//phpcs:ignore Magento2.Functions.DiscouragedFunction
if (pathinfo($file, PATHINFO_BASENAME) !== 'di.xml') {
return [];
}
Expand All @@ -99,12 +104,14 @@ public function getDependencyInfo($currentModule, $fileType, $file, &$contents)
}

/**
* Fetch all possible dependencies.
*
* @param string $contents
* @return array
*/
private function fetchPossibleDependencies($contents)
{
$doc = new DOMDocument();
$doc = new \DOMDocument();
$doc->loadXML($contents);
return [
RuleInterface::TYPE_SOFT => $this->getSoftDependencies($doc),
Expand All @@ -113,16 +120,22 @@ private function fetchPossibleDependencies($contents)
}

/**
* @param DOMDocument $doc
* Collect soft dependencies.
*
* @param \DOMDocument $doc
* @return array
*/
private function getSoftDependencies(DOMDocument $doc)
private function getSoftDependencies(\DOMDocument $doc)
{
$result = [];
foreach (self::$tagNameMap as $tagName => $attributeNames) {
$nodes = $doc->getElementsByTagName($tagName);
/** @var \DOMElement $node */
foreach ($nodes as $node) {
if ($tagName === 'virtualType' && !$node->getAttribute('type')) {
$result[] = Classes::resolveVirtualType($node->getAttribute('name'));
continue;
}
foreach ($attributeNames as $attributeName) {
$result[] = $node->getAttribute($attributeName);
}
Expand All @@ -133,13 +146,15 @@ private function getSoftDependencies(DOMDocument $doc)
}

/**
* @param DOMDocument $doc
* Collect hard dependencies.
*
* @param \DOMDocument $doc
* @return array
*/
private function getHardDependencies(DOMDocument $doc)
private function getHardDependencies(\DOMDocument $doc)
{
$result = [];
$xpath = new DOMXPath($doc);
$xpath = new \DOMXPath($doc);
$textNodes = $xpath->query('//*[@xsi:type="object"]');
/** @var \DOMElement $node */
foreach ($textNodes as $node) {
Expand Down

This file was deleted.

Loading

0 comments on commit b95f28b

Please sign in to comment.