Skip to content

Commit 863764e

Browse files
committed
MAGETWO-93701: Make cron:run CLI command react on cron disable configuration
1 parent 2fc966c commit 863764e

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

app/code/Magento/Cron/Test/Unit/Console/Command/CronCommandTest.php

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,45 @@
66
namespace Magento\Cron\Test\Unit\Console\Command;
77

88
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;
912
use Symfony\Component\Console\Tester\CommandTester;
1013

1114
class CronCommandTest extends \PHPUnit\Framework\TestCase
1215
{
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+
1332
/**
1433
* Test command with disables cron
1534
*
1635
* @return void
1736
*/
1837
public function testExecuteWithDisabledCrons()
1938
{
20-
$objectManagerFactory = $this->createMock(\Magento\Framework\App\ObjectManagerFactory::class);
21-
$deploymentConfigMock = $this->createMock(\Magento\Framework\App\DeploymentConfig::class);
22-
23-
$objectManagerFactory->expects($this->never())
39+
$this->objectManagerFactory->expects($this->never())
2440
->method('create');
25-
$deploymentConfigMock->expects($this->once())
41+
$this->deploymentConfigMock->expects($this->once())
2642
->method('get')
2743
->with('cron/enabled', 1)
2844
->willReturn(0);
29-
$commandTester = new CommandTester(new CronCommand($objectManagerFactory, $deploymentConfigMock));
45+
$commandTester = new CommandTester(
46+
new CronCommand($this->objectManagerFactory, $this->deploymentConfigMock)
47+
);
3048
$commandTester->execute([]);
3149
$expectedMsg = 'Cron is disabled. Jobs were not run.' . PHP_EOL;
3250
$this->assertEquals($expectedMsg, $commandTester->getDisplay());
@@ -39,23 +57,23 @@ public function testExecuteWithDisabledCrons()
3957
*/
4058
public function testExecute()
4159
{
42-
$objectManagerFactory = $this->createMock(\Magento\Framework\App\ObjectManagerFactory::class);
43-
$deploymentConfigMock = $this->createMock(\Magento\Framework\App\DeploymentConfig::class);
4460
$objectManager = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
4561
$cron = $this->createMock(\Magento\Framework\App\Cron::class);
4662
$objectManager->expects($this->once())
4763
->method('create')
4864
->willReturn($cron);
4965
$cron->expects($this->once())
5066
->method('launch');
51-
$objectManagerFactory->expects($this->once())
67+
$this->objectManagerFactory->expects($this->once())
5268
->method('create')
5369
->willReturn($objectManager);
54-
$deploymentConfigMock->expects($this->once())
70+
$this->deploymentConfigMock->expects($this->once())
5571
->method('get')
5672
->with('cron/enabled', 1)
5773
->willReturn(1);
58-
$commandTester = new CommandTester(new CronCommand($objectManagerFactory, $deploymentConfigMock));
74+
$commandTester = new CommandTester(
75+
new CronCommand($this->objectManagerFactory, $this->deploymentConfigMock)
76+
);
5977
$commandTester->execute([]);
6078
$expectedMsg = 'Ran jobs by schedule.' . PHP_EOL;
6179
$this->assertEquals($expectedMsg, $commandTester->getDisplay());

0 commit comments

Comments
 (0)