From 33db8a3089760947eec93149a2029164b676eae8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20M=C3=BCller?= <thomas.mueller@tmit.eu>
Date: Wed, 21 Aug 2013 00:41:20 +0200
Subject: [PATCH] kill superfluent classloader from tests - this approach might
 be of interest within the apps

---
 tests/lib/appframework/AppTest.php            |  2 +-
 tests/lib/appframework/classloader.php        | 54 -------------------
 .../controller/ControllerTest.php             |  5 +-
 .../dependencyinjection/DIContainerTest.php   |  2 +-
 .../lib/appframework/http/DispatcherTest.php  |  6 +--
 .../http/DownloadResponseTest.php             |  2 +-
 tests/lib/appframework/http/HttpTest.php      |  2 +-
 .../appframework/http/JSONResponseTest.php    |  4 +-
 .../http/RedirectResponseTest.php             |  2 +-
 tests/lib/appframework/http/RequestTest.php   |  2 -
 tests/lib/appframework/http/ResponseTest.php  |  7 +--
 .../http/TemplateResponseTest.php             | 12 +++--
 .../middleware/MiddlewareDispatcherTest.php   |  6 +--
 .../middleware/MiddlewareTest.php             | 11 ++--
 .../security/SecurityMiddlewareTest.php       |  6 +--
 .../lib/appframework/routing/RoutingTest.php  |  1 -
 .../utility/MethodAnnotationReaderTest.php    |  3 --
 17 files changed, 33 insertions(+), 94 deletions(-)
 delete mode 100644 tests/lib/appframework/classloader.php

diff --git a/tests/lib/appframework/AppTest.php b/tests/lib/appframework/AppTest.php
index dcf0e6f77e..e8ae8c8f67 100644
--- a/tests/lib/appframework/AppTest.php
+++ b/tests/lib/appframework/AppTest.php
@@ -30,7 +30,7 @@ use OC\AppFramework\Middleware\MiddlewareDispatcher;
 
 // FIXME: loading pimpl correctly from 3rdparty repo
 require_once __DIR__ . '/../../../3rdparty/Pimple/Pimple.php';
