Skip to content

Commit 9d97762

Browse files
author
Sergey Nosov
committed
Merge remote-tracking branch 'origin/MDVA-267' into 2.0.6_backlog
2 parents 5702983 + 78e87b3 commit 9d97762

File tree

18 files changed

+660
-311
lines changed

18 files changed

+660
-311
lines changed

dev/tests/integration/testsuite/Magento/Setup/Controller/ComponentGridTest.php

Lines changed: 5 additions & 227 deletions
Original file line numberDiff line numberDiff line change
@@ -15,73 +15,13 @@
1515
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1616
use Magento\Setup\Model\MarketplaceManager;
1717

18+
/**
19+
* @deprecated
20+
*
21+
* @link setup/src/Magento/Setup/Test/Unit/Controller/ComponentGridTest.php
22+
*/
1823
class ComponentGridTest extends \PHPUnit_Framework_TestCase
1924
{
20-
/**
21-
* @var ComposerInformation|\PHPUnit_Framework_MockObject_MockObject
22-
*/
23-
private $composerInformationMock;
24-
25-
/**
26-
* @var UpdatePackagesCache|\PHPUnit_Framework_MockObject_MockObject
27-
*/
28-
private $updatePackagesCacheMock;
29-
30-
/**
31-
* @var TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject
32-
*
33-
*/
34-
private $timezoneMock;
35-
36-
/**
37-
* @var FullModuleList|\PHPUnit_Framework_MockObject_MockObject
38-
*/
39-
private $fullModuleListMock;
40-
41-
/**
42-
* @var ModuleList|\PHPUnit_Framework_MockObject_MockObject
43-
*/
44-
private $enabledModuleListMock;
45-
46-
/**
47-
* @var PackageInfoFactory|\PHPUnit_Framework_MockObject_MockObject
48-
*/
49-
private $packageInfoFactoryMock;
50-
51-
/**
52-
* Module package info
53-
*
54-
* @var PackageInfo
55-
*/
56-
private $packageInfo;
57-
58-
/**
59-
* Controller
60-
*
61-
* @var ComponentGrid
62-
*/
63-
private $controller;
64-
65-
/**
66-
* @var MarketplaceManager
67-
*/
68-
private $marketplaceManagerMock;
69-
70-
/**
71-
* @var array
72-
*/
73-
private $componentData = [];
74-
75-
/**
76-
* @var array
77-
*/
78-
private $lastSyncData = [];
79-
80-
/**
81-
* @var array
82-
*/
83-
private $convertedLastSyncDate = [];
84-
8525
/**#@+
8626
* Canned formatted date and time to return from mock
8727
*/
@@ -91,179 +31,17 @@ class ComponentGridTest extends \PHPUnit_Framework_TestCase
9131

9232
public function setUp()
9333
{
94-
$this->convertedLastSyncDate = [
95-
'lastSyncDate' => [
96-
'date' => self::FORMATTED_DATE,
97-
'time' => self::FORMATTED_TIME,
98-
],
99-
];
100-
101-
$this->lastSyncData = [
102-
"lastSyncDate" => "1447271496",
103-
"packages" => [
104-
'magento/sample-module-one' => [
105-
'name' => 'magento/sample-module-one',
106-
'type' => 'magento2-module',
107-
'version' => '1.0.0'
108-
]
109-
],
110-
'countOfInstall' => 0,
111-
'countOfUpdate' => 1
112-
];
113-
$this->componentData = [
114-
'magento/sample-module-one' => [
115-
'name' => 'magento/sample-module-one',
116-
'type' => 'magento2-module',
117-
'version' => '1.0.0'
118-
]
119-
];
120-
$allComponentData = [
121-
'magento/sample-module-two' => [
122-
'name' => 'magento/sample-module-two',
123-
'type' => 'magento2-module',
124-
'version' => '1.0.0'
125-
]
126-
];
127-
$allComponentData = array_merge($allComponentData, $this->componentData);
128-
$this->composerInformationMock = $this->getMock(
129-
'Magento\Framework\Composer\ComposerInformation',
130-
[],
131-
[],
132-
'',
133-
false
134-
);
135-
$objectManagerProvider = $this->getMock('Magento\Setup\Model\ObjectManagerProvider', [], [], '', false);
136-
$objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface', [], [], '', false);
137-
$objectManagerProvider->expects($this->once())
138-
->method('get')
139-
->willReturn($objectManager);
140-
$this->packageInfoFactoryMock = $this
141-
->getMock('Magento\Framework\Module\PackageInfoFactory', [], [], '', false);
142-
$this->enabledModuleListMock = $this->getMock('Magento\Framework\Module\ModuleList', [], [], '', false);
143-
$this->enabledModuleListMock->expects($this->any())->method('has')->willReturn(true);
144-
$this->fullModuleListMock = $this->getMock('Magento\Framework\Module\FullModuleList', [], [], '', false);
145-
$this->fullModuleListMock->expects($this->any())->method('getNames')->willReturn($allComponentData);
146-
$this->timezoneMock = $this->getMock('Magento\Framework\Stdlib\DateTime\TimezoneInterface', [], [], '', false);
147-
$objectManager->expects($this->exactly(4))
148-
->method('get')
149-
->willReturnMap([
150-
['Magento\Framework\Module\PackageInfoFactory', $this->packageInfoFactoryMock],
151-
['Magento\Framework\Module\FullModuleList', $this->fullModuleListMock],
152-
['Magento\Framework\Module\ModuleList', $this->enabledModuleListMock],
153-
['Magento\Framework\Stdlib\DateTime\TimezoneInterface', $this->timezoneMock]
154-
]);
155-
$this->packageInfo = $this->getMock('Magento\Framework\Module\PackageInfo', [], [], '', false);
156-
$this->updatePackagesCacheMock = $this->getMock('Magento\Setup\Model\UpdatePackagesCache', [], [], '', false);
157-
$this->marketplaceManagerMock = $this->getMock('Magento\Setup\Model\MarketplaceManager', [], [], '', false);
158-
$this->packageInfoFactoryMock->expects($this->once())->method('create')->willReturn($this->packageInfo);
159-
$this->controller = new ComponentGrid(
160-
$this->composerInformationMock,
161-
$objectManagerProvider,
162-
$this->updatePackagesCacheMock,
163-
$this->marketplaceManagerMock
164-
);
16534
}
16635

16736
public function testIndexAction()
16837
{
169-
$viewModel = $this->controller->indexAction();
170-
$this->assertInstanceOf('Zend\View\Model\ViewModel', $viewModel);
171-
$this->assertTrue($viewModel->terminate());
17238
}
17339

17440
public function testComponentsAction()
17541
{
176-
$this->fullModuleListMock->expects($this->once())
177-
->method('getNames')
178-
->willReturn(['magento/sample-module1']);
179-
$this->packageInfo->expects($this->once())
180-
->method('getModuleName')
181-
->willReturn('Sample_Module');
182-
$this->packageInfo->expects($this->exactly(2))
183-
->method('getPackageName')
184-
->willReturn($this->componentData['magento/sample-module-one']['name']);
185-
$this->packageInfo->expects($this->exactly(2))
186-
->method('getVersion')
187-
->willReturn($this->componentData['magento/sample-module-one']['version']);
188-
$this->enabledModuleListMock->expects($this->once())
189-
->method('has')
190-
->willReturn(true);
191-
$this->composerInformationMock->expects($this->once())
192-
->method('getInstalledMagentoPackages')
193-
->willReturn($this->componentData);
194-
$this->composerInformationMock->expects($this->once())
195-
->method('isPackageInComposerJson')
196-
->willReturn(true);
197-
$this->updatePackagesCacheMock->expects($this->once())
198-
->method('getPackagesForUpdate')
199-
->willReturn($this->lastSyncData);
200-
$this->setupTimezoneMock();
201-
$jsonModel = $this->controller->componentsAction();
202-
$this->assertInstanceOf('Zend\View\Model\JsonModel', $jsonModel);
203-
$variables = $jsonModel->getVariables();
204-
$this->assertArrayHasKey('success', $variables);
205-
$this->assertTrue($variables['success']);
206-
$expected = [[
207-
'name' => 'magento/sample-module-one',
208-
'type' => 'magento2-module',
209-
'version' => '1.0.0',
210-
'update' => false,
211-
'uninstall' => true,
212-
'vendor' => 'magento',
213-
'moduleName' => 'Sample_Module',
214-
'enable' => true,
215-
'disable' => false
216-
]];
217-
$this->assertEquals($expected, $variables['components']);
218-
$this->assertArrayHasKey('total', $variables);
219-
$this->assertEquals(1, $variables['total']);
220-
$expectedLastSyncData = array_replace($this->lastSyncData, $this->convertedLastSyncDate);
221-
$this->assertEquals($expectedLastSyncData, $variables['lastSyncData']);
22242
}
22343

22444
public function testSyncAction()
22545
{
226-
$this->updatePackagesCacheMock->expects($this->once())
227-
->method('syncPackagesForUpdate');
228-
$this->updatePackagesCacheMock->expects($this->once())
229-
->method('getPackagesForUpdate')
230-
->willReturn($this->lastSyncData);
231-
$this->setupTimezoneMock();
232-
$jsonModel = $this->controller->syncAction();
233-
$this->assertInstanceOf('Zend\View\Model\JsonModel', $jsonModel);
234-
$variables = $jsonModel->getVariables();
235-
$this->assertArrayHasKey('success', $variables);
236-
$this->assertTrue($variables['success']);
237-
$expectedLastSyncData = array_replace($this->lastSyncData, $this->convertedLastSyncDate);
238-
$this->assertEquals($expectedLastSyncData, $variables['lastSyncData']);
239-
}
240-
241-
/**
242-
* Prepare the timezone mock to expect calls and return formatted date and time
243-
*
244-
* @return none
245-
*/
246-
private function setupTimezoneMock()
247-
{
248-
$this->timezoneMock->expects($this->at(0))
249-
->method('formatDateTime')
250-
->with(
251-
$this->isInstanceOf('\DateTime'),
252-
\IntlDateFormatter::MEDIUM,
253-
\IntlDateFormatter::NONE,
254-
null,
255-
null,
256-
null
257-
)->willReturn(self::FORMATTED_DATE);
258-
$this->timezoneMock->expects($this->at(1))
259-
->method('formatDateTime')
260-
->with(
261-
$this->isInstanceOf('\DateTime'),
262-
\IntlDateFormatter::NONE,
263-
\IntlDateFormatter::MEDIUM,
264-
null,
265-
null,
266-
null
267-
)->willReturn(self::FORMATTED_TIME);
26846
}
26947
}

