|
6 | 6 | namespace Magento\Cron\Test\Unit\Console\Command;
|
7 | 7 |
|
8 | 8 | use Magento\Cron\Console\Command\CronCommand;
|
| 9 | +use Magento\Framework\App\DeploymentConfig; |
| 10 | +use Magento\Framework\App\ObjectManagerFactory; |
| 11 | +use PHPUnit_Framework_MockObject_MockObject as MockObject; |
9 | 12 | use Symfony\Component\Console\Tester\CommandTester;
|
10 | 13 |
|
11 | 14 | class CronCommandTest extends \PHPUnit\Framework\TestCase
|
12 | 15 | {
|
| 16 | + /** |
| 17 | + * @var ObjectManagerFactory|MockObject |
| 18 | + */ |
| 19 | + private $objectManagerFactory; |
| 20 | + |
| 21 | + /** |
| 22 | + * @var DeploymentConfig|MockObject |
| 23 | + */ |
| 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 | + |
| 32 | + /** |
| 33 | + * Test command with disables cron |
| 34 | + * |
| 35 | + * @return void |
| 36 | + */ |
| 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 | + |
| 53 | + /** |
| 54 | + * Test command with enabled cron |
| 55 | + * |
| 56 | + * @return void |
| 57 | + */ |
13 | 58 | public function testExecute()
|
14 | 59 | {
|
15 |
| - $objectManagerFactory = $this->createMock(\Magento\Framework\App\ObjectManagerFactory::class); |
16 | 60 | $objectManager = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
|
17 | 61 | $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)); |
| 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 | + ); |
22 | 77 | $commandTester->execute([]);
|
23 | 78 | $expectedMsg = 'Ran jobs by schedule.' . PHP_EOL;
|
24 | 79 | $this->assertEquals($expectedMsg, $commandTester->getDisplay());
|
|
0 commit comments