Skip to content
Permalink
Browse files

Making modParams ignore null results.

Test added.
  • Loading branch information...
markstory committed Dec 12, 2010
1 parent a05baaa commit 10c358742b270d6d0b8fb2ac1310f53e633d1eb0
Showing with 34 additions and 2 deletions.
  1. +5 −2 cake/libs/object_collection.php
  2. +29 −0 cake/tests/cases/libs/object_collection.test.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 @@ public function trigger($callback, $params = array(), $options = array()) {
(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;
}
}
@@ -315,6 +315,35 @@ function testTriggerModParamsInvalidIndex() {
);
}
/**
* 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
*

0 comments on commit 10c3587

Please sign in to comment.
You can’t perform that action at this time.