Unit Testing

To ease with unit testing of Crud Listeners and Crud Actions, it’s recommended to use the proxy methods found in [CrudBaseObject]({{site.url}}/api/develop/class-CrudBaseObject.html).

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.

_crud()

Get the CrudComponent instance

$this->_crud()

_action($name)

Get an CrudAction object by it’s action name

$this->_action()
$this->_action($name)

_trigger($eventName, $data = [])

Trigger a Crud Event

$this->_trigger('beforeSave')
$this->_trigger('beforeSave', ['data' => 'keys'])
$this->_trigger('beforeSave', $this->_subject(['data' => 'keys']))

_listener($name)

Get a Listener by its name

$this->_listener('Api')

_subject($additional = [])

Create a Crud Subject - used in $this->_trigger

$this->_subject()
$this->_subject(['data' => 'keys'])

_session()

Get the Session Component instance

$this->_session()

_controller()

Get the controller for the current request

$this->_controller()

_request()

Get the current Cake\Network\Request for this HTTP Request

$this->_request()

_response()

Get the current Cake\Network\Response for this HTTP Request

$this->_response()

_entity()

Get the entity instance that is created from Controller::$modelClass

$this->_entity()

_table()

Get the table instance that is created from Controller::$modelClass

$this->_table()
  v: latest
Versions
latest
stable
4.4.3
4.4.2
4.4.1
4.4.0
4.3.5
4.3.4
4.3.3
4.3.2
4.3.1
4.3.0
4.2.4
4.2.3
4.2.2
4.2.1
4.2.0
4.1.4
v4.0.0
cake3
Downloads
pdf
htmlzip
epub
On Read the Docs
Project Home
Builds
Downloads
On GitHub
View
Edit

Free document hosting provided by Read the Docs.