12 use Symfony\Component\Console\Tester\CommandTester;
23 private $deploymentConfig;
28 private $fullModuleList;
33 private $maintenanceMode;
38 private $uninstallCollector;
48 private $dependencyChecker;
53 private $moduleUninstaller;
58 private $moduleRegistryUninstaller;
68 private $cleanupFiles;
73 private $backupRollback;
78 private $backupRollbackFactory;
103 private $patchApplierMock;
110 $this->deploymentConfig = $this->createMock(\
Magento\Framework\
App\DeploymentConfig::class);
111 $this->fullModuleList = $this->createMock(\
Magento\Framework\
Module\FullModuleList::class);
112 $this->maintenanceMode = $this->createMock(\
Magento\Framework\
App\MaintenanceMode::class);
113 $objectManagerProvider = $this->createMock(\
Magento\Setup\Model\ObjectManagerProvider::class);
115 \
Magento\Framework\ObjectManagerInterface::class,
120 $this->uninstallCollector = $this->createMock(\
Magento\Setup\Model\UninstallCollector::class);
121 $this->packageInfo = $this->createMock(\
Magento\Framework\
Module\PackageInfo::class);
122 $packageInfoFactory = $this->createMock(\
Magento\Framework\
Module\PackageInfoFactory::class);
123 $packageInfoFactory->expects($this->once())->method(
'create')->willReturn($this->packageInfo);
124 $this->dependencyChecker = $this->createMock(\
Magento\Framework\
Module\DependencyChecker::class);
125 $this->backupRollback = $this->createMock(\
Magento\Framework\Setup\BackupRollback::class);
126 $this->backupRollbackFactory = $this->createMock(\
Magento\Framework\Setup\BackupRollbackFactory::class);
127 $this->backupRollbackFactory->expects($this->any())
129 ->willReturn($this->backupRollback);
130 $this->cache = $this->createMock(\
Magento\Framework\
App\Cache::class);
131 $this->cleanupFiles = $this->createMock(\
Magento\Framework\
App\
State\CleanupFiles::class);
132 $objectManagerProvider->expects($this->any())->method(
'get')->willReturn(
$objectManager);
133 $configLoader = $this->getMockForAbstractClass(
139 $this->patchApplierMock = $this->getMockBuilder(PatchApplier::class)
140 ->disableOriginalConstructor()
142 $configLoader->expects($this->any())->method(
'load')->willReturn([]);
145 ->will($this->returnValueMap([
146 [\
Magento\Framework\
Module\PackageInfoFactory::class, $packageInfoFactory],
147 [\
Magento\Framework\
Module\DependencyChecker::class, $this->dependencyChecker],
148 [\
Magento\Framework\
App\Cache::class, $this->cache],
149 [\
Magento\Framework\
App\
State\CleanupFiles::class, $this->cleanupFiles],
152 $this->createMock(\
Magento\Framework\
App\State::class)
154 [\
Magento\Framework\Setup\BackupRollbackFactory::class, $this->backupRollbackFactory],
155 [PatchApplier::class, $this->patchApplierMock],
158 $composer = $this->createMock(\
Magento\Framework\Composer\ComposerInformation::class);
159 $composer->expects($this->any())
160 ->method(
'getRootRequiredPackages')
161 ->willReturn([
'magento/package-a',
'magento/package-b']);
162 $this->moduleUninstaller = $this->createMock(\
Magento\Setup\Model\ModuleUninstaller::class);
163 $this->moduleRegistryUninstaller = $this->createMock(\
Magento\Setup\Model\ModuleRegistryUninstaller::class);
166 $this->deploymentConfig,
167 $this->fullModuleList,
168 $this->maintenanceMode,
169 $objectManagerProvider,
170 $this->uninstallCollector,
171 $this->moduleUninstaller,
172 $this->moduleRegistryUninstaller,
175 $this->question = $this->createMock(\Symfony\Component\Console\Helper\QuestionHelper::class);
177 ->expects($this->any())
179 ->will($this->returnValue(
true));
180 $this->helperSet = $this->createMock(\Symfony\Component\Console\Helper\HelperSet::class);
182 ->expects($this->any())
185 ->will($this->returnValue($this->question));
186 $this->command->setHelperSet($this->helperSet);
187 $this->tester =
new CommandTester($this->command);
192 $this->deploymentConfig->expects($this->once())->method(
'isAvailable')->willReturn(
false);
193 $this->tester->execute([
'module' => [
'Magento_A']]);
195 'You cannot run this command because the Magento application is not installed.' . PHP_EOL,
196 $this->tester->getDisplay()
208 array $packageInfoMap,
209 array $fullModuleListMap,
213 $this->deploymentConfig->expects($this->once())->method(
'isAvailable')->willReturn(
true);
214 $this->packageInfo->expects($this->exactly(count($input[
'module'])))
215 ->method(
'getPackageName')
216 ->will($this->returnValueMap($packageInfoMap));
217 $this->fullModuleList->expects($this->exactly(count($input[
'module'])))
219 ->will($this->returnValueMap($fullModuleListMap));
220 $this->tester->execute($input);
222 $this->assertContains(
$message, $this->tester->getDisplay());
232 'one non-composer package' => [
233 [[
'Magento_C',
'magento/package-c']],
234 [[
'Magento_C',
true]],
235 [
'module' => [
'Magento_C']],
236 [
'Magento_C is not an installed composer package']
238 'one non-composer package, one valid' => [
239 [[
'Magento_A',
'magento/package-a'], [
'Magento_C',
'magento/package-c']],
240 [[
'Magento_A',
true], [
'Magento_C',
true]],
241 [
'module' => [
'Magento_A',
'Magento_C']],
242 [
'Magento_C is not an installed composer package']
244 'two non-composer packages' => [
245 [[
'Magento_C',
'magento/package-c'], [
'Magento_D',
'magento/package-d']],
246 [[
'Magento_C',
true], [
'Magento_D',
true]],
247 [
'module' => [
'Magento_C',
'Magento_D']],
248 [
'Magento_C, Magento_D are not installed composer packages']
250 'one unknown module' => [
252 [[
'Magento_C',
false]],
253 [
'module' => [
'Magento_C']],
254 [
'Unknown module(s): Magento_C']
256 'two unknown modules' => [
257 [[
'Magento_C',
''], [
'Magento_D',
'']],
258 [[
'Magento_C',
false], [
'Magento_D',
false]],
259 [
'module' => [
'Magento_C',
'Magento_D']],
260 [
'Unknown module(s): Magento_C, Magento_D']
262 'one unknown module, one valid' => [
263 [[
'Magento_C',
''], [
'Magento_B',
'magento/package-b']],
264 [[
'Magento_C',
false], [
'Magento_B',
true]],
265 [
'module' => [
'Magento_C',
'Magento_B']],
266 [
'Unknown module(s): Magento_C']
268 'one non-composer package, one unknown module' => [
269 [[
'Magento_C',
'magento/package-c'], [
'Magento_D',
'']],
270 [[
'Magento_C',
true], [
'Magento_D',
false]],
271 [
'module' => [
'Magento_C',
'Magento_D']],
272 [
'Magento_C is not an installed composer package',
'Unknown module(s): Magento_D']
274 'two non-composer package, one unknown module' => [
275 [[
'Magento_C',
'magento/package-c'], [
'Magento_D',
''], [
'Magento_E',
'magento/package-e']],
276 [[
'Magento_C',
true], [
'Magento_D',
false], [
'Magento_E',
true]],
277 [
'module' => [
'Magento_C',
'Magento_D',
'Magento_E']],
278 [
'Magento_C, Magento_E are not installed composer packages',
'Unknown module(s): Magento_D']
280 'two non-composer package, two unknown module' => [
282 [
'Magento_C',
'magento/package-c'],
284 [
'Magento_E',
'magento/package-e'],
287 [[
'Magento_C',
true], [
'Magento_D',
false], [
'Magento_E',
true], [
'Magento_F',
false]],
288 [
'module' => [
'Magento_C',
'Magento_D',
'Magento_E',
'Magento_F']],
289 [
'Magento_C, Magento_E are not installed composer packages',
'Unknown module(s): Magento_D, Magento_F']
291 'two non-composer package, two unknown module, two valid' => [
293 [
'Magento_C',
'magento/package-c'],
295 [
'Magento_E',
'magento/package-e'],
297 [
'Magento_A',
'magento/package-a'],
298 [
'Magento_B',
'magento/package-b'],
304 [
'Magento_D',
false],
308 [
'module' => [
'Magento_A',
'Magento_B',
'Magento_C',
'Magento_D',
'Magento_E',
'Magento_F']],
309 [
'Magento_C, Magento_E are not installed composer packages',
'Unknown module(s): Magento_D, Magento_F']
314 private function setUpPassValidation()
316 $this->deploymentConfig->expects($this->once())->method(
'isAvailable')->willReturn(
true);
318 [
'Magento_A',
'magento/package-a'],
319 [
'Magento_B',
'magento/package-b'],
321 $this->packageInfo->expects($this->any())
322 ->method(
'getPackageName')
323 ->will($this->returnValueMap($packageMap));
324 $this->fullModuleList->expects($this->any())
340 $this->setUpPassValidation();
341 $this->dependencyChecker->expects($this->once())
342 ->method(
'checkDependenciesWhenDisableModules')
343 ->willReturn($dependencies);
344 $this->tester->execute($input);
346 $this->assertContains(
$message, $this->tester->getDisplay());
357 [
'Magento_A' => [
'Magento_D' => [
'Magento_D',
'Magento_A']]],
358 [
'module' => [
'Magento_A']],
360 "Cannot uninstall module 'Magento_A' because the following module(s) depend on it:" .
361 PHP_EOL .
"\tMagento_D" 365 [
'Magento_A' => [
'Magento_D' => [
'Magento_D',
'Magento_A']]],
366 [
'module' => [
'Magento_A',
'Magento_B']],
368 "Cannot uninstall module 'Magento_A' because the following module(s) depend on it:" .
369 PHP_EOL .
"\tMagento_D" 374 'Magento_A' => [
'Magento_D' => [
'Magento_D',
'Magento_A']],
375 'Magento_B' => [
'Magento_E' => [
'Magento_E',
'Magento_A']]
377 [
'module' => [
'Magento_A',
'Magento_B']],
379 "Cannot uninstall module 'Magento_A' because the following module(s) depend on it:" .
380 PHP_EOL .
"\tMagento_D",
381 "Cannot uninstall module 'Magento_B' because the following module(s) depend on it:" .
382 PHP_EOL .
"\tMagento_E" 388 private function setUpExecute()
390 $this->setUpPassValidation();
391 $this->dependencyChecker->expects($this->once())
392 ->method(
'checkDependenciesWhenDisableModules')
393 ->willReturn([
'Magento_A' => [],
'Magento_B' => []]);
394 $this->cache->expects($this->once())->method(
'clean');
395 $this->cleanupFiles->expects($this->once())->method(
'clearCodeGeneratedClasses');
400 $input = [
'module' => [
'Magento_A',
'Magento_B']];
401 $this->setUpExecute();
402 $this->moduleUninstaller->expects($this->once())
403 ->method(
'uninstallCode')
404 ->with($this->isInstanceOf(\Symfony\Component\Console\Output\OutputInterface::class), $input[
'module']);
405 $this->moduleRegistryUninstaller->expects($this->once())
406 ->method(
'removeModulesFromDb')
407 ->with($this->isInstanceOf(\Symfony\Component\Console\Output\OutputInterface::class), $input[
'module']);
408 $this->moduleRegistryUninstaller->expects($this->once())
409 ->method(
'removeModulesFromDeploymentConfig')
410 ->with($this->isInstanceOf(\Symfony\Component\Console\Output\OutputInterface::class), $input[
'module']);
411 $this->tester->execute($input);
416 $input = [
'module' => [
'Magento_A',
'Magento_B'],
'-c' =>
true];
417 $this->setUpExecute();
418 $this->moduleUninstaller->expects($this->once())
419 ->method(
'uninstallCode')
420 ->with($this->isInstanceOf(\Symfony\Component\Console\Output\OutputInterface::class), $input[
'module']);
421 $this->moduleRegistryUninstaller->expects($this->once())
422 ->method(
'removeModulesFromDb')
423 ->with($this->isInstanceOf(\Symfony\Component\Console\Output\OutputInterface::class), $input[
'module']);
424 $this->moduleRegistryUninstaller->expects($this->once())
425 ->method(
'removeModulesFromDeploymentConfig')
426 ->with($this->isInstanceOf(\Symfony\Component\Console\Output\OutputInterface::class), $input[
'module']);
427 $this->cleanupFiles->expects($this->once())->method(
'clearMaterializedViewFiles');
428 $this->tester->execute($input);
433 $input = [
'module' => [
'Magento_A',
'Magento_B'],
'-r' =>
true];
434 $this->setUpExecute();
435 $this->moduleUninstaller->expects($this->once())
436 ->method(
'uninstallData')
437 ->with($this->isInstanceOf(\Symfony\Component\Console\Output\OutputInterface::class), $input[
'module']);
438 $this->moduleUninstaller->expects($this->once())
439 ->method(
'uninstallCode')
440 ->with($this->isInstanceOf(\Symfony\Component\Console\Output\OutputInterface::class), $input[
'module']);
441 $this->moduleRegistryUninstaller->expects($this->once())
442 ->method(
'removeModulesFromDb')
443 ->with($this->isInstanceOf(\Symfony\Component\Console\Output\OutputInterface::class), $input[
'module']);
444 $this->moduleRegistryUninstaller->expects($this->once())
445 ->method(
'removeModulesFromDeploymentConfig')
446 ->with($this->isInstanceOf(\Symfony\Component\Console\Output\OutputInterface::class), $input[
'module']);
447 $this->tester->execute($input);
452 $this->deploymentConfig->expects(self::once())
453 ->method(
'isAvailable')
455 $input = [
'module' => [
'Magento_A'],
'-c' =>
true,
'-r' =>
true,
'--non-composer' =>
true];
456 $this->patchApplierMock->expects(self::once())
457 ->method(
'revertDataPatches')
459 self::assertEquals(0, $this->tester->execute($input));
464 $input = [
'module' => [
'Magento_A',
'Magento_B'],
'-c' =>
true,
'-r' =>
true];
465 $this->setUpExecute();
466 $this->moduleUninstaller->expects($this->once())
467 ->method(
'uninstallData')
468 ->with($this->isInstanceOf(\Symfony\Component\Console\Output\OutputInterface::class), $input[
'module']);
469 $this->moduleUninstaller->expects($this->once())
470 ->method(
'uninstallCode')
471 ->with($this->isInstanceOf(\Symfony\Component\Console\Output\OutputInterface::class), $input[
'module']);
472 $this->moduleRegistryUninstaller->expects($this->once())
473 ->method(
'removeModulesFromDb')
474 ->with($this->isInstanceOf(\Symfony\Component\Console\Output\OutputInterface::class), $input[
'module']);
475 $this->moduleRegistryUninstaller->expects($this->once())
476 ->method(
'removeModulesFromDeploymentConfig')
477 ->with($this->isInstanceOf(\Symfony\Component\Console\Output\OutputInterface::class), $input[
'module']);
478 $this->cleanupFiles->expects($this->once())->method(
'clearMaterializedViewFiles');
479 $this->tester->execute($input);
484 $input = [
'module' => [
'Magento_A',
'Magento_B'],
'--backup-code' =>
true];
485 $this->setUpExecute();
486 $this->moduleUninstaller->expects($this->once())
487 ->method(
'uninstallCode')
488 ->with($this->isInstanceOf(\Symfony\Component\Console\Output\OutputInterface::class), $input[
'module']);
489 $this->moduleRegistryUninstaller->expects($this->once())
490 ->method(
'removeModulesFromDb')
491 ->with($this->isInstanceOf(\Symfony\Component\Console\Output\OutputInterface::class), $input[
'module']);
492 $this->moduleRegistryUninstaller->expects($this->once())
493 ->method(
'removeModulesFromDeploymentConfig')
494 ->with($this->isInstanceOf(\Symfony\Component\Console\Output\OutputInterface::class), $input[
'module']);
495 $this->backupRollback->expects($this->once())
496 ->method(
'codeBackup')
497 ->willReturn($this->backupRollback);
498 $this->tester->execute($input);
503 $input = [
'module' => [
'Magento_A',
'Magento_B'],
'--backup-media' =>
true];
504 $this->setUpExecute();
505 $this->moduleUninstaller->expects($this->once())
506 ->method(
'uninstallCode')
507 ->with($this->isInstanceOf(\Symfony\Component\Console\Output\OutputInterface::class), $input[
'module']);
508 $this->moduleRegistryUninstaller->expects($this->once())
509 ->method(
'removeModulesFromDb')
510 ->with($this->isInstanceOf(\Symfony\Component\Console\Output\OutputInterface::class), $input[
'module']);
511 $this->moduleRegistryUninstaller->expects($this->once())
512 ->method(
'removeModulesFromDeploymentConfig')
513 ->with($this->isInstanceOf(\Symfony\Component\Console\Output\OutputInterface::class), $input[
'module']);
514 $this->backupRollback->expects($this->once())
515 ->method(
'codeBackup')
516 ->willReturn($this->backupRollback);
517 $this->tester->execute($input);
522 $input = [
'module' => [
'Magento_A',
'Magento_B'],
'--backup-db' =>
true];
523 $this->setUpExecute();
524 $this->moduleUninstaller->expects($this->once())
525 ->method(
'uninstallCode')
526 ->with($this->isInstanceOf(\Symfony\Component\Console\Output\OutputInterface::class), $input[
'module']);
527 $this->moduleRegistryUninstaller->expects($this->once())
528 ->method(
'removeModulesFromDb')
529 ->with($this->isInstanceOf(\Symfony\Component\Console\Output\OutputInterface::class), $input[
'module']);
530 $this->moduleRegistryUninstaller->expects($this->once())
531 ->method(
'removeModulesFromDeploymentConfig')
532 ->with($this->isInstanceOf(\Symfony\Component\Console\Output\OutputInterface::class), $input[
'module']);
533 $this->backupRollback->expects($this->once())
535 ->willReturn($this->backupRollback);
536 $this->tester->execute($input);
541 $input = [
'module' => [
'Magento_A',
'Magento_B']];
542 $this->setUpExecute();
543 $this->moduleUninstaller->expects($this->once())
544 ->method(
'uninstallCode')
545 ->with($this->isInstanceOf(\Symfony\Component\Console\Output\OutputInterface::class), $input[
'module']);
546 $this->moduleRegistryUninstaller->expects($this->once())
547 ->method(
'removeModulesFromDb')
548 ->with($this->isInstanceOf(\Symfony\Component\Console\Output\OutputInterface::class), $input[
'module']);
549 $this->moduleRegistryUninstaller->expects($this->once())
550 ->method(
'removeModulesFromDeploymentConfig')
551 ->with($this->isInstanceOf(\Symfony\Component\Console\Output\OutputInterface::class), $input[
'module']);
553 ->expects($this->once())
555 ->will($this->returnValue(
false));
557 ->expects($this->once())
560 ->will($this->returnValue($this->question));
561 $this->command->setHelperSet($this->helperSet);
562 $this->tester =
new CommandTester($this->command);
563 $this->tester->execute($input);
testExecuteFailedDependencies(array $dependencies, array $input, array $expect)
executeFailedDependenciesDataProvider()
testExecuteApplicationNotInstalled()
testExecuteNonComposerModules()
testExecuteFailedValidation(array $packageInfoMap, array $fullModuleListMap, array $input, array $expect)
executeFailedValidationDataProvider()
testExecuteClearStaticContent()