diff --git a/plugins/TestRunner/Commands/TestsRun.php b/plugins/TestRunner/Commands/TestsRun.php
index d5b7398d9f936bc417564d046043f978975d1839..b024930eb68397f4e0887121fce336774dd22152 100644
--- a/plugins/TestRunner/Commands/TestsRun.php
+++ b/plugins/TestRunner/Commands/TestsRun.php
@@ -41,6 +41,7 @@ class TestsRun extends ConsoleCommand
         $options = $input->getOption('options');
         $groups  = $input->getOption('group');
         $magics  = $input->getArgument('variables');
+        $piwikDomain = $input->getOption('piwik-domain');
 
         $groups = $this->getGroupsFromString($groups);
 
@@ -113,7 +114,7 @@ class TestsRun extends ConsoleCommand
             }
         }
 
-        $this->executeTests($suite, $testFile, $groups, $options, $command, $output);
+        $this->executeTests($piwikDomain, $suite, $testFile, $groups, $options, $command, $output);
 
         return $this->returnVar;
     }
@@ -158,12 +159,12 @@ class TestsRun extends ConsoleCommand
         return $this->fixPathToTestFileOrDirectory($testFile);
     }
 
-    private function executeTests($suite, $testFile, $groups, $options, $command, OutputInterface $output)
+    private function executeTests($piwikDomain, $suite, $testFile, $groups, $options, $command, OutputInterface $output)
     {
         if (empty($suite) && empty($groups) && empty($testFile)) {
             foreach ($this->getTestsSuites() as $suite) {
                 $suite = $this->buildTestSuiteName($suite);
-                $this->executeTests($suite, $testFile, $groups, $options, $command, $output);
+                $this->executeTests($piwikDomain, $suite, $testFile, $groups, $options, $command, $output);
             }
 
             return;
@@ -175,12 +176,17 @@ class TestsRun extends ConsoleCommand
             $params = $params . " " . $testFile;
         }
 
-        $this->executeTestRun($command, $params, $output);
+        $this->executeTestRun($piwikDomain, $command, $params, $output);
     }
 
-    private function executeTestRun($command, $params, OutputInterface $output)
+    private function executeTestRun($piwikDomain, $command, $params, OutputInterface $output)
     {
-        $cmd = $this->getCommand($command, $params);
+        $envVars = '';
+        if (!empty($piwikDomain)) {
+            $envVars .= "PIWIK_DOMAIN=$piwikDomain";
+        }
+
+        $cmd = $this->getCommand($envVars, $command, $params);
         $output->writeln('Executing command: <info>' . $cmd . '</info>');
         passthru($cmd, $returnVar);
         $output->writeln("");
@@ -198,9 +204,9 @@ class TestsRun extends ConsoleCommand
      * @param $params
      * @return string
      */
-    private function getCommand($command, $params)
+    private function getCommand($envVars, $command, $params)
     {
-        return sprintf('cd %s/tests/PHPUnit && %s %s', PIWIK_DOCUMENT_ROOT, $command, $params);
+        return sprintf('cd %s/tests/PHPUnit && %s %s %s', PIWIK_DOCUMENT_ROOT, $envVars, $command, $params);
     }
 
     private function buildPhpUnitCliParams($suite, $groups, $options)
diff --git a/tests/PHPUnit/bootstrap.php b/tests/PHPUnit/bootstrap.php
index 313f8f4b6a5a6975a4ed5a8f22162dc3f231f6f5..444728bafd8c610e93bf53b5657b72a8b1cd2034 100644
--- a/tests/PHPUnit/bootstrap.php
+++ b/tests/PHPUnit/bootstrap.php
@@ -44,6 +44,16 @@ if (getenv('PIWIK_USE_XHPROF') == 1) {
     \Piwik\Profiler::setupProfilerXHProf();
 }
 
+function setPiwikDomainFromEnvVar()
+{
+    $piwikDomain = getenv('PIWIK_DOMAIN');
+    if (!empty($piwikDomain)) {
+        $_SERVER['HTTP_HOST'] = $piwikDomain;
+    }
+}
+
+setPiwikDomainFromEnvVar();
+
 // setup container for tests
 function setupRootContainer() {
     // before running tests, delete the TestingEnvironmentVariables file, since it can indirectly mess w/