Fork me on GitHub
Heads up!
These docs are for Crud v3 - that only works with CakePHP 2.x. For CRUD v4 docs please go to the new documentation site
The CRUD v4 documentation has been completely rewritten, and since CRUD v3 and CRUD v4 API is ~95% identical, it may be worth a look for CRUD v3 users as well until v4 docs are backported for v3.
...toc....

Unit Testing with Crud

To ease with unit testing of Crud Listeners and Crud Actions, it’s recommended to use the proxy methods found in CrudBaseObject.

These methods are much easier to mock than the full CrudComponent object.

They also allow you to just mock the methods you need for your specific test, rather than the big dependency nightmare the CrudComponent can be in some cases.

Proxy methods

These methods are available in all CrudAction and CrudListener objects.

Proxy method Same as Description
$this->_crud() $this->_container->crud Get the CrudComponent instance
$this->_action($name) $this->_crud()->action($name) Get an CrudAction object by it's action name
$this->_trigger($eventName, $data = []) $this->_crud()->trigger($eventName, $data = array()) Trigger a CrudEvent
$this->_listener($name) $this->_crud()->listener($name) Get a Crud Listener by its name
$this->_subject($additional = array()) $this->_crud()->getSubject($additional = array()) Create a Crud event subject - used in $this->_trigger
$this->_session() $this->_crud()->Session Get the Session Component instance
$this->_controller() $this->_container->controller Get the controller for the current request
$this->_request() $this->_container->request Get the current CakeRequest for this request
$this->_model() $this->_container->model Get the model instance that is created from Controller::$modelClass



comments powered by Disqus