Skip to content

Commit 6064c1c

Browse files
ruudkfabpot
authored andcommitted
Definition::removeMethodCall should remove all matching calls
It would only remove the first match, leaving the other method call(s) there to exist. This leads to unexpected situations.
1 parent 22b41dc commit 6064c1c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Definition.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,6 @@ public function removeMethodCall($method)
392392
foreach ($this->calls as $i => $call) {
393393
if ($call[0] === $method) {
394394
unset($this->calls[$i]);
395-
break;
396395
}
397396
}
398397

Tests/DefinitionTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,4 +425,20 @@ public function testAddError()
425425
$def->addError('Second error');
426426
$this->assertSame(['First error', 'Second error'], $def->getErrors());
427427
}
428+
429+
public function testMultipleMethodCalls()
430+
{
431+
$def = new Definition('stdClass');
432+
433+
$def->addMethodCall('configure', ['arg1']);
434+
$this->assertTrue($def->hasMethodCall('configure'));
435+
$this->assertCount(1, $def->getMethodCalls());
436+
437+
$def->addMethodCall('configure', ['arg2']);
438+
$this->assertTrue($def->hasMethodCall('configure'));
439+
$this->assertCount(2, $def->getMethodCalls());
440+
441+
$def->removeMethodCall('configure');
442+
$this->assertFalse($def->hasMethodCall('configure'));
443+
}
428444
}

0 commit comments

Comments
 (0)