Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DiRuleTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class DiRuleTest extends \PHPUnit\Framework\TestCase
11 {
18  public function testGetDependencyInfo($module, $contents, array $expected)
19  {
20  $diRule = new DiRule(new VirtualTypeMapper([
21  'scope' => [
22  'someVirtualType1' => 'Magento\AnotherModule\Some\Class1',
23  'someVirtualType2' => 'Magento\AnotherModule\Some\Class2'
24  ]
25  ]));
26  $file = '/some/path/scope/di.xml';
27  static::assertEquals($expected, $diRule->getDependencyInfo($module, null, $file, $contents));
28  }
29 
34  {
35  return [
36  'Di without dependencies' => [
37  'Magento\SomeModule',
38  $this->getFileContent('di_no_dependency.xml'),
39  []
40  ],
41  'Di only in module dependencies' => [
42  'Magento\SomeModule',
43  $this->getFileContent('di_in_module_dependency.xml'),
44  []
45  ],
46  'Di external dependencies' => [
47  'Magento\SomeModule',
48  $this->getFileContent('di_external_dependency.xml'),
49  [
50  [
51  'module' => 'Magento\ExternalModule3',
52  'type' => RuleInterface::TYPE_SOFT,
53  'source' => 'Magento\ExternalModule3\Some\Another\Class'
54  ],
55  [
56  'module' => 'Magento\ExternalModule5',
57  'type' => RuleInterface::TYPE_SOFT,
58  'source' => 'Magento\ExternalModule5\Some\Another\Class'
59  ],
60  [
61  'module' => 'Magento\ExternalModule6',
62  'type' => RuleInterface::TYPE_SOFT,
63  'source' => 'Magento\ExternalModule6\Some\Plugin\Class'
64  ],
65  [
66  'module' => 'Magento\ExternalModule1',
67  'type' => RuleInterface::TYPE_HARD,
68  'source' => 'Magento\ExternalModule1\Some\Argument1'
69  ],
70  [
71  'module' => 'Magento\ExternalModule2',
72  'type' => RuleInterface::TYPE_HARD,
73  'source' => 'Magento\ExternalModule2\Some\Argument2'
74  ],
75  [
76  'module' => 'Magento\ExternalModule4',
77  'type' => RuleInterface::TYPE_HARD,
78  'source' => 'Magento\ExternalModule4\Some\Argument3'
79  ]
80  ]
81  ],
82  'Di virtual dependencies' => [
83  'Magento\SomeModule',
84  $this->getFileContent('di_virtual_dependency.xml'),
85  [
86  [
87  'module' => 'Magento\AnotherModule',
88  'type' => RuleInterface::TYPE_HARD,
89  'source' => 'Magento\AnotherModule\Some\Class1',
90  ],
91  [
92  'module' => 'Magento\AnotherModule',
93  'type' => RuleInterface::TYPE_HARD,
94  'source' => 'Magento\AnotherModule\Some\Class2',
95  ]
96  ]
97  ]
98  ];
99  }
100 
107  private function getFileContent($fileName)
108  {
109  return file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . $fileName);
110  }
111 }
$contents
Definition: website.php:14
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
$fileName
Definition: translate.phtml:15
testGetDependencyInfo($module, $contents, array $expected)
Definition: DiRuleTest.php:18