Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ModuleUninstallerTest.php
Go to the documentation of this file.
1 <?php
7 
10 
14 class ModuleUninstallerTest extends \PHPUnit\Framework\TestCase
15 {
19  private $objectManager;
20 
24  private $remove;
25 
29  private $collector;
30 
34  private $setup;
35 
39  private $uninstaller;
40 
44  private $output;
45 
49  private $moduleRegistryUninstaller;
50 
54  private $patchApplierMock;
55 
56  public function setUp()
57  {
58  $this->moduleRegistryUninstaller = $this->createMock(\Magento\Setup\Model\ModuleRegistryUninstaller::class);
59  $this->objectManager = $this->getMockForAbstractClass(
60  \Magento\Framework\ObjectManagerInterface::class,
61  [],
62  '',
63  false
64  );
65  $objectManagerProvider = $this->createMock(\Magento\Setup\Model\ObjectManagerProvider::class);
66  $objectManagerProvider->expects($this->once())->method('get')->willReturn($this->objectManager);
67 
68  $this->remove = $this->createMock(\Magento\Framework\Composer\Remove::class);
69  $this->collector = $this->createMock(\Magento\Setup\Model\UninstallCollector::class);
70 
71  $this->setup = $this->createMock(\Magento\Setup\Module\Setup::class);
72  $this->patchApplierMock = $this->createMock(PatchApplier::class);
73  $setupFactory = $this->createMock(\Magento\Setup\Module\SetupFactory::class);
74  $setupFactory->expects($this->any())->method('create')->willReturn($this->setup);
75 
76  $this->uninstaller = new ModuleUninstaller(
77  $objectManagerProvider,
78  $this->remove,
79  $this->collector,
80  $setupFactory,
81  $this->moduleRegistryUninstaller
82  );
83 
84  $this->output = $this->createMock(\Symfony\Component\Console\Output\OutputInterface::class);
85  }
86 
87  public function testUninstallRemoveData()
88  {
89  $this->moduleRegistryUninstaller->expects($this->never())->method($this->anything());
90  $uninstall = $this->getMockForAbstractClass(\Magento\Framework\Setup\UninstallInterface::class, [], '', false);
91  $uninstall->expects($this->atLeastOnce())
92  ->method('uninstall')
93  ->with($this->setup, $this->isInstanceOf(\Magento\Setup\Model\ModuleContext::class));
94  $this->collector->expects($this->once())
95  ->method('collectUninstall')
96  ->willReturn(['moduleA' => $uninstall, 'moduleB' => $uninstall]);
97 
98  $resource = $this->createMock(\Magento\Framework\Module\ModuleResource::class);
99  $resource->expects($this->atLeastOnce())->method('getDbVersion')->willReturn('1.0');
100 
101  $this->output->expects($this->atLeastOnce())->method('writeln');
102 
103  $this->objectManager->expects($this->any())
104  ->method('get')
105  ->willReturnMap(
106  [
107  [\Magento\Framework\Module\ModuleResource::class, $resource],
108  [PatchApplier::class, $this->patchApplierMock]
109  ]
110  );
111  $this->patchApplierMock->expects($this->exactly(2))->method('revertDataPatches')->willReturnMap(
112  [
113  ['moduleA'],
114  ['moduleB']
115  ]
116  );
117  $this->uninstaller->uninstallData($this->output, ['moduleA', 'moduleB']);
118  }
119 
120  public function testUninstallRemoveCode()
121  {
122  $this->moduleRegistryUninstaller->expects($this->never())->method($this->anything());
123  $this->output->expects($this->once())->method('writeln');
124  $packageInfoFactory = $this->createMock(\Magento\Framework\Module\PackageInfoFactory::class);
125  $packageInfo = $this->createMock(\Magento\Framework\Module\PackageInfo::class);
126  $packageInfo->expects($this->atLeastOnce())->method('getPackageName');
127  $packageInfoFactory->expects($this->once())->method('create')->willReturn($packageInfo);
128  $this->objectManager->expects($this->once())
129  ->method('get')
130  ->with(\Magento\Framework\Module\PackageInfoFactory::class)
131  ->willReturn($packageInfoFactory);
132  $this->remove->expects($this->once())->method('remove');
133  $this->uninstaller->uninstallCode($this->output, ['moduleA', 'moduleB']);
134  }
135 }
output($string, $level=INFO, $label='')
$resource
Definition: bulk.php:12