Skip to content

Commit

Permalink
Revert "check method predictions only once"
Browse files Browse the repository at this point in the history
This reverts commit 1e7f7a4.
  • Loading branch information
everzet committed Sep 4, 2017
1 parent 15ea9ac commit 771f0f2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 44 deletions.
22 changes: 3 additions & 19 deletions spec/Prophecy/Call/CallCenterSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
namespace spec\Prophecy\Call;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Prophecy\Argument\ArgumentsWildcard;
use Prophecy\Call\Call;
use Prophecy\Promise\PromiseInterface;
use Prophecy\Prophecy\MethodProphecy;
use Prophecy\Prophecy\ObjectProphecy;
use Prophecy\Argument\ArgumentsWildcard;

class CallCenterSpec extends ObjectBehavior
{
Expand Down Expand Up @@ -65,11 +63,6 @@ function it_executes_promise_of_method_prophecy_that_matches_signature_passed_to
$method3->getMethodName()->willReturn('getName');
$method3->getArgumentsWildcard()->willReturn($arguments3);
$method3->getPromise()->willReturn($promise);
$method3->addCall(Argument::that(function (Call $call) {
return 'getName' === $call->getMethodName()
&& array('world', 'everything') === $call->getArguments()
&& 42 === $call->getReturnValue();
}))->willReturn($method3);
$arguments3->scoreArguments(array('world', 'everything'))->willReturn(200);

$objectProphecy->getMethodProphecies()->willReturn(array(
Expand All @@ -84,7 +77,8 @@ function it_executes_promise_of_method_prophecy_that_matches_signature_passed_to
$this->makeCall($objectProphecy, 'getName', array('world', 'everything'))->shouldReturn(42);

$calls = $this->findCalls('getName', $arguments3);
$calls->shouldHaveCount(0);
$calls->shouldHaveCount(1);
$calls[0]->getReturnValue()->shouldReturn(42);
}

function it_executes_promise_of_method_prophecy_that_matches_with_highest_score_to_makeCall(
Expand All @@ -106,11 +100,6 @@ function it_executes_promise_of_method_prophecy_that_matches_with_highest_score_
$method2->getMethodName()->willReturn('getName');
$method2->getArgumentsWildcard()->willReturn($arguments2);
$method2->getPromise()->willReturn($promise);
$method2->addCall(Argument::that(function (Call $call) {
return 'getName' === $call->getMethodName()
&& array('world', 'everything') === $call->getArguments()
&& 'second' === $call->getReturnValue();
}))->willReturn($method2);
$arguments2->scoreArguments(array('world', 'everything'))->willReturn(300);

$method3->hasReturnVoid()->willReturn(false);
Expand Down Expand Up @@ -160,11 +149,6 @@ function it_returns_null_if_method_prophecy_that_matches_makeCall_arguments_has_
$method->getMethodName()->willReturn('getName');
$method->getArgumentsWildcard()->willReturn($arguments);
$method->getPromise()->willReturn(null);
$method->addCall(Argument::that(function (Call $call) {
return 'getName' === $call->getMethodName()
&& array('world', 'everything') === $call->getArguments()
&& null === $call->getReturnValue();
}))->willReturn($method);
$arguments->scoreArguments(array('world', 'everything'))->willReturn(100);

$objectProphecy->getMethodProphecies()->willReturn(array($method));
Expand Down
6 changes: 2 additions & 4 deletions src/Prophecy/Call/CallCenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,9 @@ public function makeCall(ObjectProphecy $prophecy, $methodName, array $arguments
);
}

$call = new Call(
$this->recordedCalls[] = new Call(
$methodName, $arguments, $returnValue, $exception, $file, $line
);
$methodProphecy->addCall($call);

if (null !== $exception) {
throw $exception;
Expand All @@ -128,8 +127,7 @@ public function makeCall(ObjectProphecy $prophecy, $methodName, array $arguments
}

/**
* Searches for calls for which no method prophecy was available by method
* name and arguments wildcard.
* Searches for calls by method name & arguments wildcard.
*
* @param string $methodName
* @param ArgumentsWildcard $wildcard
Expand Down
26 changes: 5 additions & 21 deletions src/Prophecy/Prophecy/MethodProphecy.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
namespace Prophecy\Prophecy;

use Prophecy\Argument;
use Prophecy\Call\Call;
use Prophecy\Prophet;
use Prophecy\Promise;
use Prophecy\Prediction;
use Prophecy\Exception\Doubler\MethodNotFoundException;
use Prophecy\Exception\InvalidArgumentException;
use Prophecy\Exception\Prophecy\MethodProphecyException;
use Prophecy\Prediction;
use Prophecy\Promise;
use Prophecy\Prophet;

/**
* Method prophecy.
Expand All @@ -35,7 +34,6 @@ class MethodProphecy
private $checkedPredictions = array();
private $bound = false;
private $voidReturnType = false;
private $calls = array();

/**
* Initializes method prophecy.
Expand Down Expand Up @@ -306,10 +304,10 @@ public function shouldHave($prediction)
$this->willReturn();
}

$calls = array_merge($this->calls, $this->getObjectProphecy()->findProphecyMethodCalls(
$calls = $this->getObjectProphecy()->findProphecyMethodCalls(
$this->getMethodName(),
$this->getArgumentsWildcard()
));
);

try {
$prediction->check($calls, $this->getObjectProphecy(), $this);
Expand Down Expand Up @@ -386,20 +384,6 @@ public function checkPrediction()
$this->shouldHave($this->prediction);
}

/**
* Adds a call made to this prophecy.
*
* @param Call $call
*
* @return $this
*/
public function addCall(Call $call)
{
$this->calls[] = $call;

return $this;
}

/**
* Returns currently registered promise.
*
Expand Down

0 comments on commit 771f0f2

Please sign in to comment.