dev/tests/integration/testsuite/Magento/Setup/Model/UpdatePackagesCacheTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Magento\TestFramework\Helper\Bootstrap;
1010
use Magento\Framework\Composer\ComposerJsonFinder;
1111
use Magento\Framework\Composer\MagentoComposerApplicationFactory;
12-
use Magento\Setup\Model\UpdatePackagesCache;
1312

1413
/**
1514
* Tests Magento\Framework\ComposerInformation
@@ -81,12 +80,6 @@ public function testGetPackagesForUpdate()
8180

8281
$this->setupDirectory('testSkeleton');
8382

84-
$objectManagerProvider = $this->getMock('Magento\Setup\Model\ObjectManagerProvider', [], [], '', false);
85-
$objectManagerProvider
86-
->expects($this->any())
87-
->method('get')
88-
->willReturn($this->objectManager);
89-
9083
/** @var UpdatePackagesCache $updatePackagesCache|\PHPUnit_Framework_MockObject_MockObject */
9184
$updatePackagesCache = $this->getMock('Magento\Setup\Model\UpdatePackagesCache', [], [], '', false);
9285

lib/internal/Magento/Framework/ObjectManager/ObjectManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ObjectManager implements \Magento\Framework\ObjectManagerInterface
2727
protected $_sharedInstances = [];
2828

