From 2d8e217890be694f00a85ec56fd00a67e756095f Mon Sep 17 00:00:00 2001 From: Safwan Khan <safwkhan@ebay.com> Date: Wed, 29 Apr 2015 15:03:54 -0500 Subject: [PATCH] MAGETWO-36079: Move dev/shell/cron.sh - Implemented unit test for the command. --- .../Cron/Console/Command/CronCommand.php | 6 ++--- .../Unit/Console/Command/CronCommandTest.php | 26 +++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 app/code/Magento/Cron/Test/Unit/Console/Command/CronCommandTest.php diff --git a/app/code/Magento/Cron/Console/Command/CronCommand.php b/app/code/Magento/Cron/Console/Command/CronCommand.php index 5f820f208ef..2d51530988e 100644 --- a/app/code/Magento/Cron/Console/Command/CronCommand.php +++ b/app/code/Magento/Cron/Console/Command/CronCommand.php @@ -11,7 +11,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputOption; use Magento\Framework\App\ObjectManagerFactory; -use Magento\Framework\App\ObjectManager; +use Magento\Framework\ObjectManagerInterface; use Magento\Store\Model\Store; use Magento\Store\Model\StoreManager; @@ -28,7 +28,7 @@ class CronCommand extends Command /** * Object Manager * - * @var ObjectManager + * @var ObjectManagerInterface */ protected $objectManager; @@ -72,7 +72,7 @@ class CronCommand extends Command protected function execute(InputInterface $input, OutputInterface $output) { $params['group'] = $input->getOption(self::INPUT_KEY_GROUP); - // This flag 'standaloneProcessStarted' is for internal communication between processes only + // This 'standaloneProcessStarted' flag is for internal communication between processes only $params['standaloneProcessStarted'] = '0'; /** @var \Magento\Framework\App\Cron $cronObserver */ $cronObserver = $this->objectManager->create('Magento\Framework\App\Cron', ['parameters' => $params]); diff --git a/app/code/Magento/Cron/Test/Unit/Console/Command/CronCommandTest.php b/app/code/Magento/Cron/Test/Unit/Console/Command/CronCommandTest.php new file mode 100644 index 00000000000..396846acd8d --- /dev/null +++ b/app/code/Magento/Cron/Test/Unit/Console/Command/CronCommandTest.php @@ -0,0 +1,26 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Cron\Test\Unit\Console\Command; + +use Magento\Cron\Console\Command\CronCommand; +use Symfony\Component\Console\Tester\CommandTester; + +class CronCommandTest extends \PHPUnit_Framework_TestCase +{ + public function testExecute() + { + $objectManagerFactory = $this->getMock('Magento\Framework\App\ObjectManagerFactory', [], [], '', false); + $objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface', [], [], '', false); + $cron = $this->getMock('Magento\Framework\App\Cron', [], [], '', false); + $objectManager->expects($this->once())->method('create')->willReturn($cron); + $cron->expects($this->once())->method('launch'); + $objectManagerFactory->expects($this->once())->method('create')->willReturn($objectManager); + $commandTester = new CommandTester(new CronCommand($objectManagerFactory)); + $commandTester->execute([]); + $expectedMsg = 'Ran jobs by schedule.' . PHP_EOL; + $this->assertEquals($expectedMsg, $commandTester->getDisplay()); + } +} -- GitLab