Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
JobSetCacheTest.php
Go to the documentation of this file.
1 <?php
7 
9 use Symfony\Component\Console\Input\ArrayInput;
10 use Symfony\Component\Console\Input\InputDefinition;
11 use Symfony\Component\Console\Input\InputArgument;
12 
16 class JobSetCacheTest extends \PHPUnit\Framework\TestCase
17 {
25  public function testSetCache($commandClass, $arrayInput, $jobName, $params)
26  {
27  $arrayInput = new ArrayInput($arrayInput);
28  $objectManagerProvider = $this->createMock(\Magento\Setup\Model\ObjectManagerProvider::class);
30  $this->getMockForAbstractClass(\Magento\Framework\ObjectManagerInterface::class, [], '', false);
31  $cleanupFiles = $this->createMock(\Magento\Framework\App\State\CleanupFiles::class);
32  $cache = $this->createMock(\Magento\Framework\App\Cache::class);
33  $valueMap = [
34  [ \Magento\Framework\Module\PackageInfoFactory::class],
35  [ \Magento\Framework\App\State\CleanupFiles::class, $cleanupFiles],
36  [ \Magento\Framework\App\Cache::class, $cache],
37  ];
38  $objectManager->expects($this->atLeastOnce())->method('get')->will($this->returnValueMap($valueMap));
39  $objectManagerProvider->expects($this->once())->method('get')->willReturn($objectManager);
40 
41  $output =
42  $this->getMockForAbstractClass(\Symfony\Component\Console\Output\OutputInterface::class, [], '', false);
43  $status = $this->createMock(\Magento\Setup\Model\Cron\Status::class);
44  $command = $this->createMock($commandClass);
45 
46  $command->expects($this->once())
47  ->method('run')
48  ->with($arrayInput, $output);
49 
50  $definition = new InputDefinition([
51  new InputArgument('types', InputArgument::REQUIRED),
52  new InputArgument('command', InputArgument::REQUIRED),
53  ]);
54 
55  $inputDef = $this->createMock(\Symfony\Component\Console\Input\InputDefinition::class);
56  $inputDef->expects($this->any())->method('hasArgument')->willReturn(true);
57  $command->expects($this->any())->method('getDefinition')->willReturn($inputDef);
58  $command->expects($this->any())->method('setDefinition')->with($definition);
59 
60  $model = new JobSetCache($command, $objectManagerProvider, $output, $status, $jobName, $params);
61  $model->execute();
62  }
63 
67  public function setCacheDataProvider()
68  {
69  return [
70  [
71  \Magento\Backend\Console\Command\CacheEnableCommand::class,
72  ['command' => 'cache:enable', 'types' => ['cache1']],
73  'setup:cache:enable',
74  ['cache1']
75  ],
76  [
77  \Magento\Backend\Console\Command\CacheDisableCommand::class,
78  ['command' => 'cache:disable'],
79  'setup:cache:disable',
80  []
81  ],
82  ];
83  }
84 }
$objectManager
Definition: bootstrap.php:17
$status
Definition: order_status.php:8
testSetCache($commandClass, $arrayInput, $jobName, $params)
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18