diff --git a/cake/libs/object_collection.php b/cake/libs/object_collection.php index b84ba01f9..831dd555b 100644 --- a/cake/libs/object_collection.php +++ b/cake/libs/object_collection.php @@ -73,7 +73,10 @@ abstract class ObjectCollection { * objects. Defaults to false. * * - `modParams` Allows each object the callback gets called on to modify the parameters to the next object. - * Setting modParams to an integer value will allow you to modify the parameter with that index. Defaults to false. + * Setting modParams to an integer value will allow you to modify the parameter with that index. + * Any non-null value will modify the parameter index indicated. + * Defaults to false. + * * * @param string $callback Method to fire on all the objects. Its assumed all the objects implement * the method you are calling. @@ -115,7 +118,7 @@ abstract class ObjectCollection { (is_array($options['breakOn']) && in_array($result, $options['breakOn'], true))) ) { break; - } elseif ($options['modParams'] !== false) { + } elseif ($options['modParams'] !== false && $result !== null) { $params[$options['modParams']] = $result; } } diff --git a/cake/tests/cases/libs/object_collection.test.php b/cake/tests/cases/libs/object_collection.test.php index c2105558c..91f7080e1 100644 --- a/cake/tests/cases/libs/object_collection.test.php +++ b/cake/tests/cases/libs/object_collection.test.php @@ -315,6 +315,35 @@ class ObjectCollectionTest extends CakeTestCase { ); } +/** + * test that returrning null doesn't modify parameters. + * + * @expectedException CakeException + * @return void + */ + function testTriggerModParamsNullIgnored() { + $this->_makeMockClasses(); + $this->Objects->load('TriggerMockFirst'); + $this->Objects->load('TriggerMockSecond'); + + $this->Objects->TriggerMockFirst->expects($this->once()) + ->method('callback') + ->with(array('value')) + ->will($this->returnValue(null)); + + $this->Objects->TriggerMockSecond->expects($this->once()) + ->method('callback') + ->with(array('value')) + ->will($this->returnValue('new value')); + + $result = $this->Objects->trigger( + 'callback', + array(array('value')), + array('modParams' => 2) + ); + $this->assertEquals('new value', $result); + } + /** * test normalizeObjectArray *