Skip to content

Commit e490424

Browse files
committed
Addendum to fix for #69, according to requested changes.
1 parent cba6995 commit e490424

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

PhpUnit/DefinitionHasMethodCallConstraint.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class DefinitionHasMethodCallConstraint extends Constraint
1515
public function __construct($methodName, array $arguments = array(), $index = null)
1616
{
1717
if ($index !== null && !is_int($index)) {
18-
throw new \RuntimeException(sprintf('Expected value of integer type for method call index, "%s" given.', is_object($index) ? get_class($index) : gettype($index)));
18+
throw new \InvalidArgumentException(sprintf('Expected value of integer type for method call index, "%s" given.', is_object($index) ? get_class($index) : gettype($index)));
1919
}
2020

2121
parent::__construct();
@@ -33,14 +33,16 @@ public function evaluate($other, $description = '', $returnResult = false)
3333
);
3434
}
3535

36-
for ($i = 0; $i < $iMax = count($methodCalls = $other->getMethodCalls()); $i++) {
37-
list($method, $arguments) = $methodCalls[$i];
36+
$methodCalls = $other->getMethodCalls();
37+
38+
for ($currentIndex = 0; $currentIndex < $iMax = count($methodCalls); $currentIndex++) {
39+
list($method, $arguments) = $methodCalls[$currentIndex];
3840

3941
if ($method !== $this->methodName) {
4042
continue;
4143
}
4244

43-
if (null !== $this->index && $i !== $this->index) {
45+
if (null !== $this->index && $currentIndex !== $this->index) {
4446
continue;
4547
}
4648

@@ -66,8 +68,16 @@ public function evaluate($other, $description = '', $returnResult = false)
6668

6769
public function toString()
6870
{
71+
if (null !== $this->index) {
72+
return sprintf(
73+
'has a method call to "%s" with the given arguments on invocation order index with value of %s.',
74+
$this->methodName,
75+
$this->index
76+
);
77+
}
78+
6979
return sprintf(
70-
'has a method call to "%s" with the given arguments on any or explicitly stated invocation order index.',
80+
'has a method call to "%s" with the given arguments.',
7181
$this->methodName
7282
);
7383
}

Tests/PhpUnit/DefinitionHasMethodCallConstraintTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ public function it_has_a_string_representation()
5555
$method = 'methodName';
5656
$constraint = new DefinitionHasMethodCallConstraint($method, array());
5757

58-
$this->assertSame('has a method call to "'.$method.'" with the given arguments on any or explicitly stated invocation order index.', $constraint->toString());
58+
$this->assertSame('has a method call to "'.$method.'" with the given arguments.', $constraint->toString());
59+
60+
$invocationIndex = 2;
61+
$constraint = new DefinitionHasMethodCallConstraint($method, array(), $invocationIndex);
62+
63+
$this->assertSame('has a method call to "'.$method.'" with the given arguments on invocation order index with value of '.$invocationIndex.'.', $constraint->toString());
5964
}
6065
}

0 commit comments

Comments
 (0)