Skip to content

Commit

Permalink
Add @trigger doc blocks of methods triggering CakeEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
Guy Warner committed Nov 30, 2014
1 parent ac02350 commit fb61d93
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/Cake/Controller/Controller.php
Expand Up @@ -669,6 +669,8 @@ public function getEventManager() {
* - triggers Component `startup` methods.
*
* @return void
* @triggers Controller.initialize $this
* @triggers Controller.startup $this
*/
public function startupProcess() {
$this->getEventManager()->dispatch(new CakeEvent('Controller.initialize', $this));
Expand All @@ -683,6 +685,7 @@ public function startupProcess() {
* - calls the Controller's `afterFilter` method.
*
* @return void
* @triggers Controller.shutdown $this
*/
public function shutdownProcess() {
$this->getEventManager()->dispatch(new CakeEvent('Controller.shutdown', $this));
Expand Down Expand Up @@ -751,6 +754,7 @@ public function loadModel($modelClass = null, $id = null) {
* @param int $status Optional HTTP status code (eg: 404)
* @param bool $exit If true, exit() will be called after the redirect
* @return void
* @triggers Controller.beforeRedirect $this, array($url, $status, $exit)
* @link http://book.cakephp.org/2.0/en/controllers.html#Controller::redirect
*/
public function redirect($url, $status = null, $exit = true) {
Expand Down Expand Up @@ -920,6 +924,7 @@ public function validateErrors() {
* @param string $view View to use for rendering
* @param string $layout Layout to use
* @return CakeResponse A response object containing the rendered view.
* @triggers Controller.beforeRender $this
* @link http://book.cakephp.org/2.0/en/controllers.html#Controller::render
*/
public function render($view = null, $layout = null) {
Expand Down
1 change: 1 addition & 0 deletions lib/Cake/Event/CakeEventManager.php
Expand Up @@ -221,6 +221,7 @@ protected function _detachSubscriber(CakeEventListener $subscriber, $eventKey =
*
* @param string|CakeEvent $event the event key name or instance of CakeEvent
* @return CakeEvent
* @triggers $event
*/
public function dispatch($event) {
if (is_string($event)) {
Expand Down
6 changes: 6 additions & 0 deletions lib/Cake/Model/Model.php
Expand Up @@ -1699,6 +1699,8 @@ public function saveField($name, $value, $validate = false) {
* @param array $fieldList List of fields to allow to be saved
* @return mixed On success Model::$data if its not empty or true, false on failure
* @throws PDOException
* @triggers Model.beforeSave $this, array($options)
* @triggers Model.afterSave $this, array($created, $options)
* @link http://book.cakephp.org/2.0/en/models/saving-your-data.html
*/
public function save($data = null, $validate = true, $fieldList = array()) {
Expand Down Expand Up @@ -2591,6 +2593,8 @@ public function updateAll($fields, $conditions = true) {
* @param int|string $id ID of record to delete
* @param bool $cascade Set to true to delete records that depend on this record
* @return bool True on success
* @triggers Model.beforeDelete $this, array($cascade)
* @triggers Model.afterDelete $this)
* @link http://book.cakephp.org/2.0/en/models/deleting-data.html
*/
public function delete($id = null, $cascade = true) {
Expand Down Expand Up @@ -2964,6 +2968,7 @@ protected function _readDataSource($type, $query) {
* @param string $type Type of find operation (all / first / count / neighbors / list / threaded)
* @param array $query Option fields (conditions / fields / joins / limit / offset / order / page / group / callbacks)
* @return array|null Query array or null if it could not be build for some reasons
* @triggers Model.beforeFind $this, array($query)
* @see Model::find()
*/
public function buildQuery($type = 'first', $query = array()) {
Expand Down Expand Up @@ -3252,6 +3257,7 @@ protected function _findThreaded($state, $query, $results = array()) {
* @param array $results Results to filter
* @param bool $primary If this is the primary model results (results from model where the find operation was performed)
* @return array Set of filtered results
* @triggers Model.afterFind $this, array($results, $primary)
*/
protected function _filterResults($results, $primary = true) {
$event = new CakeEvent('Model.afterFind', $this, array($results, $primary));
Expand Down
2 changes: 2 additions & 0 deletions lib/Cake/Model/ModelValidator.php
Expand Up @@ -235,6 +235,7 @@ public function validateMany(&$data, $options = array()) {
*
* @param string $options An optional array of custom options to be made available in the beforeValidate callback
* @return array Array of invalid fields
* @triggers Model.afterValidate $model
* @see ModelValidator::validates()
*/
public function errors($options = array()) {
Expand Down Expand Up @@ -444,6 +445,7 @@ protected function _validateWithModels($options) {
*
* @param array $options Options to pass to callback.
* @return bool
* @triggers Model.beforeValidate $model, array($options)
*/
protected function _triggerBeforeValidate($options = array()) {
$model = $this->getModel();
Expand Down
2 changes: 2 additions & 0 deletions lib/Cake/Routing/Dispatcher.php
Expand Up @@ -138,6 +138,8 @@ protected function _attachFilters($manager) {
* @param CakeResponse $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
* @triggers Dispatcher.beforeDispatch $this, compact('request', 'response', 'additionalParams')
* @triggers Dispatcher.afterDispatch $this, compact('request', 'response')
* @throws MissingControllerException When the controller is missing.
*/
public function dispatch(CakeRequest $request, CakeResponse $response, $additionalParams = array()) {
Expand Down
14 changes: 14 additions & 0 deletions lib/Cake/Test/Case/Event/CakeEventManagerTest.php
Expand Up @@ -193,6 +193,7 @@ public function testDetachFromAll() {
* Tests event dispatching
*
* @return void
* @triggers fake.event
*/
public function testDispatch() {
$manager = new CakeEventManager();
Expand Down Expand Up @@ -227,6 +228,7 @@ public function testDispatchWithKeyName() {
* Tests event dispatching with a return value
*
* @return void
* @triggers fake.event
*/
public function testDispatchReturnValue() {
$this->skipIf(
Expand Down Expand Up @@ -254,6 +256,7 @@ public function testDispatchReturnValue() {
* Tests that returning false in a callback stops the event
*
* @return void
* @triggers fake.event
*/
public function testDispatchFalseStopsEvent() {
$this->skipIf(
Expand Down Expand Up @@ -281,6 +284,7 @@ public function testDispatchFalseStopsEvent() {
* Tests event dispatching using priorities
*
* @return void
* @triggers fake.event
*/
public function testDispatchPrioritized() {
$manager = new CakeEventManager();
Expand All @@ -298,6 +302,7 @@ public function testDispatchPrioritized() {
* Tests event dispatching with passed params
*
* @return void
* @triggers fake.event $this, array('some' => 'data')
*/
public function testDispatchPassingParams() {
$manager = new CakeEventManager();
Expand All @@ -316,6 +321,9 @@ public function testDispatchPassingParams() {
* Tests subscribing a listener object and firing the events it subscribed to
*
* @return void
* @triggers fake.event
* @triggers another.event $this, array('some' => 'data')
* @triggers multiple.handlers
*/
public function testAttachSubscriber() {
$manager = new CakeEventManager();
Expand Down Expand Up @@ -380,6 +388,7 @@ public function testGlobalDispatcherGetter() {
* Tests that the global event manager gets the event too from any other manager
*
* @return void
* @triggers fake.event
*/
public function testDispatchWithGlobal() {
$generalManager = $this->getMock('CakeEventManager', array('prioritisedListeners'));
Expand All @@ -396,6 +405,7 @@ public function testDispatchWithGlobal() {
* Tests that stopping an event will not notify the rest of the listeners
*
* @return void
* @triggers fake.event
*/
public function testStopPropagation() {
$generalManager = $this->getMock('CakeEventManager');
Expand Down Expand Up @@ -423,6 +433,7 @@ public function testStopPropagation() {
* Tests event dispatching using priorities
*
* @return void
* @triggers fake.event
*/
public function testDispatchPrioritizedWithGlobal() {
$generalManager = $this->getMock('CakeEventManager');
Expand Down Expand Up @@ -454,6 +465,7 @@ public function testDispatchPrioritizedWithGlobal() {
* Tests event dispatching using priorities
*
* @return void
* @triggers fake.event
*/
public function testDispatchGlobalBeforeLocal() {
$generalManager = $this->getMock('CakeEventManager');
Expand Down Expand Up @@ -490,6 +502,7 @@ public function onMyEvent($event) {
/**
* Tests events dispatched by a local manager can be handled by
* handler registered in the global event manager
* @triggers my_event $manager
*/
public function testDispatchLocalHandledByGlobal() {
$callback = array($this, 'onMyEvent');
Expand All @@ -505,6 +518,7 @@ public function testDispatchLocalHandledByGlobal() {
* listeners at the same priority.
*
* @return void
* @triggers fake.event $this)
*/
public function testDispatchWithGlobalAndLocalEvents() {
$listener = new CustomTestEventListener();
Expand Down
6 changes: 6 additions & 0 deletions lib/Cake/Test/Case/Event/CakeEventTest.php
Expand Up @@ -30,6 +30,7 @@ class CakeEventTest extends CakeTestCase {
* Tests the name() method
*
* @return void
* @triggers fake.event
*/
public function testName() {
$event = new CakeEvent('fake.event');
Expand All @@ -40,6 +41,8 @@ public function testName() {
* Tests the subject() method
*
* @return void
* @triggers fake.event $this
* @triggers fake.event
*/
public function testSubject() {
$event = new CakeEvent('fake.event', $this);
Expand All @@ -53,6 +56,7 @@ public function testSubject() {
* Tests the event propagation stopping property
*
* @return void
* @triggers fake.event
*/
public function testPropagation() {
$event = new CakeEvent('fake.event');
Expand All @@ -65,6 +69,7 @@ public function testPropagation() {
* Tests that it is possible to get/set custom data in a event
*
* @return void
* @triggers fake.event $this, array('some' => 'data')
*/
public function testEventData() {
$event = new CakeEvent('fake.event', $this, array('some' => 'data'));
Expand All @@ -75,6 +80,7 @@ public function testEventData() {
* Tests that it is possible to get the name and subject directly
*
* @return void
* @triggers fake.event $this
*/
public function testEventDirectPropertyAccess() {
$event = new CakeEvent('fake.event', $this);
Expand Down
14 changes: 14 additions & 0 deletions lib/Cake/Test/Case/Routing/DispatcherTest.php
Expand Up @@ -589,6 +589,7 @@ public function tearDown() {
* testParseParamsWithoutZerosAndEmptyPost method
*
* @return void
* @triggers DispatcherTest $Dispatcher, array('request' => $request)
*/
public function testParseParamsWithoutZerosAndEmptyPost() {
$Dispatcher = new Dispatcher();
Expand All @@ -607,6 +608,7 @@ public function testParseParamsWithoutZerosAndEmptyPost() {
* testParseParamsReturnsPostedData method
*
* @return void
* @triggers DispatcherTest $Dispatcher, array('request' => $request)
*/
public function testParseParamsReturnsPostedData() {
$_POST['testdata'] = "My Posted Content";
Expand All @@ -622,6 +624,7 @@ public function testParseParamsReturnsPostedData() {
* testParseParamsWithSingleZero method
*
* @return void
* @triggers DispatcherTest $Dispatcher, array('request' => $test)
*/
public function testParseParamsWithSingleZero() {
$Dispatcher = new Dispatcher();
Expand All @@ -640,6 +643,7 @@ public function testParseParamsWithSingleZero() {
* testParseParamsWithManySingleZeros method
*
* @return void
* @triggers DispatcherTest $Dispatcher, array('request' => $test)
*/
public function testParseParamsWithManySingleZeros() {
$Dispatcher = new Dispatcher();
Expand All @@ -659,6 +663,7 @@ public function testParseParamsWithManySingleZeros() {
* testParseParamsWithManyZerosInEachSectionOfUrl method
*
* @return void
* @triggers DispatcherTest $Dispatcher, array('request' => $test)
*/
public function testParseParamsWithManyZerosInEachSectionOfUrl() {
$Dispatcher = new Dispatcher();
Expand All @@ -678,6 +683,7 @@ public function testParseParamsWithManyZerosInEachSectionOfUrl() {
* testParseParamsWithMixedOneToManyZerosInEachSectionOfUrl method
*
* @return void
* @triggers DispatcherTest $Dispatcher, array('request' => $test)
*/
public function testParseParamsWithMixedOneToManyZerosInEachSectionOfUrl() {
$Dispatcher = new Dispatcher();
Expand All @@ -697,6 +703,8 @@ public function testParseParamsWithMixedOneToManyZerosInEachSectionOfUrl() {
* testQueryStringOnRoot method
*
* @return void
* @triggers DispatcherTest $Dispatcher, array('request' => $request)
* @triggers DispatcherTest $Dispatcher, array('request' => $request)
*/
public function testQueryStringOnRoot() {
Router::reload();
Expand Down Expand Up @@ -928,6 +936,7 @@ public function testAdminDispatch() {
* testPluginDispatch method
*
* @return void
* @triggers DispatcherTest $Dispatcher, array('request' => $url)
*/
public function testPluginDispatch() {
$_POST = array();
Expand Down Expand Up @@ -1640,6 +1649,11 @@ public function testFullPageCachingDispatch($url) {
* testHttpMethodOverrides method
*
* @return void
* @triggers DispatcherTest $dispatcher, array('request' => $request)
* @triggers DispatcherTest $dispatcher, array('request' => $request)
* @triggers DispatcherTest $dispatcher, array('request' => $request)
* @triggers DispatcherTest $dispatcher, array('request' => $request)
* @triggers DispatcherTest $dispatcher, array('request' => $request)
*/
public function testHttpMethodOverrides() {
Router::reload();
Expand Down
12 changes: 12 additions & 0 deletions lib/Cake/Test/Case/Routing/Filter/AssetDispatcherTest.php
Expand Up @@ -39,6 +39,12 @@ public function tearDown() {
* test that asset filters work for theme and plugin assets
*
* @return void
* @triggers DispatcherTest $this, compact('request', 'response')
* @triggers DispatcherTest $this, compact('request', 'response')
* @triggers DispatcherTest $this, compact('request', 'response')
* @triggers DispatcherTest $this, compact('request', 'response')
* @triggers DispatcherTest $this, compact('request', 'response')
* @triggers DispatcherTest $this, compact('request', 'response')
*/
public function testAssetFilterForThemeAndPlugins() {
$filter = new AssetDispatcher();
Expand Down Expand Up @@ -88,6 +94,7 @@ public function testAssetFilterForThemeAndPlugins() {
* by Routing.
*
* @return void
* @triggers DispatcherTest $this, compact('request', 'response')
*/
public function testNoHandleRoutedExtension() {
$filter = new AssetDispatcher();
Expand Down Expand Up @@ -115,6 +122,8 @@ public function testNoHandleRoutedExtension() {
* file dispatching
*
* @return void
* @triggers DispatcherTest $this, compact('request', 'response')
* @triggers DispatcherTest $this, compact('request', 'response')
*/
public function testNotModified() {
$filter = new AssetDispatcher();
Expand Down Expand Up @@ -160,6 +169,7 @@ public function testNotModified() {
* Test that no exceptions are thrown for //index.php type URLs.
*
* @return void
* @triggers Dispatcher.beforeRequest $this, compact('request', 'response')
*/
public function test404OnDoubleSlash() {
$filter = new AssetDispatcher();
Expand All @@ -176,6 +186,7 @@ public function test404OnDoubleSlash() {
* Test that attempts to traverse directories are prevented.
*
* @return void
* @triggers Dispatcher.beforeRequest $this, compact('request', 'response')
*/
public function test404OnDoubleDot() {
App::build(array(
Expand All @@ -198,6 +209,7 @@ public function test404OnDoubleDot() {
* Test that attempts to traverse directories with urlencoded paths fail.
*
* @return void
* @triggers Dispatcher.beforeRequest $this, compact('request', 'response')
*/
public function test404OnDoubleDotEncoded() {
App::build(array(
Expand Down
2 changes: 2 additions & 0 deletions lib/Cake/Test/Case/Utility/ObjectCollectionTest.php
Expand Up @@ -535,6 +535,7 @@ public function testnormalizeObjectArray() {
* tests that passing an instance of CakeEvent to trigger will prepend the subject to the list of arguments
*
* @return void
* @triggers callback $subjectClass, array('first argument')
*/
public function testDispatchEventWithSubject() {
$this->_makeMockClasses();
Expand All @@ -560,6 +561,7 @@ public function testDispatchEventWithSubject() {
* will NOT prepend the subject to the list of arguments
*
* @return void
* @triggers callback $subjectClass, array('first argument')
*/
public function testDispatchEventNoSubject() {
$this->_makeMockClasses();
Expand Down
1 change: 1 addition & 0 deletions lib/Cake/TestSuite/ControllerTestCase.php
Expand Up @@ -213,6 +213,7 @@ public function __call($name, $arguments) {
* @param string $url The url to test
* @param array $options See options
* @return mixed
* @triggers ControllerTestCase $Dispatch, array('request' => $request
*/
protected function _testAction($url = '', $options = array()) {
$this->vars = $this->result = $this->view = $this->contents = $this->headers = null;
Expand Down

0 comments on commit fb61d93

Please sign in to comment.