|
10 | 10 |
|
11 | 11 | class CronCommandTest extends \PHPUnit\Framework\TestCase
|
12 | 12 | {
|
| 13 | + /** |
| 14 | + * Test command with disables cron |
| 15 | + * |
| 16 | + * @return void |
| 17 | + */ |
| 18 | + public function testExecuteWithDisabledCrons() |
| 19 | + { |
| 20 | + $objectManagerFactory = $this->createMock(\Magento\Framework\App\ObjectManagerFactory::class); |
| 21 | + $deploymentConfigMock = $this->createMock(\Magento\Framework\App\DeploymentConfig::class); |
| 22 | + |
| 23 | + $objectManagerFactory->expects($this->never()) |
| 24 | + ->method('create'); |
| 25 | + $deploymentConfigMock->expects($this->once()) |
| 26 | + ->method('get') |
| 27 | + ->with('cron/enabled', 1) |
| 28 | + ->willReturn(0); |
| 29 | + $commandTester = new CommandTester(new CronCommand($objectManagerFactory, $deploymentConfigMock)); |
| 30 | + $commandTester->execute([]); |
| 31 | + $expectedMsg = 'Cron is disabled. Jobs were not run.' . PHP_EOL; |
| 32 | + $this->assertEquals($expectedMsg, $commandTester->getDisplay()); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * Test command with enabled cron |
| 37 | + * |
| 38 | + * @return void |
| 39 | + */ |
13 | 40 | public function testExecute()
|
14 | 41 | {
|
15 | 42 | $objectManagerFactory = $this->createMock(\Magento\Framework\App\ObjectManagerFactory::class);
|
| 43 | + $deploymentConfigMock = $this->createMock(\Magento\Framework\App\DeploymentConfig::class); |
16 | 44 | $objectManager = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
|
17 | 45 | $cron = $this->createMock(\Magento\Framework\App\Cron::class);
|
18 |
| - $objectManager->expects($this->once())->method('create')->willReturn($cron); |
19 |
| - $cron->expects($this->once())->method('launch'); |
20 |
| - $objectManagerFactory->expects($this->once())->method('create')->willReturn($objectManager); |
21 |
| - $commandTester = new CommandTester(new CronCommand($objectManagerFactory)); |
| 46 | + $objectManager->expects($this->once()) |
| 47 | + ->method('create') |
| 48 | + ->willReturn($cron); |
| 49 | + $cron->expects($this->once()) |
| 50 | + ->method('launch'); |
| 51 | + $objectManagerFactory->expects($this->once()) |
| 52 | + ->method('create') |
| 53 | + ->willReturn($objectManager); |
| 54 | + $deploymentConfigMock->expects($this->once()) |
| 55 | + ->method('get') |
| 56 | + ->with('cron/enabled', 1) |
| 57 | + ->willReturn(1); |
| 58 | + $commandTester = new CommandTester(new CronCommand($objectManagerFactory, $deploymentConfigMock)); |
22 | 59 | $commandTester->execute([]);
|
23 | 60 | $expectedMsg = 'Ran jobs by schedule.' . PHP_EOL;
|
24 | 61 | $this->assertEquals($expectedMsg, $commandTester->getDisplay());
|
|
0 commit comments