Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SystemPackageTest.php
Go to the documentation of this file.
1 <?php
8 
11 
12 class SystemPackageTest extends \PHPUnit\Framework\TestCase
13 {
17  private $infoCommand;
18 
22  private $systemPackage;
23 
27  private $repository;
28 
32  private $locker;
33 
37  private $magentoComposerApp;
38 
42  private $composerAppFactory;
43 
47  private $composer;
48 
52  private $expectedPackages = [
53  [
54  'id' => '1.2.0',
55  'name' => 'Version 1.2.0 EE (latest)',
57  'stable' => true,
58  'current' => false,
59  ],
60  [
61  'id' => '1.2.0',
62  'name' => 'Version 1.2.0 CE (latest)',
64  'stable' => true,
65  'current' => false,
66  ],
67  [
68  'id' => '1.1.0',
69  'name' => 'Version 1.1.0 EE',
71  'stable' => true,
72  'current' => false,
73  ],
74  [
75  'id' => '1.1.0',
76  'name' => 'Version 1.1.0 CE',
78  'stable' => true,
79  'current' => false,
80  ],
81  [
82  'id' => '1.1.0-RC1',
83  'name' => 'Version 1.1.0-RC1 EE (unstable version)',
85  'stable' => false,
86  'current' => false,
87  ],
88  [
89  'id' => '1.1.0-RC1',
90  'name' => 'Version 1.1.0-RC1 CE (unstable version)',
92  'stable' => false,
93  'current' => false,
94  ],
95  [
96  'id' => '1.0.0',
97  'name' => 'Version 1.0.0 EE',
99  'stable' => true,
100  'current' => true,
101  ],
102  [
103  'id' => '1.0.0',
104  'name' => 'Version 1.0.0 CE',
106  'stable' => true,
107  'current' => true,
108  ],
109  ];
110 
114  private $composerInformation;
115 
116  public function setUp()
117  {
118  $this->composerAppFactory = $this->createMock(
119  \Magento\Framework\Composer\MagentoComposerApplicationFactory::class
120  );
121 
122  $this->infoCommand = $this->createMock(
123  \Magento\Composer\InfoCommand::class
124  );
125 
126  $this->magentoComposerApp =
127  $this->createMock(\Magento\Composer\MagentoComposerApplication::class);
128  $this->locker = $this->createMock(\Composer\Package\Locker::class);
129  $this->repository = $this->createMock(\Composer\Repository\ArrayRepository::class);
130  $this->composer = $this->createMock(\Composer\Composer::class);
131  $this->composerInformation = $this->createMock(
132  \Magento\Framework\Composer\ComposerInformation::class
133  );
134  }
135 
136  public function testGetPackageVersions()
137  {
138  $communityPackage = $this->createMock(\Composer\Package\Package::class);
139  $communityPackage->expects($this->once())->method('getName')->willReturn(SystemPackage::EDITION_COMMUNITY);
140  $enterprisePackage = $this->createMock(\Composer\Package\Package::class);
141  $enterprisePackage->expects($this->once())->method('getName')->willReturn(SystemPackage::EDITION_ENTERPRISE);
142  $this->composerInformation->expects($this->any())->method('isSystemPackage')->willReturn(true);
143  $this->composerInformation->expects($this->once())->method('isPackageInComposerJson')->willReturn(true);
144  $this->repository
145  ->expects($this->once())
146  ->method('getPackages')
147  ->willReturn([$communityPackage, $enterprisePackage]);
148 
149  $this->locker->expects($this->once())->method('getLockedRepository')->willReturn($this->repository);
150 
151  $this->composer->expects($this->once())->method('getLocker')->willReturn($this->locker);
152  $this->magentoComposerApp->expects($this->once())->method('createComposer')->willReturn($this->composer);
153 
154  $this->composerAppFactory->expects($this->once())
155  ->method('createInfoCommand')
156  ->willReturn($this->infoCommand);
157 
158  $this->composerAppFactory->expects($this->once())
159  ->method('create')
160  ->willReturn($this->magentoComposerApp);
161 
162  $this->composerAppFactory->expects($this->once())
163  ->method('createInfoCommand')
164  ->willReturn($this->infoCommand);
165 
166  $this->systemPackage = new SystemPackage($this->composerAppFactory, $this->composerInformation);
167 
168  $this->infoCommand->expects($this->any())
169  ->method('run')
170  ->willReturnMap([
171  [
173  false,
174  [
176  'description' => 'eCommerce Platform for Growth (Enterprise Edition)',
177  'keywords' => '',
178  'versions' => '1.2.0, 1.1.0, 1.1.0-RC1, * 1.0.0',
179  'type' => 'metapackage',
180  'license' => 'OSL-3.0, AFL-3.0',
181  'source' => '[]',
183  'current_version' => '1.0.0',
184  InfoCommand::AVAILABLE_VERSIONS => [1 => '1.2.0', 2 => '1.1.0', 3 => '1.1.0-RC1', 4 => '1.0.0'],
185  'new_versions' => ['1.2.0', '1.1.0', '1.1.0-RC1'],
186  ],
187  ],
188  [
190  false,
191  [
193  'description' => 'eCommerce Platform for Growth (Enterprise Edition)',
194  'keywords' => '',
195  'versions' => '1.2.0, 1.1.0, 1.1.0-RC1, * 1.0.0',
196  'type' => 'metapackage',
197  'license' => 'OSL-3.0, AFL-3.0',
198  'source' => '[]',
200  'current_version' => '1.0.0',
201  InfoCommand::AVAILABLE_VERSIONS => [1 => '1.2.0', 2 => '1.1.0', 3 => '1.1.0-RC1', 4 => '1.0.0'],
202  'new_versions' => ['1.2.0', '1.1.0', '1.1.0-RC1'],
203  ],
204 
205  ]
206  ]);
207  $this->assertEquals($this->expectedPackages, $this->systemPackage->getPackageVersions());
208  }
209 
215  {
216  $package = $this->createMock(\Composer\Package\Package::class);
217  $this->repository
218  ->expects($this->once())
219  ->method('getPackages')
220  ->willReturn([$package]);
221 
222  $this->locker->expects($this->once())->method('getLockedRepository')->willReturn($this->repository);
223  $this->composerInformation->expects($this->any())->method('isSystemPackage')->willReturn(false);
224  $this->composer->expects($this->once())->method('getLocker')->willReturn($this->locker);
225  $this->magentoComposerApp->expects($this->once())->method('createComposer')->willReturn($this->composer);
226 
227  $this->composerAppFactory->expects($this->once())
228  ->method('create')
229  ->willReturn($this->magentoComposerApp);
230 
231  $this->composerAppFactory->expects($this->once())
232  ->method('createInfoCommand')
233  ->willReturn($this->infoCommand);
234 
235  $this->systemPackage = new SystemPackage($this->composerAppFactory, $this->composerInformation);
236  $this->systemPackage->getPackageVersions();
237  }
238 
244  {
245  $communityPackage = $this->createMock(\Composer\Package\Package::class);
246  $enterprisePackage = $this->createMock(\Composer\Package\Package::class);
247 
248  $communityPackage->expects($this->once())->method('getName')->willReturn(SystemPackage::EDITION_COMMUNITY);
249  $enterprisePackage->expects($this->once())->method('getName')->willReturn(SystemPackage::EDITION_ENTERPRISE);
250  $this->composerInformation->expects($this->any())->method('isSystemPackage')->willReturn(true);
251  $this->composerInformation->expects($this->once())->method('isPackageInComposerJson')->willReturn(true);
252 
253  $this->repository
254  ->expects($this->once())
255  ->method('getPackages')
256  ->willReturn([$communityPackage, $enterprisePackage]);
257 
258  $this->locker->expects($this->once())->method('getLockedRepository')->willReturn($this->repository);
259 
260  $this->composer->expects($this->once())->method('getLocker')->willReturn($this->locker);
261  $this->magentoComposerApp->expects($this->once())->method('createComposer')->willReturn($this->composer);
262 
263  $this->composerAppFactory->expects($this->once())
264  ->method('create')
265  ->willReturn($this->magentoComposerApp);
266 
267  $this->composerAppFactory->expects($this->once())
268  ->method('createInfoCommand')
269  ->willReturn($this->infoCommand);
270 
271  $this->systemPackage = new SystemPackage($this->composerAppFactory, $this->composerInformation);
272 
273  $this->infoCommand->expects($this->once())
274  ->method('run')
276  ->willReturn(false);
277 
278  $this->systemPackage->getPackageVersions();
279  }
280 
287  public function testGetAllowedEnterpriseVersions($ceCurrentVersion, $expectedResult)
288  {
289  $this->composerAppFactory->expects($this->once())
290  ->method('createInfoCommand')
291  ->willReturn($this->infoCommand);
292  $this->systemPackage = new SystemPackage($this->composerAppFactory, $this->composerInformation);
293  $this->infoCommand->expects($this->once())
294  ->method('run')
296  ->willReturn([InfoCommand::AVAILABLE_VERSIONS => ['1.0.0', '1.0.1', '1.0.2']]);
297  $require = $this->createMock(\Composer\Package\Link::class);
298  $constraintMock = $this->createMock(\Composer\Semver\Constraint\Constraint::class);
299  $constraintMock->expects($this->any())->method('getPrettyString')
300  ->willReturn('1.0.1');
301  $require->expects($this->any())
302  ->method('getConstraint')
303  ->willReturn($constraintMock);
304 
305  $this->composerInformation->expects($this->any())
306  ->method('getPackageRequirements')
307  ->willReturn([SystemPackage::EDITION_COMMUNITY => $require]);
308  $this->assertEquals(
309  $expectedResult,
310  $this->systemPackage->getAllowedEnterpriseVersions($ceCurrentVersion)
311  );
312  }
313 
318  {
319  return [
320  ['2.0.0', []],
321  [
322  '1.0.0',
323  [
324  [
326  'versions' => [
327  [
328  'id' => '1.0.2',
329  'name' => 'Version 1.0.2 EE (latest)',
330  'current' => false,
331  ],
332  [
333  'id' => '1.0.1',
334  'name' => 'Version 1.0.1 EE',
335  'current' => false,
336  ],
337  [
338 
339  'id' => '1.0.0',
340  'name' => 'Version 1.0.0 EE',
341  'current' => false,
342  ],
343  ],
344  ],
345  ],
346  ],
347  ];
348  }
349 }
testGetAllowedEnterpriseVersions($ceCurrentVersion, $expectedResult)