From cf2694bca2e55ea8f1fd3df7725cd97c9c3468ad Mon Sep 17 00:00:00 2001
From: diosmosis <benaka@piwik.pro>
Date: Mon, 15 Jun 2015 21:05:07 -0700
Subject: [PATCH] Fixes #7900, add test for this problem (Common not being
 available at the start of the script) in ArchiveCronTest.php by executing the
 real archive.php w/ the --help option.

---
 tests/PHPUnit/System/ArchiveCronTest.php | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/tests/PHPUnit/System/ArchiveCronTest.php b/tests/PHPUnit/System/ArchiveCronTest.php
index 9c8be19798..db722f9266 100644
--- a/tests/PHPUnit/System/ArchiveCronTest.php
+++ b/tests/PHPUnit/System/ArchiveCronTest.php
@@ -105,6 +105,15 @@ class ArchiveCronTest extends SystemTestCase
         }
     }
 
+    public function test_archivePhpScript_DoesNotFail_WhenCommandHelpRequested()
+    {
+        $output = $this->runArchivePhpCron(array('--help' => null), PIWIK_INCLUDE_PATH . '/misc/cron/archive.php');
+        $output = implode("\n", $output);
+
+        $this->assertRegExp('/Usage:\s*core:archive/', $output);
+        $this->assertNotContains("Starting Piwik reports archiving...", $output);
+    }
+
     private function setLastRunArchiveOptions()
     {
         $periodTypes = array('day', 'periods');
@@ -123,13 +132,20 @@ class ArchiveCronTest extends SystemTestCase
         }
     }
 
-    private function runArchivePhpCron()
+    private function runArchivePhpCron($options = array(), $archivePhpScript = false)
     {
-        $archivePhpScript = PIWIK_INCLUDE_PATH . '/tests/PHPUnit/proxy/archive.php';
+        $archivePhpScript = $archivePhpScript ?: PIWIK_INCLUDE_PATH . '/tests/PHPUnit/proxy/archive.php';
         $urlToProxy = Fixture::getRootUrl() . 'tests/PHPUnit/proxy/index.php';
 
         // create the command
-        $cmd = "php \"$archivePhpScript\" --url=\"$urlToProxy\" 2>&1";
+        $cmd = "php \"$archivePhpScript\" --url=\"$urlToProxy\"";
+        foreach ($options as $name => $value) {
+            $cmd .= " $name";
+            if ($value !== null) {
+                $cmd .= "=" . escapeshellarg($value);
+            }
+        }
+        $cmd .= " 2>&1";
 
         // run the command
         exec($cmd, $output, $result);
-- 
GitLab