Skip to content

Commit 9dd64b9

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-51369-cli-extension-check' into PR_Branch
2 parents 8884b3f + cf46c07 commit 9dd64b9

File tree

4 files changed

+90
-29
lines changed

4 files changed

+90
-29
lines changed

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Magento\Framework\Setup\UpgradeDataInterface;
2828
use Magento\Framework\Setup\SchemaSetupInterface;
2929
use Magento\Framework\Setup\ModuleDataSetupInterface;
30+
use Magento\Setup\Controller\ResponseTypeInterface;
3031
use Magento\Setup\Model\ConfigModel as SetupConfigModel;
3132
use Magento\Setup\Module\DataSetupFactory;
3233
use Magento\Setup\Module\SetupFactory;
@@ -220,6 +221,11 @@ class Installer
220221
*/
221222
private $componentRegistrar;
222223

224+
/**
225+
* @var PhpReadinessCheck
226+
*/
227+
private $phpReadinessCheck;
228+
223229
/**
224230
* Constructor
225231
*
@@ -243,6 +249,7 @@ class Installer
243249
* @param DataSetupFactory $dataSetupFactory
244250
* @param \Magento\Framework\Setup\SampleData\State $sampleDataState
245251
* @param ComponentRegistrar $componentRegistrar
252+
* @param PhpReadinessCheck $phpReadinessCheck
246253
*
247254
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
248255
*/
@@ -266,7 +273,8 @@ public function __construct(
266273
SetupFactory $setupFactory,
267274
DataSetupFactory $dataSetupFactory,
268275
\Magento\Framework\Setup\SampleData\State $sampleDataState,
269-
ComponentRegistrar $componentRegistrar
276+
ComponentRegistrar $componentRegistrar,
277+
PhpReadinessCheck $phpReadinessCheck
270278
) {
271279
$this->filePermissions = $filePermissions;
272280
$this->deploymentConfigWriter = $deploymentConfigWriter;
@@ -289,6 +297,7 @@ public function __construct(
289297
$this->dataSetupFactory = $dataSetupFactory;
290298
$this->sampleDataState = $sampleDataState;
291299
$this->componentRegistrar = $componentRegistrar;
300+
$this->phpReadinessCheck = $phpReadinessCheck;
292301
}
293302

294303
/**
@@ -301,6 +310,7 @@ public function __construct(
301310
public function install($request)
302311
{
303312
$script[] = ['File permissions check...', 'checkInstallationFilePermissions', []];
313+
$script[] = ['Required extensions check...', 'checkExtensions', []];
304314
$script[] = ['Enabling Maintenance Mode...', 'setMaintenanceMode', [1]];
305315
$script[] = ['Installing deployment configuration...', 'installDeploymentConfig', [$request]];
306316
if (!empty($request[InstallCommand::INPUT_KEY_CLEANUP_DB])) {
@@ -457,6 +467,24 @@ public function checkInstallationFilePermissions()
457467
}
458468
}
459469

470+
/**
471+
* Check required extensions for installation
472+
*
473+
* @return void
474+
* @throws \Exception
475+
*/
476+
public function checkExtensions()
477+
{
478+
$phpExtensionsCheckResult = $this->phpReadinessCheck->checkPhpExtensions();
479+
if ($phpExtensionsCheckResult['responseType'] === ResponseTypeInterface::RESPONSE_TYPE_ERROR
480+
&& isset($phpExtensionsCheckResult['data']['missing'])
481+
) {
482+
$errorMsg = "Missing following extensions: '"
483+
. implode("' '", $phpExtensionsCheckResult['data']['missing']) . "'";
484+
throw new \Exception($errorMsg);
485+
}
486+
}
487+
460488
/**
461489
* Check permissions of directories that are expected to be non-writable for application
462490
*

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ public function create(LoggerInterface $log)
7373
$this->serviceLocator->get('Magento\Setup\Module\SetupFactory'),
7474
$this->serviceLocator->get('Magento\Setup\Module\DataSetupFactory'),
7575
$this->serviceLocator->get('Magento\Framework\Setup\SampleData\State'),
76-
new \Magento\Framework\Component\ComponentRegistrar()
76+
new \Magento\Framework\Component\ComponentRegistrar(),
77+
$this->serviceLocator->get('Magento\Setup\Model\PhpReadinessCheck')
7778
);
7879
}
7980

setup/src/Magento/Setup/Test/Unit/Model/InstallerFactoryTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,13 @@ public function testCreate()
8989
'Magento\Framework\Setup\SampleData\State',
9090
$this->getMock('Magento\Framework\Setup\SampleData\State', [], [], '', false),
9191
],
92+
[
93+
'Magento\Setup\Model\PhpReadinessCheck',
94+
$this->getMock('Magento\Setup\Model\PhpReadinessCheck', [], [], '', false),
95+
],
9296
];
9397
$serviceLocatorMock = $this->getMockForAbstractClass('Zend\ServiceManager\ServiceLocatorInterface', ['get']);
94-
$serviceLocatorMock
95-
->expects($this->any())
96-
->method('get')
97-
->will($this->returnValueMap($returnValueMap));
98+
$serviceLocatorMock->expects($this->any())->method('get')->will($this->returnValueMap($returnValueMap));
9899

99100
$log = $this->getMockForAbstractClass('Magento\Framework\Setup\LoggerInterface');
100101
$resourceFactoryMock = $this->getMock('Magento\Setup\Module\ResourceFactory', [], [], '', false);

setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ class InstallerTest extends \PHPUnit_Framework_TestCase
131131
*/
132132
private $componentRegistrar;
133133

134+
/**
135+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\PhpReadinessCheck
136+
*/
137+
private $phpReadinessCheck;
138+
134139
/**
135140
* Sample DB configuration segment
136141
*
@@ -179,6 +184,7 @@ protected function setUp()
179184
$this->dataSetupFactory = $this->getMock('Magento\Setup\Module\DataSetupFactory', [], [], '', false);
180185
$this->sampleDataState = $this->getMock('Magento\Framework\Setup\SampleData\State', [], [], '', false);
181186
$this->componentRegistrar = $this->getMock('Magento\Framework\Component\ComponentRegistrar', [], [], '', false);
187+
$this->phpReadinessCheck = $this->getMock('Magento\Setup\Model\PhpReadinessCheck', [], [], '', false);
182188
$this->object = $this->createObject();
183189
}
184190

@@ -220,7 +226,8 @@ private function createObject($connectionFactory = false, $objectManagerProvider
220226
$this->setupFactory,
221227
$this->dataSetupFactory,
222228
$this->sampleDataState,
223-
$this->componentRegistrar
229+
$this->componentRegistrar,
230+
$this->phpReadinessCheck
224231
);
225232
}
226233

@@ -280,33 +287,36 @@ public function testInstall()
280287
$this->getMock('Magento\Setup\Model\AdminAccount', [], [], '', false)
281288
);
282289
$this->sampleDataState->expects($this->once())->method('hasError')->willReturn(true);
290+
$this->phpReadinessCheck->expects($this->once())->method('checkPhpExtensions')->willReturn(
291+
['responseType' => \Magento\Setup\Controller\ResponseTypeInterface::RESPONSE_TYPE_SUCCESS]
292+
);
283293

284294
$this->logger->expects($this->at(0))->method('log')->with('Starting Magento installation:');
285295
$this->logger->expects($this->at(1))->method('log')->with('File permissions check...');
296+
$this->logger->expects($this->at(3))->method('log')->with('Required extensions check...');
286297
// at(2) invokes logMeta()
287-
$this->logger->expects($this->at(3))->method('log')->with('Enabling Maintenance Mode...');
298+
$this->logger->expects($this->at(5))->method('log')->with('Enabling Maintenance Mode...');
288299
// at(4) - logMeta and so on...
289-
$this->logger->expects($this->at(5))->method('log')->with('Installing deployment configuration...');
290-
$this->logger->expects($this->at(7))->method('log')->with('Installing database schema:');
291-
$this->logger->expects($this->at(9))->method('log')->with("Module 'Foo_One':");
292-
$this->logger->expects($this->at(11))->method('log')->with("Module 'Bar_Two':");
293-
$this->logger->expects($this->at(13))->method('log')->with('Schema post-updates:');
294-
$this->logger->expects($this->at(14))->method('log')->with("Module 'Foo_One':");
295-
$this->logger->expects($this->at(16))->method('log')->with("Module 'Bar_Two':");
296-
$this->logger->expects($this->at(19))->method('log')->with('Installing user configuration...');
297-
$this->logger->expects($this->at(21))->method('log')->with('Enabling caches:');
298-
$this->logger->expects($this->at(25))->method('log')->with('Installing data...');
299-
$this->logger->expects($this->at(26))->method('log')->with('Data install/update:');
300-
$this->logger->expects($this->at(27))->method('log')->with("Module 'Foo_One':");
301-
$this->logger->expects($this->at(29))->method('log')->with("Module 'Bar_Two':");
302-
$this->logger->expects($this->at(31))->method('log')->with('Data post-updates:');
303-
$this->logger->expects($this->at(32))->method('log')->with("Module 'Foo_One':");
304-
$this->logger->expects($this->at(34))->method('log')->with("Module 'Bar_Two':");
305-
$this->logger->expects($this->at(37))->method('log')->with('Installing admin user...');
306-
$this->logger->expects($this->at(39))->method('log')->with('Caches clearing:');
307-
$this->logger->expects($this->at(42))->method('log')->with('Disabling Maintenance Mode:');
308-
$this->logger->expects($this->at(44))->method('log')->with('Post installation file permissions check...');
309-
$this->logger->expects($this->at(46))->method('log')->with('Write installation date...');
300+
$this->logger->expects($this->at(7))->method('log')->with('Installing deployment configuration...');
301+
$this->logger->expects($this->at(9))->method('log')->with('Installing database schema:');
302+
$this->logger->expects($this->at(11))->method('log')->with("Module 'Foo_One':");
303+
$this->logger->expects($this->at(13))->method('log')->with("Module 'Bar_Two':");
304+
$this->logger->expects($this->at(15))->method('log')->with('Schema post-updates:');
305+
$this->logger->expects($this->at(16))->method('log')->with("Module 'Foo_One':");
306+
$this->logger->expects($this->at(18))->method('log')->with("Module 'Bar_Two':");
307+
$this->logger->expects($this->at(21))->method('log')->with('Installing user configuration...');
308+
$this->logger->expects($this->at(23))->method('log')->with('Enabling caches:');
309+
$this->logger->expects($this->at(27))->method('log')->with('Installing data...');
310+
$this->logger->expects($this->at(28))->method('log')->with('Data install/update:');
311+
$this->logger->expects($this->at(29))->method('log')->with("Module 'Foo_One':");
312+
$this->logger->expects($this->at(31))->method('log')->with("Module 'Bar_Two':");
313+
$this->logger->expects($this->at(33))->method('log')->with('Data post-updates:');
314+
$this->logger->expects($this->at(34))->method('log')->with("Module 'Foo_One':");
315+
$this->logger->expects($this->at(36))->method('log')->with("Module 'Bar_Two':");
316+
$this->logger->expects($this->at(39))->method('log')->with('Installing admin user...');
317+
$this->logger->expects($this->at(41))->method('log')->with('Caches clearing:');
318+
$this->logger->expects($this->at(44))->method('log')->with('Disabling Maintenance Mode:');
319+
$this->logger->expects($this->at(46))->method('log')->with('Post installation file permissions check...');
310320
$this->logger->expects($this->at(48))->method('logSuccess')->with('Magento installation complete.');
311321
$this->logger->expects($this->at(50))->method('log')
312322
->with('Sample Data is installed with errors. See log file for details');
@@ -335,6 +345,27 @@ public function testCheckInstallationFilePermissionsError()
335345
$this->object->checkInstallationFilePermissions();
336346
}
337347

348+
public function testCheckExtensions()
349+
{
350+
$this->phpReadinessCheck->expects($this->once())->method('checkPhpExtensions')->willReturn(
351+
['responseType' => \Magento\Setup\Controller\ResponseTypeInterface::RESPONSE_TYPE_SUCCESS]
352+
);
353+
$this->object->checkExtensions();
354+
}
355+
356+
/**
357+
* @expectedException \Exception
358+
* @expectedExceptionMessage Missing following extensions: 'foo'
359+
*/
360+
public function testCheckExtensionsError()
361+
{
362+
$this->phpReadinessCheck->expects($this->once())->method('checkPhpExtensions')->willReturn(
363+
['responseType' => \Magento\Setup\Controller\ResponseTypeInterface::RESPONSE_TYPE_ERROR,
364+
'data'=>['required'=>['foo', 'bar'], 'missing'=>['foo']]]
365+
);
366+
$this->object->checkExtensions();
367+
}
368+
338369
public function testCheckApplicationFilePermissions()
339370
{
340371
$this->filePermissions

0 commit comments

Comments
 (0)