Skip to content

Commit

Permalink
Fixing issue where mockObject expectations were not counted hiding fa…
Browse files Browse the repository at this point in the history
…ils. Fixing all objects not actually being iterated.
  • Loading branch information
markstory committed Sep 15, 2010
1 parent 5d697b9 commit 7a14d3a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cake/libs/object_collection.php
Expand Up @@ -79,7 +79,7 @@ public function trigger($callback, $params = array(), $options = array()) {
if ($options['triggerDisabled'] === true) {
$list = array_keys($this->_loaded);
}
foreach ($this->_enabled as $name) {
foreach ($list as $name) {
$result = call_user_func_array(array(&$this->_loaded[$name], $callback), $params);
if ($options['collectReturn'] === true) {
$collected[] = $result;
Expand Down
27 changes: 21 additions & 6 deletions cake/tests/cases/libs/controller/component_collection.test.php
Expand Up @@ -18,6 +18,7 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

App::import('Component', array('Cookie', 'Security'));
App::import('Core', 'ComponentCollection');

class ComponentCollectionTest extends CakeTestCase {
Expand Down Expand Up @@ -145,6 +146,9 @@ function testTrigger() {
->with(null);
$this->Components->TriggerMockSecurity->expects($this->once())->method('startup')
->with(null);

$this->mockObjects[] = $this->Components->TriggerMockCookie;
$this->mockObjects[] = $this->Components->TriggerMockSecurity;

$this->assertTrue($this->Components->trigger('startup', array(&$controller)));
}
Expand All @@ -154,17 +158,20 @@ function testTrigger() {
*
* @return void
*/
function testTriggerOnDisabledObjects() {
function testTriggerWithTriggerDisabledObjects() {
$controller = 'Not a controller';

$this->_makeMockClasses();
$this->Components->load('TriggerMockCookie', array(), false);
$this->Components->load('TriggerMockSecurity');

$this->Components->TriggerMockCookie->expects($this->once())->method('initalize')
$this->Components->TriggerMockCookie->expects($this->once())->method('initialize')
->with($controller);
$this->Components->TriggerMockSecurity->expects($this->once())->method('initalize')
$this->Components->TriggerMockSecurity->expects($this->once())->method('initialize')
->with($controller);

$this->mockObjects[] = $this->Components->TriggerMockCookie;
$this->mockObjects[] = $this->Components->TriggerMockSecurity;

$result = $this->Components->trigger('initialize', array(&$controller), array('triggerDisabled' => true));
$this->assertTrue($result);
Expand All @@ -182,9 +189,11 @@ function testTriggerWithDisabledComponents() {
$this->Components->load('TriggerMockSecurity');

$this->Components->TriggerMockCookie->expects($this->once())->method('startup')
->with(null);
$this->Components->TriggerMockSecurity->expects($this->never())->method('startup')
->with(null);
->with($controller);
$this->Components->TriggerMockSecurity->expects($this->never())->method('startup');

$this->mockObjects[] = $this->Components->TriggerMockCookie;
$this->mockObjects[] = $this->Components->TriggerMockSecurity;

$this->Components->disable('TriggerMockSecurity');

Expand All @@ -206,6 +215,9 @@ function testTriggerWithCollectReturn() {
->will($this->returnValue(array('one', 'two')));
$this->Components->TriggerMockSecurity->expects($this->once())->method('startup')
->will($this->returnValue(array('three', 'four')));

$this->mockObjects[] = $this->Components->TriggerMockCookie;
$this->mockObjects[] = $this->Components->TriggerMockSecurity;

$result = $this->Components->trigger('startup', array(&$controller), array('collectReturn' => true));
$expected = array(
Expand All @@ -229,6 +241,9 @@ function testTriggerWithBreak() {
$this->Components->TriggerMockCookie->expects($this->once())->method('startup')
->will($this->returnValue(false));
$this->Components->TriggerMockSecurity->expects($this->never())->method('startup');

$this->mockObjects[] = $this->Components->TriggerMockCookie;
$this->mockObjects[] = $this->Components->TriggerMockSecurity;

$result = $this->Components->trigger(
'startup',
Expand Down

0 comments on commit 7a14d3a

Please sign in to comment.