Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ModuleRegistryUninstallerTest.php
Go to the documentation of this file.
1 <?php
7 
11 
12 class ModuleRegistryUninstallerTest extends \PHPUnit\Framework\TestCase
13 {
17  private $deploymentConfig;
18 
22  private $writer;
23 
27  private $loader;
28 
32  private $dataSetup;
33 
37  private $output;
38 
42  private $moduleRegistryUninstaller;
43 
44  public function setUp()
45  {
46  $this->deploymentConfig = $this->createMock(\Magento\Framework\App\DeploymentConfig::class);
47  $this->writer = $this->createMock(\Magento\Framework\App\DeploymentConfig\Writer::class);
48  $this->loader = $this->createMock(\Magento\Framework\Module\ModuleList\Loader::class);
49  $this->dataSetup = $this->createMock(\Magento\Setup\Module\DataSetup::class);
50  $dataSetupFactory = $this->createMock(\Magento\Setup\Module\DataSetupFactory::class);
51  $dataSetupFactory->expects($this->any())->method('create')->willReturn($this->dataSetup);
52  $this->output = $this->createMock(\Symfony\Component\Console\Output\OutputInterface::class);
53  $this->moduleRegistryUninstaller = new ModuleRegistryUninstaller(
54  $dataSetupFactory,
55  $this->deploymentConfig,
56  $this->writer,
57  $this->loader
58  );
59  }
60 
61  public function testRemoveModulesFromDb()
62  {
63  $this->output->expects($this->atLeastOnce())->method('writeln');
64  $this->dataSetup->expects($this->atLeastOnce())->method('deleteTableRow');
65  $this->moduleRegistryUninstaller->removeModulesFromDb($this->output, ['moduleA', 'moduleB']);
66  }
67 
69  {
70  $this->output->expects($this->atLeastOnce())->method('writeln');
71  $this->deploymentConfig->expects($this->once())
72  ->method('getConfigData')
73  ->willReturn(['moduleA' => 1, 'moduleB' => 1, 'moduleC' => 1, 'moduleD' => 1]);
74  $this->loader->expects($this->once())->method('load')->willReturn(['moduleC' => [], 'moduleD' => []]);
75  $this->writer->expects($this->once())
76  ->method('saveConfig')
77  ->with(
78  [
80  ConfigOptionsListConstants::KEY_MODULES => ['moduleC' => 1, 'moduleD' => 1]
81  ]
82  ]
83  );
84  $this->moduleRegistryUninstaller->removeModulesFromDeploymentConfig($this->output, ['moduleA', 'moduleB']);
85  }
86 }
output($string, $level=INFO, $label='')