Skip to content

Commit

Permalink
Hotfix: case insensitive methods
Browse files Browse the repository at this point in the history
Fixes #165
  • Loading branch information
michalbundyra committed Sep 4, 2019
1 parent 93d6a38 commit 343219c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/Prophecy/Call/CallCenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function makeCall(ObjectProphecy $prophecy, $methodName, array $arguments
}

// If no method prophecies defined, then it's a dummy, so we'll just return null
if ('__destruct' === $methodName || 0 == count($prophecy->getMethodProphecies())) {
if ('__destruct' === strtolower($methodName) || 0 == count($prophecy->getMethodProphecies())) {
$this->recordedCalls[] = new Call($methodName, $arguments, null, null, $file, $line);

return null;
Expand Down Expand Up @@ -138,9 +138,11 @@ public function makeCall(ObjectProphecy $prophecy, $methodName, array $arguments
*/
public function findCalls($methodName, ArgumentsWildcard $wildcard)
{
$lowerMethodName = strtolower($methodName);

return array_values(
array_filter($this->recordedCalls, function (Call $call) use ($methodName, $wildcard) {
return $methodName === $call->getMethodName()
array_filter($this->recordedCalls, function (Call $call) use ($lowerMethodName, $wildcard) {
return $lowerMethodName === strtolower($call->getMethodName())
&& 0 < $call->getScore($wildcard)
;
})
Expand Down
13 changes: 10 additions & 3 deletions src/Prophecy/Prophecy/ObjectProphecy.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,18 @@ public function getMethodProphecies($methodName = null)
return $this->methodProphecies;
}

if (!isset($this->methodProphecies[$methodName])) {
return array();
$lowerMethodName = strtolower($methodName);

$result = array();
foreach ($this->methodProphecies as $name => $prophecies) {
if (strtolower($name) === $lowerMethodName) {
foreach ($prophecies as $prophecy) {
$result[] = $prophecy;
}
}
}

return $this->methodProphecies[$methodName];
return $result;
}

/**
Expand Down
16 changes: 16 additions & 0 deletions tests/Doubler/Generator/ClassMirrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,4 +498,20 @@ function it_changes_argument_names_if_they_are_varying()

$this->assertEquals('__dot_dot_dot__', $argumentNode->getName());
}

/**
* @test
*/
public function case_insensitive_method_names()
{
$prophecy = $this->prophesize('ArrayObject');
$prophecy->offsetGet(1)->willReturn(1)->shouldBeCalledTimes(1);
$prophecy->offsetget(2)->willReturn(2)->shouldBeCalledTimes(1);
$prophecy->OffsetGet(3)->willReturn(3)->shouldBeCalledTimes(1);

$arrayObject = $prophecy->reveal();
self::assertSame(1, $arrayObject->offsetGet(1));
self::assertSame(2, $arrayObject->offsetGet(2));
self::assertSame(3, $arrayObject->offsetGet(3));
}
}

0 comments on commit 343219c

Please sign in to comment.