Class ControllerTestDispatcher
ControllerTestDispatcher class
- Dispatcher implements CakeEventListener
- ControllerTestDispatcher
Copyright: Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
License: MIT License
Location: Cake/TestSuite/ControllerTestCase.php
Properties summary
-
$loadRoutes
publicboolean
Use custom routes during tests -
$testController
publicThe controller to use in the dispatch process
Inherited Properties
Method Summary
-
_getController() protected
Returns the test controller -
_loadRoutes() protected
Loads routes and resets if the test case dictates it should
Method Detail
_getController() protected ¶
_getController( CakeRequest
$request , CakeResponse
$response )
Returns the test controller
Parameters
-
CakeRequest
$request - The request instance.
-
CakeResponse
$response - The response instance.
Returns
Overrides
_loadRoutes() protected ¶
_loadRoutes( )
Loads routes and resets if the test case dictates it should
Methods inherited from Dispatcher
__construct() public ¶
__construct( string $base = false )
Constructor.
Parameters
- string $base optional false
- The base directory for the application. Writes
App.base
to Configure.
_attachFilters() protected ¶
_attachFilters( CakeEventManager
$manager )
Attaches all event listeners for this dispatcher instance. Loads the dispatcher filters from the configured locations.
Parameters
-
CakeEventManager
$manager - Event manager instance.
Throws
_invoke() protected ¶
_invoke( Controller
$controller , CakeRequest
$request )
Initializes the components and models a controller will be using. Triggers the controller action, and invokes the rendering if Controller::$autoRender is true and echo's the output. Otherwise the return value of the controller action are returned.
Parameters
-
Controller
$controller - Controller to invoke
-
CakeRequest
$request - The request object to invoke the controller for.
Returns
_loadController() protected ¶
_loadController( CakeRequest
$request )
Load controller and return controller class name
Parameters
-
CakeRequest
$request - Request instance.
Returns
Name of controller class name
dispatch() public ¶
dispatch( CakeRequest
$request , CakeResponse
$response , array $additionalParams = array() )
Dispatches and invokes given Request, handing over control to the involved controller. If the controller is set to autoRender, via Controller::$autoRender, then Dispatcher will render the view.
Actions in CakePHP can be any public method on a controller, that is not declared in Controller. If you
want controller methods to be public and in-accessible by URL, then prefix them with a _
.
For example public function _loadPosts() { }
would not be accessible via URL. Private and protected methods
are also not accessible via URL.
If no controller of given name can be found, invoke() will throw an exception. If the controller is found, and the action is not found an exception will be thrown.
Parameters
-
CakeRequest
$request - Request object to dispatch.
-
CakeResponse
$response - Response object to put the results of the dispatch into.
- array $additionalParams optional array()
- Settings array ("bare", "return") which is melded with the GET and POST params
Returns
if
$request['return']
is set then it returns response body, null otherwiseThrows
Triggers
Dispatcher.afterDispatch $this, compact('request', 'response')
getEventManager() public ¶
getEventManager( )
Returns the CakeEventManager instance or creates one if none was created. Attaches the default listeners and filters
Returns
implementedEvents() public ¶
implementedEvents( )
Returns the list of events this object listens to.
Returns
Implementation of
parseParams() public ¶
parseParams( CakeEvent
$event )
Applies Routing and additionalParameters to the request to be dispatched. If Routes have not been loaded they will be loaded, and app/Config/routes.php will be run.
Parameters
-
CakeEvent
$event - containing the request, response and additional params