From 944ba23b58dbd34695193e95c522a17be70725be Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Fri, 12 Feb 2021 16:09:11 +0100 Subject: [PATCH] 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. --- .../Component/DependencyInjection/Definition.php | 1 - .../DependencyInjection/Tests/DefinitionTest.php | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/Definition.php b/src/Symfony/Component/DependencyInjection/Definition.php index 349b2ed5ab..f07c0c5bcf 100644 --- a/src/Symfony/Component/DependencyInjection/Definition.php +++ b/src/Symfony/Component/DependencyInjection/Definition.php @@ -392,7 +392,6 @@ class Definition foreach ($this->calls as $i => $call) { if ($call[0] === $method) { unset($this->calls[$i]); - break; } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php b/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php index 0a46e5795c..d03233f5d2 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php @@ -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')); + } }