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.
This commit is contained in:
Ruud Kamphuis 2021-02-12 16:09:11 +01:00 committed by Fabien Potencier
parent 4a32fd0446
commit 944ba23b58
2 changed files with 16 additions and 1 deletions

View File

@ -392,7 +392,6 @@ class Definition
foreach ($this->calls as $i => $call) {
if ($call[0] === $method) {
unset($this->calls[$i]);
break;
}
}

View File

@ -425,4 +425,20 @@ class DefinitionTest extends TestCase
$def->addError('Second error');
$this->assertSame(['First error', 'Second error'], $def->getErrors());
}
public function testMultipleMethodCalls()
{
$def = new Definition('stdClass');
$def->addMethodCall('configure', ['arg1']);
$this->assertTrue($def->hasMethodCall('configure'));
$this->assertCount(1, $def->getMethodCalls());
$def->addMethodCall('configure', ['arg2']);
$this->assertTrue($def->hasMethodCall('configure'));
$this->assertCount(2, $def->getMethodCalls());
$def->removeMethodCall('configure');
$this->assertFalse($def->hasMethodCall('configure'));
}
}