Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
JobComponentUninstallTest.php
Go to the documentation of this file.
1 <?php
7 
9 use Magento\Setup\Model\Cron\ComponentUninstallerFactory;
12 
16 class JobComponentUninstallTest extends \PHPUnit\Framework\TestCase
17 {
21  private $job;
22 
26  private $output;
27 
31  private $status;
32 
36  private $updater;
37 
41  private $objectManager;
42 
46  private $objectManagerProvider;
47 
51  private $moduleUninstallHelper;
52 
56  private $themeUninstallHelper;
57 
61  private $composerInformation;
62 
66  private $quence;
67 
68  public function setUp()
69  {
70  $this->output = $this->getMockForAbstractClass(
71  \Symfony\Component\Console\Output\OutputInterface::class,
72  [],
73  '',
74  false
75  );
76  $this->status = $this->createMock(\Magento\Setup\Model\Cron\Status::class);
77  $this->moduleUninstallHelper = $this->createMock(\Magento\Setup\Model\Cron\Helper\ModuleUninstall::class);
78  $this->themeUninstallHelper = $this->createMock(\Magento\Setup\Model\Cron\Helper\ThemeUninstall::class);
79  $this->composerInformation = $this->createMock(\Magento\Framework\Composer\ComposerInformation::class);
80  $this->objectManagerProvider =
81  $this->createMock(\Magento\Setup\Model\ObjectManagerProvider::class);
82  $this->objectManager = $this->getMockForAbstractClass(
83  \Magento\Framework\ObjectManagerInterface::class,
84  [],
85  '',
86  false
87  );
88 
89  $packageInfoFactory = $this->createMock(\Magento\Framework\Module\PackageInfoFactory::class);
90  $packageInfo = $this->createMock(\Magento\Framework\Module\PackageInfo::class);
91  $packageInfoFactory->expects($this->any())->method('create')->willReturn($packageInfo);
92  $this->objectManagerProvider->expects($this->any())->method('get')->willReturn($this->objectManager);
93  $this->updater = $this->createMock(\Magento\Setup\Model\Updater::class);
94  $this->quence = $this->createPartialMock(\Magento\Setup\Model\Cron\Queue::class, ['addJobs']);
95  }
96 
97  private function setUpUpdater()
98  {
99  $this->updater->expects($this->any())->method('createUpdaterTask')->willReturn('');
100  }
101 
102  private function setUpQuence()
103  {
104  $this->quence->expects($this->once())->method('addJobs');
105  }
106 
107  public function testExecuteModule()
108  {
109  $this->setUpUpdater();
110  $this->setUpQuence();
111  $this->moduleUninstallHelper->expects($this->once())
112  ->method('uninstall')
113  ->with($this->output, 'vendor/module-package', true);
114 
115  $this->job = new JobComponentUninstall(
116  $this->composerInformation,
117  $this->moduleUninstallHelper,
118  $this->themeUninstallHelper,
119  $this->objectManagerProvider,
120  $this->output,
121  $this->quence,
122  $this->status,
123  $this->updater,
124  'setup:component:uninstall',
125  [
126  'components' => [
127  [
128  JobComponentUninstall::COMPONENT_NAME => 'vendor/module-package',
129  ]
130  ],
131  'dataOption' => 'true'
132  ]
133  );
134 
135  $this->composerInformation->expects($this->once())
136  ->method('getInstalledMagentoPackages')
137  ->willReturn(['vendor/module-package' => ['type' => ComposerInformation::MODULE_PACKAGE_TYPE]]);
138  $this->job->execute();
139  }
140 
141  public function testExecuteLanguage()
142  {
143  $this->setUpUpdater();
144  $this->setUpQuence();
145  $this->composerInformation->expects($this->once())
146  ->method('getInstalledMagentoPackages')
147  ->willReturn(['vendor/language-a' => ['type' => ComposerInformation::LANGUAGE_PACKAGE_TYPE]]);
148 
149  $this->moduleUninstallHelper->expects($this->never())->method($this->anything());
150  $this->themeUninstallHelper->expects($this->never())->method($this->anything());
151 
152  $this->job = new JobComponentUninstall(
153  $this->composerInformation,
154  $this->moduleUninstallHelper,
155  $this->themeUninstallHelper,
156  $this->objectManagerProvider,
157  $this->output,
158  $this->quence,
159  $this->status,
160  $this->updater,
161  'setup:component:uninstall',
162  [
163  'components' => [
164  [
165  JobComponentUninstall::COMPONENT_NAME => 'vendor/language-a',
166  ]
167  ]
168  ]
169  );
170  $this->job->execute();
171  }
172 
173  public function testExecuteTheme()
174  {
175  $this->setUpUpdater();
176  $this->setUpQuence();
177  $this->composerInformation->expects($this->once())
178  ->method('getInstalledMagentoPackages')
179  ->willReturn(['vendor/theme-a' => ['type' => ComposerInformation::THEME_PACKAGE_TYPE]]);
180  $this->themeUninstallHelper->expects($this->once())
181  ->method('uninstall')
182  ->with($this->output, 'vendor/theme-a');
183  $this->moduleUninstallHelper->expects($this->never())->method($this->anything());
184 
185  $this->job = new JobComponentUninstall(
186  $this->composerInformation,
187  $this->moduleUninstallHelper,
188  $this->themeUninstallHelper,
189  $this->objectManagerProvider,
190  $this->output,
191  $this->quence,
192  $this->status,
193  $this->updater,
194  'setup:component:uninstall',
195  [
196  'components' => [
197  [
198  JobComponentUninstall::COMPONENT_NAME => 'vendor/theme-a',
199  ]
200  ]
201  ]
202  );
203  $this->job->execute();
204  }
205 
210  public function testExecuteUnknownType()
211  {
212  $this->setUpUpdater();
213  $this->composerInformation->expects($this->once())
214  ->method('getInstalledMagentoPackages')
215  ->willReturn(['vendor/unknown-a' => ['type' => 'unknown']]);
216 
217  $this->moduleUninstallHelper->expects($this->never())->method($this->anything());
218  $this->themeUninstallHelper->expects($this->never())->method($this->anything());
219 
220  $this->job = new JobComponentUninstall(
221  $this->composerInformation,
222  $this->moduleUninstallHelper,
223  $this->themeUninstallHelper,
224  $this->objectManagerProvider,
225  $this->output,
226  $this->quence,
227  $this->status,
228  $this->updater,
229  'setup:component:uninstall',
230  [
231  'components' => [
232  [
233  JobComponentUninstall::COMPONENT_NAME => 'vendor/unknown-a',
234  ]
235  ]
236  ]
237  );
238  $this->job->execute();
239  }
240 
247  public function testExecuteWrongFormat(array $params)
248  {
249  $this->moduleUninstallHelper->expects($this->never())->method($this->anything());
250  $this->themeUninstallHelper->expects($this->never())->method($this->anything());
251 
252  $this->job = new JobComponentUninstall(
253  $this->composerInformation,
254  $this->moduleUninstallHelper,
255  $this->themeUninstallHelper,
256  $this->objectManagerProvider,
257  $this->output,
258  $this->quence,
259  $this->status,
260  $this->updater,
261  'setup:component:uninstall',
262  $params
263  );
264  $this->job->execute();
265  }
266 
271  {
272  return [
273  'empty' => [[]],
274  'no name' => [['components' => [['key' => 'value']]]],
275  'components not array' => [['components' => '']],
276  ];
277  }
278 
283  public function testExecuteUpdateFails()
284  {
285  $this->updater->expects($this->once())->method('createUpdaterTask')->willReturn('error');
286  $this->composerInformation->expects($this->once())
287  ->method('getInstalledMagentoPackages')
288  ->willReturn(['vendor/language-a' => ['type' => ComposerInformation::LANGUAGE_PACKAGE_TYPE]]);
289 
290  $this->job = new JobComponentUninstall(
291  $this->composerInformation,
292  $this->moduleUninstallHelper,
293  $this->themeUninstallHelper,
294  $this->objectManagerProvider,
295  $this->output,
296  $this->quence,
297  $this->status,
298  $this->updater,
299  'setup:component:uninstall',
300  [
301  'components' => [
302  [
303  JobComponentUninstall::COMPONENT_NAME => 'vendor/language-a',
304  ]
305  ]
306  ]
307  );
308  $this->job->execute();
309  }
310 }
output($string, $level=INFO, $label='')
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18