From 6957eecce6c3393b21450b40750cef9da90462a9 Mon Sep 17 00:00:00 2001
From: Maddy Chellathurai <mchellathura@magento.com>
Date: Wed, 18 May 2016 12:12:02 -0500
Subject: [PATCH] MAGETWO-52000: [Github][PR]impossible to see what is wrong
 with cron - unhelpful error message #3189

- fixes for QA issues.
---
 .../Magento/Setup/Model/Cron/JobSetCache.php  | 19 +++++++++++++++---
 .../Magento/Setup/Model/Cron/JobUpgrade.php   |  4 ++--
 .../Test/Unit/Model/Cron/JobSetCacheTest.php  | 20 +++++++++++++------
 3 files changed, 32 insertions(+), 11 deletions(-)

diff --git a/setup/src/Magento/Setup/Model/Cron/JobSetCache.php b/setup/src/Magento/Setup/Model/Cron/JobSetCache.php
index c1f65bc58ba..7f58f34b7b1 100644
--- a/setup/src/Magento/Setup/Model/Cron/JobSetCache.php
+++ b/setup/src/Magento/Setup/Model/Cron/JobSetCache.php
@@ -7,6 +7,8 @@ namespace Magento\Setup\Model\Cron;
 
 use Magento\Backend\Console\Command\AbstractCacheManageCommand;
 use Symfony\Component\Console\Input\ArrayInput;
+use Symfony\Component\Console\Input\InputDefinition;
+use Symfony\Component\Console\Input\InputArgument;
 
 class JobSetCache extends AbstractJob
 {
@@ -55,10 +57,21 @@ class JobSetCache extends AbstractJob
     public function execute()
     {
         try {
-            if (!empty($this->params)) {
-                $arguments[AbstractCacheManageCommand::INPUT_KEY_TYPES] = explode(' ', $this->params[0]);
+            $arguments = [];
+            if ($this->getName() === 'setup:cache:enable') {
+                if (!empty($this->params)) {
+                    $arguments[AbstractCacheManageCommand::INPUT_KEY_TYPES] = explode(' ', $this->params[0]);
+                }
+                $arguments['command'] = 'cache:enable';
+                $definition = new InputDefinition([
+                    new InputArgument(AbstractCacheManageCommand::INPUT_KEY_TYPES, InputArgument::REQUIRED),
+                    new InputArgument('command', InputArgument::REQUIRED),
+                ]);
+
+                $this->command->setDefinition($definition);
+            } else {
+                $arguments['command'] = 'cache:disable';
             }
-            $arguments['command'] = $this->command->getName();
             $this->command->run(new ArrayInput($arguments), $this->output);
         } catch (\Exception $e) {
             $this->status->toggleUpdateError(true);
diff --git a/setup/src/Magento/Setup/Model/Cron/JobUpgrade.php b/setup/src/Magento/Setup/Model/Cron/JobUpgrade.php
index 19f06687394..ef2e12606bd 100644
--- a/setup/src/Magento/Setup/Model/Cron/JobUpgrade.php
+++ b/setup/src/Magento/Setup/Model/Cron/JobUpgrade.php
@@ -62,14 +62,14 @@ class JobUpgrade extends AbstractJob
     public function execute()
     {
         try {
-            $this->params['command'] = 'setup:upgrade';
-            $this->command->run(new ArrayInput($this->params), $this->output);
             $this->queue->addJobs(
                 [['name' => JobFactory::JOB_STATIC_REGENERATE, 'params' => []]]
             );
             $this->queue->addJobs(
                 [['name' => \Magento\Setup\Model\Updater::TASK_TYPE_MAINTENANCE_MODE, 'params' => ['enable' => false]]]
             );
+            $this->params['command'] = 'setup:upgrade';
+            $this->command->run(new ArrayInput($this->params), $this->output);
         } catch (\Exception $e) {
             $this->status->toggleUpdateError(true);
             throw new \RuntimeException(sprintf('Could not complete %s successfully: %s', $this, $e->getMessage()));
diff --git a/setup/src/Magento/Setup/Test/Unit/Model/Cron/JobSetCacheTest.php b/setup/src/Magento/Setup/Test/Unit/Model/Cron/JobSetCacheTest.php
index ef098061d12..c4c5b296e74 100644
--- a/setup/src/Magento/Setup/Test/Unit/Model/Cron/JobSetCacheTest.php
+++ b/setup/src/Magento/Setup/Test/Unit/Model/Cron/JobSetCacheTest.php
@@ -7,6 +7,8 @@ namespace Magento\Setup\Test\Unit\Model\Cron;
 
 use Magento\Setup\Model\Cron\JobSetCache;
 use Symfony\Component\Console\Input\ArrayInput;
+use Symfony\Component\Console\Input\InputDefinition;
+use Symfony\Component\Console\Input\InputArgument;
 
 class JobSetCacheTest extends \PHPUnit_Framework_TestCase
 {
@@ -15,8 +17,9 @@ class JobSetCacheTest extends \PHPUnit_Framework_TestCase
      * @param string $commandClass
      * @param string $commandName
      * @param string $jobName
+     * @param array $params
      */
-    public function testSetCache($commandClass, $commandName, $jobName)
+    public function testSetCache($commandClass, $commandName, $jobName, $params)
     {
         $objectManagerProvider = $this->getMock('Magento\Setup\Model\ObjectManagerProvider', [], [], '', false);
         $objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface', [], '', false);
@@ -32,12 +35,17 @@ class JobSetCacheTest extends \PHPUnit_Framework_TestCase
         $output = $this->getMockForAbstractClass('Symfony\Component\Console\Output\OutputInterface', [], '', false);
         $status = $this->getMock('Magento\Setup\Model\Cron\Status', [], [], '', false);
         $command = $this->getMock($commandClass, [], [], '', false);
-        $command->expects($this->once())->method('getName')->willReturn($commandName);
         $command->expects($this->once())
             ->method('run')
-            ->with(new ArrayInput(['command' => $commandName]), $output);
+            ->with(new ArrayInput(['command' => $commandName, 'types' => $params]), $output);
 
-        $model = new JobSetCache($command, $objectManagerProvider, $output, $status, $jobName, []);
+        $definition = new InputDefinition([
+            new InputArgument('types', InputArgument::REQUIRED),
+            new InputArgument('command', InputArgument::REQUIRED),
+        ]);
+        $command->expects($this->any())->method('setDefinition')->with($definition);
+
+        $model = new JobSetCache($command, $objectManagerProvider, $output, $status, $jobName, $params);
         $model->execute();
     }
 
@@ -47,8 +55,8 @@ class JobSetCacheTest extends \PHPUnit_Framework_TestCase
     public function setCacheDataProvider()
     {
         return [
-            ['Magento\Backend\Console\Command\CacheEnableCommand', 'cache:enable', 'setup:cache:enable'],
-            ['Magento\Backend\Console\Command\CacheDisableCommand', 'cache:disable', 'setup:cache:disable'],
+            ['Magento\Backend\Console\Command\CacheEnableCommand', 'cache:enable', 'setup:cache:enable', ['cache1']],
+            ['Magento\Backend\Console\Command\CacheDisableCommand', 'cache:disable', 'setup:cache:disable', []],
         ];
     }
 }
-- 
GitLab