diff --git a/PhpUnit/AbstractContainerBuilderTestCase.php b/PhpUnit/AbstractContainerBuilderTestCase.php index e1cc475..5714b43 100644 --- a/PhpUnit/AbstractContainerBuilderTestCase.php +++ b/PhpUnit/AbstractContainerBuilderTestCase.php @@ -173,13 +173,13 @@ protected function assertContainerBuilderHasServiceDefinitionWithArgument( * * @param string $serviceId * @param string $method - * @param array $arguments + * @param array|null $arguments * @param int|null $index */ protected function assertContainerBuilderHasServiceDefinitionWithMethodCall( $serviceId, $method, - array $arguments = array(), + array $arguments = null, $index = null ) { $definition = $this->container->findDefinition($serviceId); diff --git a/PhpUnit/DefinitionHasMethodCallConstraint.php b/PhpUnit/DefinitionHasMethodCallConstraint.php index bd213f8..69ec119 100644 --- a/PhpUnit/DefinitionHasMethodCallConstraint.php +++ b/PhpUnit/DefinitionHasMethodCallConstraint.php @@ -12,7 +12,7 @@ class DefinitionHasMethodCallConstraint extends Constraint private $arguments; private $index; - public function __construct($methodName, array $arguments = array(), $index = null) + public function __construct($methodName, array $arguments = null, $index = null) { if ($index !== null && !is_int($index)) { throw new \InvalidArgumentException(sprintf('Expected value of integer type for method call index, "%s" given.', is_object($index) ? get_class($index) : gettype($index))); @@ -46,9 +46,11 @@ public function evaluate($other, $description = '', $returnResult = false) continue; } - if ($this->equalArguments($this->arguments, $arguments)) { - return true; + if (null !== $this->arguments && !$this->equalArguments($this->arguments, $arguments)) { + continue; } + + return true; } if (!$returnResult) { diff --git a/Tests/PhpUnit/DefinitionHasMethodCallConstraintTest.php b/Tests/PhpUnit/DefinitionHasMethodCallConstraintTest.php index caa4093..000f8a1 100644 --- a/Tests/PhpUnit/DefinitionHasMethodCallConstraintTest.php +++ b/Tests/PhpUnit/DefinitionHasMethodCallConstraintTest.php @@ -44,6 +44,8 @@ public function definitionProvider() array($definitionWithTwoMethodCalls, 'methodCallOne', $otherArguments, null, false), // the definition has a call to this method, arguments match with the first call, but invocation index is wrong array($definitionWithTwoMethodCalls, 'methodCallOne', $argumentsOfFirstCall, 1, false), + // the definition has a call to this method, has arguments, but they are not checked + array($definitionWithTwoMethodCalls, 'methodCallOne', null, null, true), ); }