Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
JobModuleTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class JobModuleTest extends \PHPUnit\Framework\TestCase
11 {
12  public function testExecuteModuleDisable()
13  {
14  $objectManagerProvider = $this->createMock(\Magento\Setup\Model\ObjectManagerProvider::class);
16  $this->getMockForAbstractClass(\Magento\Framework\ObjectManagerInterface::class, [], '', false);
17  $cleanupFiles = $this->createMock(\Magento\Framework\App\State\CleanupFiles::class);
18  $cleanupFiles->expects($this->once())->method('clearCodeGeneratedFiles');
19  $cache = $this->createMock(\Magento\Framework\App\Cache::class);
20  $cache->expects($this->once())->method('clean');
21  $valueMap = [
22  [\Magento\Framework\Module\PackageInfoFactory::class],
23  [\Magento\Framework\App\State\CleanupFiles::class, $cleanupFiles],
24  [\Magento\Framework\App\Cache::class, $cache],
25  ];
26  $objectManager->expects($this->atLeastOnce())->method('get')->will($this->returnValueMap($valueMap));
27  $objectManagerProvider->expects($this->once())->method('get')->willReturn($objectManager);
28  $command = $this->createMock(\Magento\Setup\Console\Command\ModuleDisableCommand::class);
29  $command->expects($this->once())->method('run');
30  $status = $this->createMock(\Magento\Setup\Model\Cron\Status::class);
31  $status->expects($this->atLeastOnce())->method('add');
32  $output =
33  $this->getMockForAbstractClass(\Symfony\Component\Console\Output\OutputInterface::class, [], '', false);
34  $params['components'][] = ['name' => 'vendor/module'];
35  $jobModuleDisable = new JobModule(
36  $command,
37  $objectManagerProvider,
38  $output,
39  $status,
40  'setup:module:disable',
41  $params
42  );
43  $jobModuleDisable->execute();
44  }
45 
46  public function testExecuteModuleEnable()
47  {
48  $objectManagerProvider = $this->createMock(\Magento\Setup\Model\ObjectManagerProvider::class);
50  $this->getMockForAbstractClass(\Magento\Framework\ObjectManagerInterface::class, [], '', false);
51  $cleanupFiles = $this->createMock(\Magento\Framework\App\State\CleanupFiles::class);
52  $cleanupFiles->expects($this->once())->method('clearCodeGeneratedFiles');
53  $cache = $this->createMock(\Magento\Framework\App\Cache::class);
54  $cache->expects($this->once())->method('clean');
55  $valueMap = [
56  [\Magento\Framework\Module\PackageInfoFactory::class],
57  [\Magento\Framework\App\State\CleanupFiles::class, $cleanupFiles],
58  [\Magento\Framework\App\Cache::class, $cache],
59  ];
60  $objectManager->expects($this->atLeastOnce())->method('get')->will($this->returnValueMap($valueMap));
61  $objectManagerProvider->expects($this->once())->method('get')->willReturn($objectManager);
62  $command = $this->createMock(\Magento\Setup\Console\Command\ModuleEnableCommand::class);
63  $command->expects($this->once())->method('run');
64  $status = $this->createMock(\Magento\Setup\Model\Cron\Status::class);
65  $status->expects($this->atLeastOnce())->method('add');
66  $output =
67  $this->getMockForAbstractClass(\Symfony\Component\Console\Output\OutputInterface::class, [], '', false);
68  $params['components'][] = ['name' => 'vendor/module'];
69  $jobModuleEnable = new JobModule(
70  $command,
71  $objectManagerProvider,
72  $output,
73  $status,
74  'setup:module:enable',
75  $params
76  );
77  $jobModuleEnable->execute();
78  }
79 }
$objectManager
Definition: bootstrap.php:17
$status
Definition: order_status.php:8
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18