2929
/**
30-
* @var Config\Config
30+
* @var ConfigInterface
3131
*/
3232
protected $_config;
3333

setup/src/Magento/Setup/Controller/ComponentGrid.php

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace Magento\Setup\Controller;
88

9+
use Magento\Setup\Model\DateTime\TimezoneProvider;
10+
911
/**
1012
* Controller for component grid tasks
1113
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -51,11 +53,16 @@ class ComponentGrid extends \Zend\Mvc\Controller\AbstractActionController
5153
*/
5254
private $timezone;
5355

56+
/**
57+
* @var \Magento\Framework\ObjectManagerInterface
58+
*/
59+
private $objectManager;
60+
5461
/**
5562
* @param \Magento\Framework\Composer\ComposerInformation $composerInformation
5663
* @param \Magento\Setup\Model\ObjectManagerProvider $objectManagerProvider
57-
* @param \Magento\Setup\Model\MarketplaceManager $marketplaceManager
5864
* @param \Magento\Setup\Model\UpdatePackagesCache $updatePackagesCache
65+
* @param \Magento\Setup\Model\MarketplaceManager $marketplaceManager
5966
*/
6067
public function __construct(
6168
\Magento\Framework\Composer\ComposerInformation $composerInformation,
@@ -64,13 +71,40 @@ public function __construct(
6471
\Magento\Setup\Model\MarketplaceManager $marketplaceManager
6572
) {
6673
$this->composerInformation = $composerInformation;
67-
$objectManager = $objectManagerProvider->get();
68-
$this->enabledModuleList = $objectManager->get('Magento\Framework\Module\ModuleList');
69-
$this->fullModuleList = $objectManager->get('Magento\Framework\Module\FullModuleList');
70-
$this->packageInfo = $objectManager->get('Magento\Framework\Module\PackageInfoFactory')->create();
74+
$this->objectManager = $objectManagerProvider->get();
75+
$this->enabledModuleList = $this->objectManager->get('Magento\Framework\Module\ModuleList');
76+
$this->fullModuleList = $this->objectManager->get('Magento\Framework\Module\FullModuleList');
77+
$this->packageInfo = $this->objectManager->get('Magento\Framework\Module\PackageInfoFactory')->create();
7178
$this->marketplaceManager = $marketplaceManager;
7279
$this->updatePackagesCache = $updatePackagesCache;
73-
$this->timezone = $objectManager->get('Magento\Framework\Stdlib\DateTime\TimezoneInterface');
80+
}
81+
82+
/**
83+
* Get timezone
84+
*
85+
* @return \Magento\Framework\Stdlib\DateTime\TimezoneInterface|null
86+
*/
87+
private function getTimezone()
88+
{
89+
if ($this->timezone === null) {
90+
$this->timezone = $this->objectManager->get('Magento\Setup\Model\DateTime\TimezoneProvider')->get();
91+
}
92+
return $this->timezone;
93+
}
94+
95+
/**
96+
* Set timezone
97+
*
98+
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone
99+
* @return void
100+
* @throws \Exception
101+
*/
102+
public function setTimezone(\Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone)
103+
{
104+
if ($this->timezone !== null) {
105+
throw new \Exception('timezone is already set');
106+
}
107+
$this->timezone = $timezone;
74108
}
75109

76110
/**
@@ -214,12 +248,12 @@ private function formatLastSyncData($packagesForInstall, $lastSyncData)
214248
private function formatSyncDate($syncDate)
215249
{
216250
return [
217-
'date' => $this->timezone->formatDateTime(
251+
'date' => $this->getTimezone()->formatDateTime(
218252
new \DateTime('@'.$syncDate),
219253
\IntlDateFormatter::MEDIUM,
220254
\IntlDateFormatter::NONE
221255
),
222-
'time' => $this->timezone->formatDateTime(
256+
'time' => $this->getTimezone()->formatDateTime(
223257
new \DateTime('@'.$syncDate),
224258
\IntlDateFormatter::NONE,
225259
\IntlDateFormatter::MEDIUM

setup/src/Magento/Setup/Model/ConfigGenerator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ public function __construct(Random $random, DeploymentConfig $deploymentConfig)
6464
/**
6565
* Creates install segment config data
6666
*
67+
* @deprecated
68+
*
6769
* @return ConfigData
6870
*/
6971
public function createInstallConfig()

setup/src/Magento/Setup/Model/ConfigOptionsList.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ public function getOptions()
163163
public function createConfig(array $data, DeploymentConfig $deploymentConfig)
164164
{
165165
$configData = [];
166-
$configData[] = $this->configGenerator->createInstallConfig($deploymentConfig);
167166
$configData[] = $this->configGenerator->createCryptConfig($data, $deploymentConfig);
168167
$configData[] = $this->configGenerator->createSessionConfig($data);
169168
$definitionConfig = $this->configGenerator->createDefinitionsConfig($data);

0 commit comments

Comments
 (0)