Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check arguments in assertContainerBuilderHasServiceDefinitionWithMehodCall only if they were provided #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions PhpUnit/AbstractContainerBuilderTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions PhpUnit/DefinitionHasMethodCallConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions Tests/PhpUnit/DefinitionHasMethodCallConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
}

Expand Down