Browse Source

Move controller related exceptions under Controller/Error

ADmad 12 years ago
parent
commit
370a89d7a1

+ 1 - 2
src/Controller/ComponentRegistry.php

@@ -15,7 +15,6 @@
 namespace Cake\Controller;
 
 use Cake\Core\App;
-use Cake\Error;
 use Cake\Event\EventListener;
 use Cake\Event\EventManager;
 use Cake\Utility\ObjectRegistry;
@@ -76,7 +75,7 @@ class ComponentRegistry extends ObjectRegistry {
  *
  * @param string $class The classname that is missing.
  * @param string $plugin The plugin the component is missing in.
- * @throws \Cake\Error\MissingComponentException
+ * @throws \Cake\Controller\Error\MissingComponentException
  */
 	protected function _throwMissingClassError($class, $plugin) {
 		throw new Error\MissingComponentException([

+ 4 - 4
src/Controller/Controller.php

@@ -18,7 +18,7 @@ use Cake\Core\App;
 use Cake\Core\Configure;
 use Cake\Core\Object;
 use Cake\Core\Plugin;
-use Cake\Error;
+use Cake\Error\Exception;
 use Cake\Event\Event;
 use Cake\Event\EventListener;
 use Cake\Event\EventManager;
@@ -357,14 +357,14 @@ class Controller extends Object implements EventListener {
  *
  * @return mixed The resulting response.
  * @throws \Cake\Error\Exception When request is not set.
- * @throws \Cake\Error\PrivateActionException When actions are not public or prefixed by _
- * @throws \Cake\Error\MissingActionException When actions are not defined.
+ * @throws \Cake\Controller\Error\PrivateActionException When actions are not public or prefixed by _
+ * @throws \Cake\Controller\Error\MissingActionException When actions are not defined.
  */
 	public function invokeAction() {
 		try {
 			$request = $this->request;
 			if (!isset($request)) {
-				throw new Error\Exception('No Request object configured. Cannot invoke action');
+				throw new Exception('No Request object configured. Cannot invoke action');
 			}
 			$method = new \ReflectionMethod($this, $request->params['action']);
 			if ($this->_isPrivateAction($method, $request)) {

+ 3 - 1
src/Error/MissingActionException.php

@@ -15,7 +15,9 @@
  * @since         3.0.0
  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
  */
-namespace Cake\Error;
+namespace Cake\Controller\Error;
+
+use Cake\Error\Exception;
 
 /**
  * Missing Action exception - used when a controller action

+ 3 - 1
src/Error/MissingComponentException.php

@@ -15,7 +15,9 @@
  * @since         3.0.0
  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
  */
-namespace Cake\Error;
+namespace Cake\Controller\Error;
+
+use Cake\Error\Exception;
 
 /**
  * Used when a component cannot be found.

+ 3 - 1
src/Error/MissingControllerException.php

@@ -15,7 +15,9 @@
  * @since         3.0.0
  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
  */
-namespace Cake\Error;
+namespace Cake\Controller\Error;
+
+use Cake\Error\Exception;
 
 /**
  * Missing Controller exception - used when a controller

+ 3 - 1
src/Error/PrivateActionException.php

@@ -13,7 +13,9 @@
  * @since         3.0.0
  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
  */
-namespace Cake\Error;
+namespace Cake\Controller\Error;
+
+use Cake\Error\Exception;
 
 /**
  * Private Action exception - used when a controller action

+ 3 - 2
src/Routing/Dispatcher.php

@@ -20,6 +20,7 @@
 namespace Cake\Routing;
 
 use Cake\Controller\Controller;
+use Cake\Controller\Error\MissingControllerException;
 use Cake\Core\App;
 use Cake\Core\Configure;
 use Cake\Core\Plugin;
@@ -139,7 +140,7 @@ class Dispatcher implements EventListener {
  * @param \Cake\Network\Response $response Response object to put the results of the dispatch into.
  * @param array $additionalParams Settings array ("bare", "return") which is melded with the GET and POST params
  * @return string|void if `$request['return']` is set then it returns response body, null otherwise
- * @throws \Cake\Error\MissingControllerException When the controller is missing.
+ * @throws \Cake\Controller\Error\MissingControllerException When the controller is missing.
  */
 	public function dispatch(Request $request, Response $response, array $additionalParams = array()) {
 		$beforeEvent = new Event('Dispatcher.beforeDispatch', $this, compact('request', 'response', 'additionalParams'));
@@ -157,7 +158,7 @@ class Dispatcher implements EventListener {
 		$controller = $this->_getController($request, $response);
 
 		if (!($controller instanceof Controller)) {
-			throw new Error\MissingControllerException(array(
+			throw new MissingControllerException(array(
 				'class' => Inflector::camelize($request->params['controller']),
 				'plugin' => empty($request->params['plugin']) ? null : Inflector::camelize($request->params['plugin']),
 				'prefix' => empty($request->params['prefix']) ? null : Inflector::camelize($request->params['prefix']),

+ 6 - 4
src/TestSuite/ControllerTestCase.php

@@ -14,6 +14,8 @@
  */
 namespace Cake\TestSuite;
 
+use Cake\Controller\Error\MissingComponentException;
+use Cake\Controller\Error\MissingControllerException;
 use Cake\Core\App;
 use Cake\Error;
 use Cake\Event\Event;
@@ -306,14 +308,14 @@ abstract class ControllerTestCase extends TestCase {
  * @param string $controller Controller name
  * @param array $mocks List of classes and methods to mock
  * @return \Cake\Controller\Controller Mocked controller
- * @throws \Cake\Error\MissingControllerException When controllers could not be created.
- * @throws \Cake\Error\MissingComponentException When components could not be created.
+ * @throws \Cake\Controller\Error\MissingControllerException When controllers could not be created.
+ * @throws \Cake\Controller\Error\MissingComponentException When components could not be created.
  */
 	public function generate($controller, array $mocks = array()) {
 		$classname = App::classname($controller, 'Controller', 'Controller');
 		if (!$classname) {
 			list($plugin, $controller) = pluginSplit($controller);
-			throw new Error\MissingControllerException(array(
+			throw new MissingControllerException(array(
 				'class' => $controller . 'Controller',
 				'plugin' => $plugin
 			));
@@ -357,7 +359,7 @@ abstract class ControllerTestCase extends TestCase {
 			$componentClass = App::classname($component, 'Controller/Component', 'Component');
 			list(, $name) = pluginSplit($component, true);
 			if (!$componentClass) {
-				throw new Error\MissingComponentException(array(
+				throw new MissingComponentException(array(
 					'class' => $name . 'Component'
 				));
 			}

+ 2 - 1
tests/TestCase/Console/ConsoleErrorHandlerTest.php

@@ -15,6 +15,7 @@
 namespace Cake\Test\TestCase\Console;
 
 use Cake\Console\ConsoleErrorHandler;
+use Cake\Controller\Error\MissingActionException;
 use Cake\Error;
 use Cake\Log\Log;
 use Cake\TestSuite\TestCase;
@@ -81,7 +82,7 @@ class ConsoleErrorHandlerTest extends TestCase {
  * @return void
  */
 	public function testCakeErrors() {
-		$exception = new Error\MissingActionException('Missing action');
+		$exception = new MissingActionException('Missing action');
 		$message = sprintf('Missing action in [%s, line %s]', $exception->getFile(), $exception->getLine());
 		$this->stderr->expects($this->once())->method('write')
 			->with($this->stringContains($message));

+ 1 - 1
tests/TestCase/Controller/ComponentRegistryTest.php

@@ -114,7 +114,7 @@ class ComponentRegistryTest extends TestCase {
 /**
  * test missingcomponent exception
  *
- * @expectedException \Cake\Error\MissingComponentException
+ * @expectedException \Cake\Controller\Error\MissingComponentException
  * @return void
  */
 	public function testLoadMissingComponent() {

+ 6 - 6
tests/TestCase/Controller/ControllerTest.php

@@ -720,7 +720,7 @@ class ControllerTest extends TestCase {
 /**
  * testMissingAction method
  *
- * @expectedException \Cake\Error\MissingActionException
+ * @expectedException \Cake\Controller\Error\MissingActionException
  * @expectedExceptionMessage Action TestController::missing() could not be found.
  * @return void
  */
@@ -736,7 +736,7 @@ class ControllerTest extends TestCase {
 /**
  * test invoking private methods.
  *
- * @expectedException \Cake\Error\PrivateActionException
+ * @expectedException \Cake\Controller\Error\PrivateActionException
  * @expectedExceptionMessage Private Action TestController::private_m() is not directly accessible.
  * @return void
  */
@@ -752,7 +752,7 @@ class ControllerTest extends TestCase {
 /**
  * test invoking protected methods.
  *
- * @expectedException \Cake\Error\PrivateActionException
+ * @expectedException \Cake\Controller\Error\PrivateActionException
  * @expectedExceptionMessage Private Action TestController::protected_m() is not directly accessible.
  * @return void
  */
@@ -768,7 +768,7 @@ class ControllerTest extends TestCase {
 /**
  * test invoking hidden methods.
  *
- * @expectedException \Cake\Error\PrivateActionException
+ * @expectedException \Cake\Controller\Error\PrivateActionException
  * @expectedExceptionMessage Private Action TestController::_hidden() is not directly accessible.
  * @return void
  */
@@ -784,7 +784,7 @@ class ControllerTest extends TestCase {
 /**
  * test invoking controller methods.
  *
- * @expectedException \Cake\Error\PrivateActionException
+ * @expectedException \Cake\Controller\Error\PrivateActionException
  * @expectedExceptionMessage Private Action TestController::redirect() is not directly accessible.
  * @return void
  */
@@ -800,7 +800,7 @@ class ControllerTest extends TestCase {
 /**
  * test invoking controller methods.
  *
- * @expectedException \Cake\Error\PrivateActionException
+ * @expectedException \Cake\Controller\Error\PrivateActionException
  * @expectedExceptionMessage Private Action TestController::admin_add() is not directly accessible.
  * @return void
  */

+ 11 - 7
tests/TestCase/Error/ExceptionRendererTest.php

@@ -18,6 +18,10 @@ namespace Cake\Test\TestCase\Error;
 
 use Cake\Controller\Component;
 use Cake\Controller\Controller;
+use Cake\Controller\Error\MissingActionException;
+use Cake\Controller\Error\MissingComponentException;
+use Cake\Controller\Error\MissingControllerException;
+use Cake\Controller\Error\PrivateActionException;
 use Cake\Core\App;
 use Cake\Core\Configure;
 use Cake\Error;
@@ -212,7 +216,7 @@ class ExceptionRendererTest extends TestCase {
 	public function testSubclassConvertingFrameworkErrors() {
 		Configure::write('debug', false);
 
-		$exception = new Error\MissingControllerException('PostsController');
+		$exception = new MissingControllerException('PostsController');
 		$ExceptionRenderer = $this->_mockResponse(new MyCustomExceptionRenderer($exception));
 
 		$this->assertEquals('error400', $ExceptionRenderer->method);
@@ -245,7 +249,7 @@ class ExceptionRendererTest extends TestCase {
  */
 	public function testErrorMethodCoercion() {
 		Configure::write('debug', false);
-		$exception = new Error\MissingActionException('Page not found');
+		$exception = new MissingActionException('Page not found');
 		$ExceptionRenderer = new ExceptionRenderer($exception);
 
 		$this->assertInstanceOf('Cake\Controller\ErrorController', $ExceptionRenderer->controller);
@@ -393,7 +397,7 @@ class ExceptionRendererTest extends TestCase {
 		$result = ob_get_clean();
 		$this->assertContains('Custom message', $result);
 
-		$exception = new Error\MissingActionException(array('controller' => 'PostsController', 'action' => 'index'));
+		$exception = new MissingActionException(array('controller' => 'PostsController', 'action' => 'index'));
 		$ExceptionRenderer = $this->_mockResponse(new ExceptionRenderer($exception));
 
 		ob_start();
@@ -469,7 +473,7 @@ class ExceptionRendererTest extends TestCase {
  * @return void
  */
 	public function testMissingController() {
-		$exception = new Error\MissingControllerException(array(
+		$exception = new MissingControllerException(array(
 			'class' => 'Posts',
 			'prefix' => '',
 			'plugin' => '',
@@ -492,7 +496,7 @@ class ExceptionRendererTest extends TestCase {
 	public static function testProvider() {
 		return array(
 			array(
-				new Error\MissingActionException(array(
+				new MissingActionException(array(
 					'controller' => 'PostsController',
 					'action' => 'index',
 					'prefix' => '',
@@ -505,7 +509,7 @@ class ExceptionRendererTest extends TestCase {
 				404
 			),
 			array(
-				new Error\PrivateActionException(array('controller' => 'PostsController', 'action' => '_secretSauce')),
+				new PrivateActionException(array('controller' => 'PostsController', 'action' => '_secretSauce')),
 				array(
 					'/<h2>Private Method in PostsController<\/h2>/',
 					'/<em>PostsController::_secretSauce\(\)<\/em>/'
@@ -547,7 +551,7 @@ class ExceptionRendererTest extends TestCase {
 				500
 			),
 			array(
-				new Error\MissingComponentException(array('class' => 'SideboxComponent')),
+				new MissingComponentException(array('class' => 'SideboxComponent')),
 				array(
 					'/<h2>Missing Component<\/h2>/',
 					'/Create the class <em>SideboxComponent<\/em> below in file:/',

+ 8 - 6
tests/TestCase/Routing/DispatcherTest.php

@@ -17,6 +17,8 @@ namespace Cake\Test\TestCase\Routing;
 
 use Cake\Cache\Cache;
 use Cake\Controller\Controller;
+use Cake\Controller\Error\MissingActionException;
+use Cake\Controller\Error\MissingControllerException;
 use Cake\Core\App;
 use Cake\Core\Configure;
 use Cake\Core\Plugin;
@@ -334,7 +336,7 @@ class DispatcherTest extends TestCase {
 /**
  * testMissingController method
  *
- * @expectedException \Cake\Error\MissingControllerException
+ * @expectedException \Cake\Controller\Error\MissingControllerException
  * @expectedExceptionMessage Controller class SomeController could not be found.
  * @return void
  */
@@ -352,7 +354,7 @@ class DispatcherTest extends TestCase {
 /**
  * testMissingControllerInterface method
  *
- * @expectedException \Cake\Error\MissingControllerException
+ * @expectedException \Cake\Controller\Error\MissingControllerException
  * @expectedExceptionMessage Controller class DispatcherTestInterface could not be found.
  * @return void
  */
@@ -370,7 +372,7 @@ class DispatcherTest extends TestCase {
 /**
  * testMissingControllerInterface method
  *
- * @expectedException \Cake\Error\MissingControllerException
+ * @expectedException \Cake\Controller\Error\MissingControllerException
  * @expectedExceptionMessage Controller class Abstract could not be found.
  * @return void
  */
@@ -698,7 +700,7 @@ class DispatcherTest extends TestCase {
 		try {
 			$Dispatcher->dispatch($url, $response, array('return' => 1));
 			$this->fail('No exception.');
-		} catch (Error\MissingActionException $e) {
+		} catch (MissingActionException $e) {
 			$this->assertEquals('Action SomePostsController::view() could not be found.', $e->getMessage());
 		}
 
@@ -730,14 +732,14 @@ class DispatcherTest extends TestCase {
 		try {
 			$Dispatcher->dispatch(new Request('theme/test_theme/../webroot/css/test_asset.css'), $response);
 			$this->fail('No exception');
-		} catch (Error\MissingControllerException $e) {
+		} catch (MissingControllerException $e) {
 			$this->assertEquals('Controller class Theme could not be found.', $e->getMessage());
 		}
 
 		try {
 			$Dispatcher->dispatch(new Request('theme/test_theme/pdfs'), $response);
 			$this->fail('No exception');
-		} catch (Error\MissingControllerException $e) {
+		} catch (MissingControllerException $e) {
 			$this->assertEquals('Controller class Theme could not be found.', $e->getMessage());
 		}
 	}

+ 1 - 1
tests/TestCase/TestSuite/ControllerTestCaseTest.php

@@ -265,7 +265,7 @@ class ControllerTestCaseTest extends TestCase {
 /**
  * Tests not using loaded routes during tests
  *
- * @expectedException \Cake\Error\MissingActionException
+ * @expectedException \Cake\Controller\Error\MissingActionException
  * @return void
  */
 	public function testSkipRoutes() {