From 1c54692be1358cd9bc896965b4d2d190f4c1efe2 Mon Sep 17 00:00:00 2001
From: Matthieu Napoli <matthieu@mnapoli.fr>
Date: Fri, 24 Oct 2014 12:04:05 +1300
Subject: [PATCH] Simplified tests autoloading by using Composer's
 "autoload-dev"

---
 composer.json                                            | 5 +++++
 core/Loader.php                                          | 9 ---------
 plugins/CoreConsole/Commands/TestsSetupFixture.php       | 4 ----
 ...itorIdAndUserId.php => FewVisitsWithSetVisitorId.php} | 0
 tests/PHPUnit/bootstrap.php                              | 5 -----
 5 files changed, 5 insertions(+), 18 deletions(-)
 rename tests/PHPUnit/Fixtures/{FewVisitsWithSetVisitorIdAndUserId.php => FewVisitsWithSetVisitorId.php} (100%)

diff --git a/composer.json b/composer.json
index 392f934e03..1e79ad7255 100644
--- a/composer.json
+++ b/composer.json
@@ -30,6 +30,11 @@
             "Archive_": "libs/"
         }
     },
+    "autoload-dev": {
+        "psr-4": {
+            "Piwik\\Tests\\": "tests/PHPUnit/"
+        }
+    },
     "require": {
         "php": ">=5.3.3",
         "twig/twig": "~1.0",
diff --git a/core/Loader.php b/core/Loader.php
index 932c89d5bd..b89e7743f9 100644
--- a/core/Loader.php
+++ b/core/Loader.php
@@ -35,13 +35,4 @@ class Loader
 
         return $loader;
     }
-
-    public static function registerTestNamespace()
-    {
-        $prefix = 'Piwik\\Tests\\';
-        $paths  = PIWIK_INCLUDE_PATH . '/tests/PHPUnit';
-
-        $loader = self::getLoader();
-        $loader->addPsr4($prefix, $paths, $prepend = false);
-    }
 }
diff --git a/plugins/CoreConsole/Commands/TestsSetupFixture.php b/plugins/CoreConsole/Commands/TestsSetupFixture.php
index 3413566eb7..8002eaaa7e 100644
--- a/plugins/CoreConsole/Commands/TestsSetupFixture.php
+++ b/plugins/CoreConsole/Commands/TestsSetupFixture.php
@@ -231,16 +231,12 @@ class TestsSetupFixture extends ConsoleCommand
 
     private function requireFixtureFiles(InputInterface $input)
     {
-        \Piwik\Loader::registerTestNamespace();
-
         require_once PIWIK_INCLUDE_PATH . '/libs/PiwikTracker/PiwikTracker.php';
         require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/FakeAccess.php';
         require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/TestingEnvironment.php';
         require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/IntegrationTestCase.php';
-        require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/Fixture.php';
 
         $fixturesToLoad = array(
-            '/tests/PHPUnit/Fixtures/*.php',
             '/tests/PHPUnit/UI/Fixtures/*.php',
             '/plugins/*/tests/Fixtures/*.php',
             '/plugins/*/Test/Fixtures/*.php',
diff --git a/tests/PHPUnit/Fixtures/FewVisitsWithSetVisitorIdAndUserId.php b/tests/PHPUnit/Fixtures/FewVisitsWithSetVisitorId.php
similarity index 100%
rename from tests/PHPUnit/Fixtures/FewVisitsWithSetVisitorIdAndUserId.php
rename to tests/PHPUnit/Fixtures/FewVisitsWithSetVisitorId.php
diff --git a/tests/PHPUnit/bootstrap.php b/tests/PHPUnit/bootstrap.php
index c78838b968..bdd1b3a771 100644
--- a/tests/PHPUnit/bootstrap.php
+++ b/tests/PHPUnit/bootstrap.php
@@ -30,15 +30,11 @@ error_reporting(E_ALL | E_NOTICE);
 require_once PIWIK_INCLUDE_PATH . '/core/Loader.php';
 
 \Piwik\Loader::init();
-\Piwik\Loader::registerTestNamespace();
 
 require_once PIWIK_INCLUDE_PATH . '/libs/upgradephp/upgrade.php';
 require_once PIWIK_INCLUDE_PATH . '/core/testMinimumPhpVersion.php';
-require_once PIWIK_INCLUDE_PATH . '/core/FrontController.php';
-require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/Fixture.php';
 require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/DatabaseTestCase.php';
 require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/IntegrationTestCase.php';
-require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/ConsoleCommandTestCase.php';
 require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/BenchmarkTestCase.php';
 require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/FakeAccess.php';
 require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/TestingEnvironment.php';
@@ -49,7 +45,6 @@ if (getenv('PIWIK_USE_XHPROF') == 1) {
 
 // require test fixtures
 $fixturesToLoad = array(
-    '/tests/PHPUnit/Fixtures/*.php',
     '/tests/PHPUnit/UI/Fixtures/*.php',
     '/plugins/*/tests/Fixtures/*.php',
     '/plugins/*/Test/Fixtures/*.php',
-- 
GitLab