Skip to content

Commit

Permalink
Move controller related exceptions under Controller/Error
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Apr 13, 2014
1 parent 98c861a commit 370a89d
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 38 deletions.
3 changes: 1 addition & 2 deletions src/Controller/ComponentRegistry.php
Expand Up @@ -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;
Expand Down Expand Up @@ -76,7 +75,7 @@ protected function _resolveClassName($class) {
*
* @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([
Expand Down
8 changes: 4 additions & 4 deletions src/Controller/Controller.php
Expand Up @@ -18,7 +18,7 @@
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;
Expand Down Expand Up @@ -357,14 +357,14 @@ public function setRequest(Request $request) {
*
* @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)) {
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -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.
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/Routing/Dispatcher.php
Expand Up @@ -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;
Expand Down Expand Up @@ -139,7 +140,7 @@ protected function _attachFilters($manager) {
* @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'));
Expand All @@ -157,7 +158,7 @@ public function dispatch(Request $request, Response $response, array $additional
$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']),
Expand Down
10 changes: 6 additions & 4 deletions src/TestSuite/ControllerTestCase.php
Expand Up @@ -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;
Expand Down Expand Up @@ -306,14 +308,14 @@ protected function _testAction($url = '', $options = array()) {
* @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
));
Expand Down Expand Up @@ -357,7 +359,7 @@ public function generate($controller, array $mocks = array()) {
$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'
));
}
Expand Down
3 changes: 2 additions & 1 deletion tests/TestCase/Console/ConsoleErrorHandlerTest.php
Expand Up @@ -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;
Expand Down Expand Up @@ -81,7 +82,7 @@ public function testHandleFatalError() {
* @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));
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Controller/ComponentRegistryTest.php
Expand Up @@ -114,7 +114,7 @@ public function testLoadWithEnableFalse() {
/**
* test missingcomponent exception
*
* @expectedException \Cake\Error\MissingComponentException
* @expectedException \Cake\Controller\Error\MissingComponentException
* @return void
*/
public function testLoadMissingComponent() {
Expand Down
12 changes: 6 additions & 6 deletions tests/TestCase/Controller/ControllerTest.php
Expand Up @@ -720,7 +720,7 @@ public function testPaginateUsesModelClass() {
/**
* testMissingAction method
*
* @expectedException \Cake\Error\MissingActionException
* @expectedException \Cake\Controller\Error\MissingActionException
* @expectedExceptionMessage Action TestController::missing() could not be found.
* @return void
*/
Expand All @@ -736,7 +736,7 @@ public function testInvokeActionMissingAction() {
/**
* 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
*/
Expand All @@ -752,7 +752,7 @@ public function testInvokeActionPrivate() {
/**
* 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
*/
Expand All @@ -768,7 +768,7 @@ public function testInvokeActionProtected() {
/**
* test invoking hidden methods.
*
* @expectedException \Cake\Error\PrivateActionException
* @expectedException \Cake\Controller\Error\PrivateActionException
* @expectedExceptionMessage Private Action TestController::_hidden() is not directly accessible.
* @return void
*/
Expand All @@ -784,7 +784,7 @@ public function testInvokeActionHidden() {
/**
* test invoking controller methods.
*
* @expectedException \Cake\Error\PrivateActionException
* @expectedException \Cake\Controller\Error\PrivateActionException
* @expectedExceptionMessage Private Action TestController::redirect() is not directly accessible.
* @return void
*/
Expand All @@ -800,7 +800,7 @@ public function testInvokeActionBaseMethods() {
/**
* 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
*/
Expand Down
18 changes: 11 additions & 7 deletions tests/TestCase/Error/ExceptionRendererTest.php
Expand Up @@ -18,6 +18,10 @@

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;
Expand Down Expand Up @@ -212,7 +216,7 @@ public function testSubclassMethodsNotBeingConvertedDebug0() {
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);
Expand Down Expand Up @@ -245,7 +249,7 @@ public function testConstruction() {
*/
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);
Expand Down Expand Up @@ -393,7 +397,7 @@ public function testerror400OnlyChangingCakeException() {
$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();
Expand Down Expand Up @@ -469,7 +473,7 @@ public function testExceptionResponseHeader() {
* @return void
*/
public function testMissingController() {
$exception = new Error\MissingControllerException(array(
$exception = new MissingControllerException(array(
'class' => 'Posts',
'prefix' => '',
'plugin' => '',
Expand All @@ -492,7 +496,7 @@ public function testMissingController() {
public static function testProvider() {
return array(
array(
new Error\MissingActionException(array(
new MissingActionException(array(
'controller' => 'PostsController',
'action' => 'index',
'prefix' => '',
Expand All @@ -505,7 +509,7 @@ public static function testProvider() {
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>/'
Expand Down Expand Up @@ -547,7 +551,7 @@ public static function testProvider() {
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:/',
Expand Down
14 changes: 8 additions & 6 deletions tests/TestCase/Routing/DispatcherTest.php
Expand Up @@ -17,6 +17,8 @@

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;
Expand Down Expand Up @@ -334,7 +336,7 @@ public function testQueryStringOnRoot() {
/**
* testMissingController method
*
* @expectedException \Cake\Error\MissingControllerException
* @expectedException \Cake\Controller\Error\MissingControllerException
* @expectedExceptionMessage Controller class SomeController could not be found.
* @return void
*/
Expand All @@ -352,7 +354,7 @@ public function testMissingController() {
/**
* testMissingControllerInterface method
*
* @expectedException \Cake\Error\MissingControllerException
* @expectedException \Cake\Controller\Error\MissingControllerException
* @expectedExceptionMessage Controller class DispatcherTestInterface could not be found.
* @return void
*/
Expand All @@ -370,7 +372,7 @@ public function testMissingControllerInterface() {
/**
* testMissingControllerInterface method
*
* @expectedException \Cake\Error\MissingControllerException
* @expectedException \Cake\Controller\Error\MissingControllerException
* @expectedExceptionMessage Controller class Abstract could not be found.
* @return void
*/
Expand Down Expand Up @@ -698,7 +700,7 @@ public function testChangingParamsFromBeforeFilter() {
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());
}

Expand Down Expand Up @@ -730,14 +732,14 @@ public function testAssets() {
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());
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/TestSuite/ControllerTestCaseTest.php
Expand Up @@ -265,7 +265,7 @@ public function testUseRoutes() {
/**
* Tests not using loaded routes during tests
*
* @expectedException \Cake\Error\MissingActionException
* @expectedException \Cake\Controller\Error\MissingActionException
* @return void
*/
public function testSkipRoutes() {
Expand Down

0 comments on commit 370a89d

Please sign in to comment.