-require_once __DIR__ . "/classloader.php";
+//require_once __DIR__ . "/classloader.php";
 
 
 class AppTest extends \PHPUnit_Framework_TestCase {
diff --git a/tests/lib/appframework/classloader.php b/tests/lib/appframework/classloader.php
deleted file mode 100644
index cd9f893df3..0000000000
--- a/tests/lib/appframework/classloader.php
+++ /dev/null
@@ -1,54 +0,0 @@
-<?php
-
-/**
- * ownCloud - App Framework
- *
- * @author Bernhard Posselt
- * @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
- *
- * You should have received a copy of the GNU Affero General Public
- * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-// to execute without ownCloud, we need to create our own class loader
-spl_autoload_register(function ($className){
-	if (strpos($className, 'OC\\AppFramework') === 0) {
-		$path = strtolower(str_replace('\\', '/', substr($className, 3)) . '.php');
-		$relPath = __DIR__ . '/../../../lib/' . $path;
-
-		if(file_exists($relPath)){
-			require_once $relPath;
-		}
-	}
-
-	if (strpos($className, 'OCP\\') === 0) {
-		$path = strtolower(str_replace('\\', '/', substr($className, 3)) . '.php');
-		$relPath = __DIR__ . '/../../../lib/public' . $path;
-
-		if(file_exists($relPath)){
-			require_once $relPath;
-		}
-	}
-
-	// FIXME: this will most probably not work anymore
-	if (strpos($className, 'OCA\\') === 0) {
-
-		$path = strtolower(str_replace('\\', '/', substr($className, 3)) . '.php');
-		$relPath = __DIR__ . '/../..' . $path;
-
-		if(file_exists($relPath)){
-			require_once $relPath;
-		}
-	}
-});
diff --git a/tests/lib/appframework/controller/ControllerTest.php b/tests/lib/appframework/controller/ControllerTest.php
index d8357c2a68..246371d249 100644
--- a/tests/lib/appframework/controller/ControllerTest.php
+++ b/tests/lib/appframework/controller/ControllerTest.php
@@ -25,12 +25,11 @@
 namespace Test\AppFramework\Controller;
 
 use OC\AppFramework\Http\Request;
-use OC\AppFramework\Http\JSONResponse;
-use OC\AppFramework\Http\TemplateResponse;
 use OC\AppFramework\Controller\Controller;
+use OCP\AppFramework\Http\TemplateResponse;
 
 
-require_once(__DIR__ . "/../classloader.php");
+//require_once __DIR__ . "/../classloader.php";
 
 
 class ChildController extends Controller {};
diff --git a/tests/lib/appframework/dependencyinjection/DIContainerTest.php b/tests/lib/appframework/dependencyinjection/DIContainerTest.php
index ce346f0a76..25fdd20283 100644
--- a/tests/lib/appframework/dependencyinjection/DIContainerTest.php
+++ b/tests/lib/appframework/dependencyinjection/DIContainerTest.php
@@ -29,7 +29,7 @@ namespace OC\AppFramework\DependencyInjection;
 use \OC\AppFramework\Http\Request;
 
 
-require_once(__DIR__ . "/../classloader.php");
+//require_once(__DIR__ . "/../classloader.php");
 
 
 class DIContainerTest extends \PHPUnit_Framework_TestCase {
diff --git a/tests/lib/appframework/http/DispatcherTest.php b/tests/lib/appframework/http/DispatcherTest.php
index 2e3db11050..849b0ca97a 100644
--- a/tests/lib/appframework/http/DispatcherTest.php
+++ b/tests/lib/appframework/http/DispatcherTest.php
@@ -27,7 +27,7 @@ namespace OC\AppFramework\Http;
 use OC\AppFramework\Core\API;
 use OC\AppFramework\Middleware\MiddlewareDispatcher;
 
-require_once(__DIR__ . "/../classloader.php");
+//require_once(__DIR__ . "/../classloader.php");
 
 
 class DispatcherTest extends \PHPUnit_Framework_TestCase {
@@ -69,7 +69,7 @@ class DispatcherTest extends \PHPUnit_Framework_TestCase {
 			$this->http, $this->middlewareDispatcher);
 		
 		$this->response = $this->getMockBuilder(
-			'\OC\AppFramework\Http\Response')
+			'\OCP\AppFramework\Http\Response')
 			->disableOriginalConstructor()
 			->getMock();
 
@@ -207,7 +207,7 @@ class DispatcherTest extends \PHPUnit_Framework_TestCase {
 		$out = 'yo';
 		$httpHeaders = 'Http';
 		$responseHeaders = array('hell' => 'yeah');
-		$this->setMiddlewareExpections($out, $httpHeaders, $responseHeaders, true, false);		
+		$this->setMiddlewareExpections($out, $httpHeaders, $responseHeaders, true, false);
 
 		$this->setExpectedException('\Exception');
 		$response = $this->dispatcher->dispatch($this->controller, 
diff --git a/tests/lib/appframework/http/DownloadResponseTest.php b/tests/lib/appframework/http/DownloadResponseTest.php
index 103cfe7588..64fe7992b6 100644
--- a/tests/lib/appframework/http/DownloadResponseTest.php
+++ b/tests/lib/appframework/http/DownloadResponseTest.php
@@ -25,7 +25,7 @@
 namespace OC\AppFramework\Http;
 
 
-require_once(__DIR__ . "/../classloader.php");
+//require_once(__DIR__ . "/../classloader.php");
 
 
 class ChildDownloadResponse extends DownloadResponse {};
diff --git a/tests/lib/appframework/http/HttpTest.php b/tests/lib/appframework/http/HttpTest.php
index 306bc3caf4..382d511b11 100644
--- a/tests/lib/appframework/http/HttpTest.php
+++ b/tests/lib/appframework/http/HttpTest.php
@@ -25,7 +25,7 @@
 namespace OC\AppFramework\Http;
 
 
-require_once(__DIR__ . "/../classloader.php");
+//require_once(__DIR__ . "/../classloader.php");
 
 
 
diff --git a/tests/lib/appframework/http/JSONResponseTest.php b/tests/lib/appframework/http/JSONResponseTest.php
index d15e08f6ce..534c54cbce 100644
--- a/tests/lib/appframework/http/JSONResponseTest.php
+++ b/tests/lib/appframework/http/JSONResponseTest.php
@@ -27,7 +27,9 @@
 namespace OC\AppFramework\Http;
 
 
-require_once(__DIR__ . "/../classloader.php");
+use OCP\AppFramework\Http\JSONResponse;
+
+//require_once(__DIR__ . "/../classloader.php");
 
 
 
diff --git a/tests/lib/appframework/http/RedirectResponseTest.php b/tests/lib/appframework/http/RedirectResponseTest.php
index a8577feed2..1946655b0f 100644
--- a/tests/lib/appframework/http/RedirectResponseTest.php
+++ b/tests/lib/appframework/http/RedirectResponseTest.php
@@ -25,7 +25,7 @@
 namespace OC\AppFramework\Http;
 
 
-require_once(__DIR__ . "/../classloader.php");
+//require_once(__DIR__ . "/../classloader.php");
 
 
 
diff --git a/tests/lib/appframework/http/RequestTest.php b/tests/lib/appframework/http/RequestTest.php
index c1f56c0163..0371c870cf 100644
--- a/tests/lib/appframework/http/RequestTest.php
+++ b/tests/lib/appframework/http/RequestTest.php
@@ -9,8 +9,6 @@
 namespace OC\AppFramework\Http;
 
 
-require_once(__DIR__ . "/../classloader.php");
-
 class RequestTest extends \PHPUnit_Framework_TestCase {
 
 	public function testRequestAccessors() {
diff --git a/tests/lib/appframework/http/ResponseTest.php b/tests/lib/appframework/http/ResponseTest.php
index 621ba66545..7e09086f80 100644
--- a/tests/lib/appframework/http/ResponseTest.php
+++ b/tests/lib/appframework/http/ResponseTest.php
@@ -25,13 +25,14 @@
 namespace OC\AppFramework\Http;
 
 
-require_once(__DIR__ . "/../classloader.php");
-
+use OCP\AppFramework\Http\Response;
 
 
 class ResponseTest extends \PHPUnit_Framework_TestCase {
 
-
+	/**
+	 * @var \OCP\AppFramework\Http\Response
+	 */
 	private $childResponse;
 
 	protected function setUp(){
diff --git a/tests/lib/appframework/http/TemplateResponseTest.php b/tests/lib/appframework/http/TemplateResponseTest.php
index 30684725b7..3c6d29cd33 100644
--- a/tests/lib/appframework/http/TemplateResponseTest.php
+++ b/tests/lib/appframework/http/TemplateResponseTest.php
@@ -24,15 +24,19 @@
 
 namespace OC\AppFramework\Http;
 
-use OC\AppFramework\Core\API;
-
-
-require_once(__DIR__ . "/../classloader.php");
+use OCP\AppFramework\Http\TemplateResponse;
 
 
 class TemplateResponseTest extends \PHPUnit_Framework_TestCase {
 
+	/**
+	 * @var \OCP\AppFramework\Http\TemplateResponse
+	 */
 	private $tpl;
+
+	/**
+	 * @var \OCP\AppFramework\IApi
+	 */
 	private $api;
 
 	protected function setUp() {
diff --git a/tests/lib/appframework/middleware/MiddlewareDispatcherTest.php b/tests/lib/appframework/middleware/MiddlewareDispatcherTest.php
index bfa54a48ea..d1b2fedee5 100644
--- a/tests/lib/appframework/middleware/MiddlewareDispatcherTest.php
+++ b/tests/lib/appframework/middleware/MiddlewareDispatcherTest.php
@@ -24,14 +24,10 @@
 
 namespace OC\AppFramework;
 
-use OC\AppFramework\Controller\Controller;
 use OC\AppFramework\Http\Request;
-use OC\AppFramework\Http\Response;
 use OC\AppFramework\Middleware\Middleware;
 use OC\AppFramework\Middleware\MiddlewareDispatcher;
-
-
-require_once(__DIR__ . "/../classloader.php");
+use OCP\AppFramework\Http\Response;
 
 
 // needed to test ordering
diff --git a/tests/lib/appframework/middleware/MiddlewareTest.php b/tests/lib/appframework/middleware/MiddlewareTest.php
index 1adce6b3d4..5e2930ac6a 100644
--- a/tests/lib/appframework/middleware/MiddlewareTest.php
+++ b/tests/lib/appframework/middleware/MiddlewareTest.php
@@ -28,14 +28,14 @@ use OC\AppFramework\Http\Request;
 use OC\AppFramework\Middleware\Middleware;
 
 
-require_once(__DIR__ . "/../classloader.php");
-
-
 class ChildMiddleware extends Middleware {};
 
 
 class MiddlewareTest extends \PHPUnit_Framework_TestCase {
 
+	/**
+	 * @var Middleware
+	 */
 	private $middleware;
 	private $controller;
 	private $exception;
@@ -50,12 +50,13 @@ class MiddlewareTest extends \PHPUnit_Framework_TestCase {
 		$this->controller = $this->getMock('OC\AppFramework\Controller\Controller',
 				array(), array($this->api, new Request()));
 		$this->exception = new \Exception();
-		$this->response = $this->getMock('OC\AppFramework\Http\Response');
+		$this->response = $this->getMock('OCP\AppFramework\Http\Response');
 	}
 
 
 	public function testBeforeController() {
-		$this->middleware->beforeController($this->controller, null, $this->exception);
+		$this->middleware->beforeController($this->controller, null);
+		$this->assertNull(null);
 	}
 
 
diff --git a/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php b/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php
index 90a19c9999..3ed44282a7 100644
--- a/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php
+++ b/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php
@@ -27,11 +27,7 @@ namespace OC\AppFramework\Middleware\Security;
 use OC\AppFramework\Http\Http;
 use OC\AppFramework\Http\Request;
 use OC\AppFramework\Http\RedirectResponse;
-use OC\AppFramework\Http\JSONResponse;
-use OC\AppFramework\Middleware\Middleware;
-
-
-require_once(__DIR__ . "/../../classloader.php");
+use OCP\AppFramework\Http\JSONResponse;
 
 
 class SecurityMiddlewareTest extends \PHPUnit_Framework_TestCase {
diff --git a/tests/lib/appframework/routing/RoutingTest.php b/tests/lib/appframework/routing/RoutingTest.php
index 92ad461471..a7aa922db1 100644
--- a/tests/lib/appframework/routing/RoutingTest.php
+++ b/tests/lib/appframework/routing/RoutingTest.php
@@ -5,7 +5,6 @@ namespace OC\AppFramework\Routing;
 use OC\AppFramework\DependencyInjection\DIContainer;
 use OC\AppFramework\routing\RouteConfig;
 
-require_once(__DIR__ . "/../classloader.php");
 
 class RouteConfigTest extends \PHPUnit_Framework_TestCase
 {
diff --git a/tests/lib/appframework/utility/MethodAnnotationReaderTest.php b/tests/lib/appframework/utility/MethodAnnotationReaderTest.php
index bcdcf3de37..c68812aa5c 100644
--- a/tests/lib/appframework/utility/MethodAnnotationReaderTest.php
+++ b/tests/lib/appframework/utility/MethodAnnotationReaderTest.php
@@ -25,9 +25,6 @@
 namespace OC\AppFramework\Utility;
 
 
-require_once __DIR__ . "/../classloader.php";
-
-
 class MethodAnnotationReaderTest extends \PHPUnit_Framework_TestCase {
 
 
-- 
GitLab