diff --git a/cake/libs/object_collection.php b/cake/libs/object_collection.php index 831dd555b..d91f62cc9 100644 --- a/cake/libs/object_collection.php +++ b/cake/libs/object_collection.php @@ -107,18 +107,17 @@ abstract class ObjectCollection { if ($options['modParams'] !== false && !isset($params[$options['modParams']])) { throw new CakeException(__('Cannot use modParams with indexes that do not exist.')); } - foreach ($list as $name) { $result = call_user_func_array(array($this->_loaded[$name], $callback), $params); if ($options['collectReturn'] === true) { $collected[] = $result; } if ( - $options['break'] && ($result === $options['breakOn'] || + $options['break'] && ($result === $options['breakOn'] || (is_array($options['breakOn']) && in_array($result, $options['breakOn'], true))) ) { - break; - } elseif ($options['modParams'] !== false && $result !== null) { + return $result; + } elseif ($options['modParams'] !== false && is_array($result)) { $params[$options['modParams']] = $result; } } diff --git a/cake/tests/cases/libs/model/behavior_collection.test.php b/cake/tests/cases/libs/model/behavior_collection.test.php index 12ce1dd4f..27c71e2f9 100644 --- a/cake/tests/cases/libs/model/behavior_collection.test.php +++ b/cake/tests/cases/libs/model/behavior_collection.test.php @@ -46,7 +46,7 @@ class TestBehavior extends ModelBehavior { * @access public * @return void */ - function setup(&$model, $config = array()) { + function setup($model, $config = array()) { parent::setup($model, $config); if (isset($config['mangle'])) { $config['mangle'] .= ' mangled'; @@ -62,7 +62,7 @@ class TestBehavior extends ModelBehavior { * @access public * @return void */ - function beforeFind(&$model, $query) { + function beforeFind($model, $query) { $settings = $this->settings[$model->alias]; if (!isset($settings['beforeFind']) || $settings['beforeFind'] == 'off') { return parent::beforeFind($model, $query); @@ -91,7 +91,7 @@ class TestBehavior extends ModelBehavior { * @access public * @return void */ - function afterFind(&$model, $results, $primary) { + function afterFind($model, $results, $primary) { $settings = $this->settings[$model->alias]; if (!isset($settings['afterFind']) || $settings['afterFind'] == 'off') { return parent::afterFind($model, $results, $primary); @@ -119,7 +119,7 @@ class TestBehavior extends ModelBehavior { * @access public * @return void */ - function beforeSave(&$model) { + function beforeSave($model) { $settings = $this->settings[$model->alias]; if (!isset($settings['beforeSave']) || $settings['beforeSave'] == 'off') { return parent::beforeSave($model); @@ -129,7 +129,7 @@ class TestBehavior extends ModelBehavior { return false; break; case 'test': - return null; + return true; break; case 'modify': $model->data[$model->alias]['name'] .= ' modified before'; @@ -146,7 +146,7 @@ class TestBehavior extends ModelBehavior { * @access public * @return void */ - function afterSave(&$model, $created) { + function afterSave($model, $created) { $settings = $this->settings[$model->alias]; if (!isset($settings['afterSave']) || $settings['afterSave'] == 'off') { return parent::afterSave($model, $created); @@ -178,7 +178,7 @@ class TestBehavior extends ModelBehavior { * @access public * @return void */ - function beforeValidate(&$model) { + function beforeValidate($model) { $settings = $this->settings[$model->alias]; if (!isset($settings['validate']) || $settings['validate'] == 'off') { return parent::beforeValidate($model); @@ -210,7 +210,7 @@ class TestBehavior extends ModelBehavior { * @access public * @return void */ - function beforeDelete(&$model, $cascade = true) { + function beforeDelete($model, $cascade = true) { $settings = $this->settings[$model->alias]; if (!isset($settings['beforeDelete']) || $settings['beforeDelete'] == 'off') { return parent::beforeDelete($model, $cascade); @@ -227,6 +227,7 @@ class TestBehavior extends ModelBehavior { if ($cascade) { echo ' (cascading) '; } + return true; break; } } @@ -238,7 +239,7 @@ class TestBehavior extends ModelBehavior { * @access public * @return void */ - function afterDelete(&$model) { + function afterDelete($model) { $settings = $this->settings[$model->alias]; if (!isset($settings['afterDelete']) || $settings['afterDelete'] == 'off') { return parent::afterDelete($model); @@ -257,10 +258,10 @@ class TestBehavior extends ModelBehavior { * @access public * @return void */ - function onError(&$model) { + function onError($model, $error) { $settings = $this->settings[$model->alias]; if (!isset($settings['onError']) || $settings['onError'] == 'off') { - return parent::onError($model, $cascade); + return parent::onError($model, $error); } echo "onError trigger success"; } @@ -271,7 +272,7 @@ class TestBehavior extends ModelBehavior { * @access public * @return void */ - function beforeTest(&$model) { + function beforeTest($model) { if (!isset($model->beforeTestResult)) { $model->beforeTestResult = array(); } @@ -361,7 +362,7 @@ class Test3Behavior extends TestBehavior{ * @subpackage cake.tests.cases.libs.model */ class Test4Behavior extends ModelBehavior{ - function setup(&$model, $config = null) { + function setup($model, $config = null) { $model->bindModel( array('hasMany' => array('Comment')) ); @@ -375,7 +376,7 @@ class Test4Behavior extends ModelBehavior{ * @subpackage cake.tests.cases.libs.model */ class Test5Behavior extends ModelBehavior{ - function setup(&$model, $config = null) { + function setup($model, $config = null) { $model->bindModel( array('belongsTo' => array('User')) ); @@ -389,7 +390,7 @@ class Test5Behavior extends ModelBehavior{ * @subpackage cake.tests.cases.libs.model */ class Test6Behavior extends ModelBehavior{ - function setup(&$model, $config = null) { + function setup($model, $config = null) { $model->bindModel( array('hasAndBelongsToMany' => array('Tag')) ); @@ -403,7 +404,7 @@ class Test6Behavior extends ModelBehavior{ * @subpackage cake.tests.cases.libs.model */ class Test7Behavior extends ModelBehavior{ - function setup(&$model, $config = null) { + function setup($model, $config = null) { $model->bindModel( array('hasOne' => array('Attachment')) ); @@ -429,16 +430,6 @@ class BehaviorCollectionTest extends CakeTestCase { 'core.attachment', 'core.tag', 'core.articles_tag' ); -/** - * tearDown method - * - * @access public - * @return void - */ - function endTest() { - ClassRegistry::flush(); - } - /** * testBehaviorBinding method * @@ -937,7 +928,8 @@ class BehaviorCollectionTest extends CakeTestCase { $this->assertIdentical(trim(ob_get_clean()), 'afterDelete success'); $this->assertIdentical($results, true); } - /** + +/** * testBehaviorOnErrorCallback method * * @access public @@ -948,10 +940,11 @@ class BehaviorCollectionTest extends CakeTestCase { $Apple->Behaviors->attach('Test', array('beforeFind' => 'off', 'onError' => 'on')); ob_start(); - $Apple->Behaviors->Test->onError($Apple); + $Apple->Behaviors->Test->onError($Apple, ''); $this->assertIdentical(trim(ob_get_clean()), 'onError trigger success'); } - /** + +/** * testBehaviorValidateCallback method * * @access public @@ -1055,17 +1048,17 @@ class BehaviorCollectionTest extends CakeTestCase { $Apple->Behaviors->attach('Test3'); $Apple->beforeTestResult = array(); - $Apple->Behaviors->trigger($Apple, 'beforeTest'); + $Apple->Behaviors->trigger('beforeTest', array(&$Apple)); $expected = array('testbehavior', 'test2behavior', 'test3behavior'); $this->assertIdentical($Apple->beforeTestResult, $expected); $Apple->beforeTestResult = array(); - $Apple->Behaviors->trigger($Apple, 'beforeTest', array(), array('break' => true, 'breakOn' => 'test2behavior')); + $Apple->Behaviors->trigger('beforeTest', array(&$Apple), array('break' => true, 'breakOn' => 'test2behavior')); $expected = array('testbehavior', 'test2behavior'); $this->assertIdentical($Apple->beforeTestResult, $expected); $Apple->beforeTestResult = array(); - $Apple->Behaviors->trigger($Apple, 'beforeTest', array(), array('break' => true, 'breakOn' => array('test2behavior', 'test3behavior'))); + $Apple->Behaviors->trigger('beforeTest', array($Apple), array('break' => true, 'breakOn' => array('test2behavior', 'test3behavior'))); $expected = array('testbehavior', 'test2behavior'); $this->assertIdentical($Apple->beforeTestResult, $expected); } @@ -1130,6 +1123,6 @@ class BehaviorCollectionTest extends CakeTestCase { $Sample->Behaviors->attach('Test2'); $Sample->Behaviors->detach('Test3'); - $Sample->Behaviors->trigger($Sample, 'beforeTest'); + $Sample->Behaviors->trigger('beforeTest', array(&$Sample)); } } diff --git a/cake/tests/cases/libs/object_collection.test.php b/cake/tests/cases/libs/object_collection.test.php index 91f7080e1..fd51cbecd 100644 --- a/cake/tests/cases/libs/object_collection.test.php +++ b/cake/tests/cases/libs/object_collection.test.php @@ -334,7 +334,7 @@ class ObjectCollectionTest extends CakeTestCase { $this->Objects->TriggerMockSecond->expects($this->once()) ->method('callback') ->with(array('value')) - ->will($this->returnValue('new value')); + ->will($this->returnValue(array('new value'))); $result = $this->Objects->trigger( 'callback',