Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CronCommandTest.php
Go to the documentation of this file.
1 <?php
7 
11 use PHPUnit_Framework_MockObject_MockObject as MockObject;
12 use Symfony\Component\Console\Tester\CommandTester;
13 
14 class CronCommandTest extends \PHPUnit\Framework\TestCase
15 {
19  private $objectManagerFactory;
20 
24  private $deploymentConfigMock;
25 
26  protected function setUp()
27  {
28  $this->objectManagerFactory = $this->createMock(ObjectManagerFactory::class);
29  $this->deploymentConfigMock = $this->createMock(DeploymentConfig::class);
30  }
31 
37  public function testExecuteWithDisabledCrons()
38  {
39  $this->objectManagerFactory->expects($this->never())
40  ->method('create');
41  $this->deploymentConfigMock->expects($this->once())
42  ->method('get')
43  ->with('cron/enabled', 1)
44  ->willReturn(0);
45  $commandTester = new CommandTester(
46  new CronCommand($this->objectManagerFactory, $this->deploymentConfigMock)
47  );
48  $commandTester->execute([]);
49  $expectedMsg = 'Cron is disabled. Jobs were not run.' . PHP_EOL;
50  $this->assertEquals($expectedMsg, $commandTester->getDisplay());
51  }
52 
58  public function testExecute()
59  {
60  $objectManager = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
61  $cron = $this->createMock(\Magento\Framework\App\Cron::class);
62  $objectManager->expects($this->once())
63  ->method('create')
64  ->willReturn($cron);
65  $cron->expects($this->once())
66  ->method('launch');
67  $this->objectManagerFactory->expects($this->once())
68  ->method('create')
69  ->willReturn($objectManager);
70  $this->deploymentConfigMock->expects($this->once())
71  ->method('get')
72  ->with('cron/enabled', 1)
73  ->willReturn(1);
74  $commandTester = new CommandTester(
75  new CronCommand($this->objectManagerFactory, $this->deploymentConfigMock)
76  );
77  $commandTester->execute([]);
78  $expectedMsg = 'Ran jobs by schedule.' . PHP_EOL;
79  $this->assertEquals($expectedMsg, $commandTester->getDisplay());
80  }
81 }
$objectManager
Definition: bootstrap.php:17