mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 00:48:25 +00:00
Making modParams ignore null results.
Test added.
This commit is contained in:
parent
a05baaa76e
commit
10c358742b
2 changed files with 34 additions and 2 deletions
|
@ -73,7 +73,10 @@ abstract class ObjectCollection {
|
||||||
* objects. Defaults to false.
|
* objects. Defaults to false.
|
||||||
*
|
*
|
||||||
* - `modParams` Allows each object the callback gets called on to modify the parameters to the next object.
|
* - `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
|
* @param string $callback Method to fire on all the objects. Its assumed all the objects implement
|
||||||
* the method you are calling.
|
* the method you are calling.
|
||||||
|
@ -115,7 +118,7 @@ abstract class ObjectCollection {
|
||||||
(is_array($options['breakOn']) && in_array($result, $options['breakOn'], true)))
|
(is_array($options['breakOn']) && in_array($result, $options['breakOn'], true)))
|
||||||
) {
|
) {
|
||||||
break;
|
break;
|
||||||
} elseif ($options['modParams'] !== false) {
|
} elseif ($options['modParams'] !== false && $result !== null) {
|
||||||
$params[$options['modParams']] = $result;
|
$params[$options['modParams']] = $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
* test normalizeObjectArray
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue