From 3733cb35f0117da3c641767fe4f3c0bc6db89368 Mon Sep 17 00:00:00 2001 From: diosmosis <benaka@piwik.pro> Date: Mon, 22 Jun 2015 06:01:29 -0700 Subject: [PATCH] Allow Environment to be specified via constructor to Console app for tests, and re-use Fixture environment in ConsoleCommandTestCase. --- core/Console.php | 10 +++++++--- .../Framework/TestCase/ConsoleCommandTestCase.php | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/Console.php b/core/Console.php index 5a3ff2f541..6b0c59297f 100644 --- a/core/Console.php +++ b/core/Console.php @@ -26,12 +26,14 @@ class Console extends Application */ private $environment; - public function __construct() + public function __construct(Environment $environment = null) { $this->setServerArgsIfPhpCgi(); parent::__construct(); + $this->environment = $environment; + $option = new InputOption('piwik-domain', null, InputOption::VALUE_OPTIONAL, @@ -169,8 +171,10 @@ class Console extends Application protected function initEnvironment(OutputInterface $output) { try { - $this->environment = new Environment('cli'); - $this->environment->init(); + if ($this->environment === null) { + $this->environment = new Environment('cli'); + $this->environment->init(); + } $config = Config::getInstance(); return $config; diff --git a/tests/PHPUnit/Framework/TestCase/ConsoleCommandTestCase.php b/tests/PHPUnit/Framework/TestCase/ConsoleCommandTestCase.php index 31452e4651..4c63a0c0c0 100644 --- a/tests/PHPUnit/Framework/TestCase/ConsoleCommandTestCase.php +++ b/tests/PHPUnit/Framework/TestCase/ConsoleCommandTestCase.php @@ -75,7 +75,7 @@ class ConsoleCommandTestCase extends SystemTestCase { parent::setUp(); - $this->application = new TestConsole(); + $this->application = new TestConsole(self::$fixture->piwikEnvironment); $this->application->setAutoExit(false); $this->applicationTester = new ApplicationTester($this->application); -- GitLab