Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConflictCheckerTest.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Framework\Module\ConflictChecker;
9 
10 class ConflictCheckerTest extends \PHPUnit\Framework\TestCase
11 {
20  $conflictReturnMap,
21  $enabledModules,
22  $moduleName,
23  $expected
24  ) {
25  $moduleListMock = $this->createMock(\Magento\Framework\Module\ModuleList::class);
26  $packageInfoMock = $this->createMock(\Magento\Framework\Module\PackageInfo::class);
27  $moduleListMock->expects($this->any())
28  ->method('getNames')
29  ->will($this->returnValue($enabledModules));
30  $packageInfoMock->expects($this->any())
31  ->method('getConflict')
32  ->will($this->returnValueMap($conflictReturnMap));
33  $packageInfoMock->expects($this->any())
34  ->method('getVersion')
35  ->will($this->returnValue('0.1'));
36  $packageInfoFactoryMock = $this->createMock(\Magento\Framework\Module\PackageInfoFactory::class);
37  $packageInfoFactoryMock->expects($this->once())
38  ->method('create')
39  ->will($this->returnValue($packageInfoMock));
40  $conflictChecker = new ConflictChecker($moduleListMock, $packageInfoFactoryMock);
41  $this->assertEquals($expected, $conflictChecker->checkConflictsWhenEnableModules($moduleName));
42  }
43 
48  {
49  return [
50  [
51  [['Vendor_A', ['Vendor_B' => '0.1']], ['Vendor_B', []]],
52  ['Vendor_A'],
53  ['Vendor_B'],
54  ['Vendor_B' => ['Vendor_A conflicts with current Vendor_B version 0.1 (version should not be 0.1)']]
55  ],
56  [
57  [['Vendor_A', ['Vendor_B' => '0.1']], ['Vendor_B', []]],
58  [],
59  ['Vendor_B'],
60  ['Vendor_B' => []]
61  ],
62  [
63  [['Vendor_B', ['Vendor_A' => '0.1']], ['Vendor_A', []]],
64  ['Vendor_A'],
65  ['Vendor_B'],
66  ['Vendor_B' => ['Vendor_B conflicts with current Vendor_A version 0.1 (version should not be 0.1)']]
67  ],
68  [
69  [['Vendor_B', ['Vendor_A' => '0.1']], ['Vendor_A', []]],
70  [],
71  ['Vendor_B'],
72  ['Vendor_B' => []]
73  ],
74  [
75  [['Vendor_A', []], ['Vendor_B', []]],
76  ['Vendor_A'],
77  ['Vendor_B'],
78  ['Vendor_B' => []]
79  ],
80  [
81  [['Vendor_A', []], ['Vendor_B', []], ['Vendor_C', []]],
82  ['Vendor_A'],
83  ['Vendor_B', 'Vendor_C'],
84  ['Vendor_B' => [], 'Vendor_C' => []]
85  ],
86  [
87  [['Vendor_A', ['Vendor_C' => '0.1']], ['Vendor_B', []], ['Vendor_C', []]],
88  ['Vendor_A'],
89  ['Vendor_B', 'Vendor_C'],
90  [
91  'Vendor_B' => [],
92  'Vendor_C' => ['Vendor_A conflicts with current Vendor_C version 0.1 (version should not be 0.1)']
93  ]
94  ],
95  [
96  [['Vendor_A', []], ['Vendor_B', ['Vendor_C' => '0.1']], ['Vendor_C', []]],
97  ['Vendor_A'],
98  ['Vendor_B', 'Vendor_C'],
99  [
100  'Vendor_B' => ['Vendor_B conflicts with current Vendor_C version 0.1 (version should not be 0.1)'],
101  'Vendor_C' => ['Vendor_B conflicts with current Vendor_C version 0.1 (version should not be 0.1)']
102  ]
103  ],
104  [
105  [['Vendor_A', ['Vendor_B' => '>=0.1']], ['Vendor_B', []]],
106  ['Vendor_A'],
107  ['Vendor_B'],
108  ['Vendor_B' => ['Vendor_A conflicts with current Vendor_B version 0.1 (version should not be >=0.1)']]
109  ],
110  [
111  [['Vendor_A', ['Vendor_B' => '~0.1']], ['Vendor_B', []]],
112  ['Vendor_A'],
113  ['Vendor_B'],
114  ['Vendor_B' => ['Vendor_A conflicts with current Vendor_B version 0.1 (version should not be ~0.1)']]
115  ],
116  ];
117  }
118 
120  {
121  $moduleListMock = $this->createMock(\Magento\Framework\Module\ModuleList::class);
122  $packageInfoMock = $this->createMock(\Magento\Framework\Module\PackageInfo::class);
123  $moduleListMock->expects($this->any())
124  ->method('getNames')
125  ->will($this->returnValue(['Vendor_A', 'Vendor_B']));
126  $packageInfoMock->expects($this->any())
127  ->method('getConflict')
128  ->will($this->returnValueMap([
129  ['Vendor_A', []],
130  ['Vendor_B', []],
131  ['Vendor_C', ['Vendor_A' => '>=0.2,<0.3', 'Vendor_B' => '<0.4']]
132  ]));
133  $packageInfoMock->expects($this->any())
134  ->method('getVersion')
135  ->will($this->returnValueMap([['Vendor_A', '0.2'], ['Vendor_B', '0.4']]));
136  $packageInfoFactoryMock = $this->createMock(\Magento\Framework\Module\PackageInfoFactory::class);
137  $packageInfoFactoryMock->expects($this->once())
138  ->method('create')
139  ->will($this->returnValue($packageInfoMock));
140  $conflictChecker = new ConflictChecker($moduleListMock, $packageInfoFactoryMock);
141  $this->assertEquals(
142  ['Vendor_C' => ['Vendor_C conflicts with current Vendor_A version 0.2 (version should not be >=0.2,<0.3)']],
143  $conflictChecker->checkConflictsWhenEnableModules(['Vendor_C'])
144  );
145  }
146 
148  {
149  $moduleListMock = $this->createMock(\Magento\Framework\Module\ModuleList::class);
150  $packageInfoMock = $this->createMock(\Magento\Framework\Module\PackageInfo::class);
151  $packageInfoMock->expects($this->any())
152  ->method('getConflict')
153  ->will($this->returnValueMap([
154  ['Vendor_A', []],
155  ['Vendor_B', []],
156  ['Vendor_C', ['Vendor_A' => '>=0.2,<0.3', 'Vendor_B' => '<0.4']]
157  ]));
158  $packageInfoMock->expects($this->any())
159  ->method('getVersion')
160  ->will($this->returnValueMap([['Vendor_A', '0.2'], ['Vendor_B', '0.4']]));
161  $packageInfoFactoryMock = $this->createMock(\Magento\Framework\Module\PackageInfoFactory::class);
162  $packageInfoFactoryMock->expects($this->once())
163  ->method('create')
164  ->will($this->returnValue($packageInfoMock));
165  $conflictChecker = new ConflictChecker($moduleListMock, $packageInfoFactoryMock);
166  $this->assertEquals(
167  ['Vendor_C' => ['Vendor_C conflicts with current Vendor_A version 0.2 (version should not be >=0.2,<0.3)']],
168  $conflictChecker->checkConflictsWhenEnableModules(['Vendor_C'], ['Vendor_A', 'Vendor_B'])
169  );
170  }
171 }
testCheckConflictsWhenEnableModules( $conflictReturnMap, $enabledModules, $moduleName, $expected)