From 8a384634e4d93b0a333ec29fcd56def4148bee4d Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 17 Mar 2021 15:50:37 +0100 Subject: [PATCH 1/6] Ignore PHPUnit cache --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 88ee1c14c..76976e36b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /composer.lock /vendor /phpunit.xml +*.cache From 3780d3f25a7173329a4266c7ff2bf0842c904396 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 17 Mar 2021 16:01:33 +0100 Subject: [PATCH 2/6] Revert #441 --- spec/Prophecy/Call/CallCenterSpec.php | 39 ++++++-------- spec/Prophecy/Prophecy/MethodProphecySpec.php | 3 +- spec/Prophecy/Prophecy/ObjectProphecySpec.php | 11 ---- src/Prophecy/Call/CallCenter.php | 54 +++---------------- src/Prophecy/Prophecy/ObjectProphecy.php | 3 -- 5 files changed, 25 insertions(+), 85 deletions(-) diff --git a/spec/Prophecy/Call/CallCenterSpec.php b/spec/Prophecy/Call/CallCenterSpec.php index e0cdab646..83d61f1ec 100644 --- a/spec/Prophecy/Call/CallCenterSpec.php +++ b/spec/Prophecy/Call/CallCenterSpec.php @@ -3,7 +3,6 @@ namespace spec\Prophecy\Call; use PhpSpec\ObjectBehavior; -use Prophecy\Exception\Call\UnexpectedCallException; use Prophecy\Promise\PromiseInterface; use Prophecy\Prophecy\MethodProphecy; use Prophecy\Prophecy\ObjectProphecy; @@ -124,6 +123,23 @@ function it_executes_promise_of_method_prophecy_that_matches_with_highest_score_ ->shouldReturn('second'); } + function it_throws_exception_if_call_does_not_match_any_of_defined_method_prophecies( + $objectProphecy, + MethodProphecy $method, + ArgumentsWildcard $arguments + ) { + $method->getMethodName()->willReturn('getName'); + $method->getArgumentsWildcard()->willReturn($arguments); + $arguments->scoreArguments(array('world', 'everything'))->willReturn(false); + $arguments->__toString()->willReturn('arg1, arg2'); + + $objectProphecy->getMethodProphecies()->willReturn(array('method1' => array($method))); + $objectProphecy->getMethodProphecies('getName')->willReturn(array($method)); + + $this->shouldThrow('Prophecy\Exception\Call\UnexpectedCallException') + ->duringMakeCall($objectProphecy, 'getName', array('world', 'everything')); + } + function it_returns_null_if_method_prophecy_that_matches_makeCall_arguments_has_no_promise( $objectProphecy, MethodProphecy $method, @@ -161,25 +177,4 @@ function it_finds_recorded_calls_by_a_method_name_and_arguments_wildcard( $calls[0]->getMethodName()->shouldReturn('getName'); $calls[0]->getArguments()->shouldReturn(array('everything')); } - - function it_records_the_error_when_stub_has_got_unexpected_method_calls( - $objectProphecy, - MethodProphecy $method, - ArgumentsWildcard $arguments - ) { - $method->getMethodName()->willReturn('getName'); - $method->getArgumentsWildcard()->willReturn($arguments); - - $arguments->getTokens()->willReturn(array()); - - $objectProphecy->getMethodProphecies()->willReturn(array('getName' => array($method))); - $objectProphecy->getMethodProphecies('getName')->willReturn(array($method)); - $objectProphecy->getMethodProphecies('method1')->willReturn(array()); - $objectProphecy->reveal()->willReturn(new \stdClass()); - - $this->shouldNotThrow('Prophecy\Exception\Call\UnexpectedCallException') - ->duringMakeCall($objectProphecy, 'method1', array()); - - $this->shouldThrow('Prophecy\Exception\Call\UnexpectedCallException')->duringCheckUnexpectedCalls(); - } } diff --git a/spec/Prophecy/Prophecy/MethodProphecySpec.php b/spec/Prophecy/Prophecy/MethodProphecySpec.php index f2fcf1366..899e042f8 100644 --- a/spec/Prophecy/Prophecy/MethodProphecySpec.php +++ b/spec/Prophecy/Prophecy/MethodProphecySpec.php @@ -353,7 +353,7 @@ function it_records_even_failed_checked_predictions( $this->withArguments($arguments); try { - $this->callOnWrappedObject('shouldHave', array($prediction)); + $this->callOnWrappedObject('shouldHave', array($prediction)); } catch (\Exception $e) {} $this->getCheckedPredictions()->shouldReturn(array($prediction)); @@ -365,7 +365,6 @@ function it_checks_prediction_via_shouldHave_method_call_with_callback( Call $call1, Call $call2 ) { - $objectProphecy->addMethodProphecy($this)->willReturn(null); $callback = function ($calls, $object, $method) { throw new RuntimeException; }; diff --git a/spec/Prophecy/Prophecy/ObjectProphecySpec.php b/spec/Prophecy/Prophecy/ObjectProphecySpec.php index 782c97b8d..062ebd574 100644 --- a/spec/Prophecy/Prophecy/ObjectProphecySpec.php +++ b/spec/Prophecy/Prophecy/ObjectProphecySpec.php @@ -287,17 +287,6 @@ function it_returns_new_MethodProphecy_for_all_callback_signatures( $methodProphecy2->shouldNotBe($methodProphecy1); } - - function it_throws_UnexpectedCallException_during_checkPredictions_if_unexpected_method_was_called( - $lazyDouble, CallCenter $callCenter - ) { - $this->beConstructedWith($lazyDouble, $callCenter); - - $callCenter->checkUnexpectedCalls()->willThrow('Prophecy\Exception\Call\UnexpectedCallException'); - - $this->shouldThrow('Prophecy\Exception\Call\UnexpectedCallException') - ->duringCheckProphecyMethodsPredictions(); - } } class ObjectProphecySpecFixtureA diff --git a/src/Prophecy/Call/CallCenter.php b/src/Prophecy/Call/CallCenter.php index 00c526d7e..807dc108d 100644 --- a/src/Prophecy/Call/CallCenter.php +++ b/src/Prophecy/Call/CallCenter.php @@ -16,7 +16,6 @@ use Prophecy\Argument\ArgumentsWildcard; use Prophecy\Util\StringUtil; use Prophecy\Exception\Call\UnexpectedCallException; -use SplObjectStorage; /** * Calls receiver & manager. @@ -32,11 +31,6 @@ class CallCenter */ private $recordedCalls = array(); - /** - * @var SplObjectStorage - */ - private $unexpectedCalls; - /** * Initializes call center. * @@ -45,7 +39,6 @@ class CallCenter public function __construct(StringUtil $util = null) { $this->util = $util ?: new StringUtil; - $this->unexpectedCalls = new SplObjectStorage(); } /** @@ -79,14 +72,16 @@ public function makeCall(ObjectProphecy $prophecy, $methodName, array $arguments } // There are method prophecies, so it's a fake/stub. Searching prophecy for this call - $matches = $this->findMethodProphecies($prophecy, $methodName, $arguments); + $matches = array(); + foreach ($prophecy->getMethodProphecies($methodName) as $methodProphecy) { + if (0 < $score = $methodProphecy->getArgumentsWildcard()->scoreArguments($arguments)) { + $matches[] = array($score, $methodProphecy); + } + } // If fake/stub doesn't have method prophecy for this call - throw exception if (!count($matches)) { - $this->unexpectedCalls->attach(new Call($methodName, $arguments, null, null, $file, $line), $prophecy); - $this->recordedCalls[] = new Call($methodName, $arguments, null, null, $file, $line); - - return null; + throw $this->createUnexpectedCallException($prophecy, $methodName, $arguments); } // Sort matches by their score value @@ -145,22 +140,6 @@ public function findCalls($methodName, ArgumentsWildcard $wildcard) ); } - /** - * @throws UnexpectedCallException - */ - public function checkUnexpectedCalls() - { - /** @var Call $call */ - foreach ($this->unexpectedCalls as $call) { - $prophecy = $this->unexpectedCalls[$call]; - - // If fake/stub doesn't have method prophecy for this call - throw exception - if (!count($this->findMethodProphecies($prophecy, $call->getMethodName(), $call->getArguments()))) { - throw $this->createUnexpectedCallException($prophecy, $call->getMethodName(), $call->getArguments()); - } - } - } - private function createUnexpectedCallException(ObjectProphecy $prophecy, $methodName, array $arguments) { @@ -218,23 +197,4 @@ function () use ($indentationLength) { $arguments ); } - - /** - * @param ObjectProphecy $prophecy - * @param string $methodName - * @param array $arguments - * - * @return array - */ - private function findMethodProphecies(ObjectProphecy $prophecy, $methodName, array $arguments) - { - $matches = array(); - foreach ($prophecy->getMethodProphecies($methodName) as $methodProphecy) { - if (0 < $score = $methodProphecy->getArgumentsWildcard()->scoreArguments($arguments)) { - $matches[] = array($score, $methodProphecy); - } - } - - return $matches; - } } diff --git a/src/Prophecy/Prophecy/ObjectProphecy.php b/src/Prophecy/Prophecy/ObjectProphecy.php index 11b87cf1b..ecc22bf55 100644 --- a/src/Prophecy/Prophecy/ObjectProphecy.php +++ b/src/Prophecy/Prophecy/ObjectProphecy.php @@ -210,15 +210,12 @@ public function findProphecyMethodCalls($methodName, ArgumentsWildcard $wildcard * Checks that registered method predictions do not fail. * * @throws \Prophecy\Exception\Prediction\AggregateException If any of registered predictions fail - * @throws \Prophecy\Exception\Call\UnexpectedCallException */ public function checkProphecyMethodsPredictions() { $exception = new AggregateException(sprintf("%s:\n", get_class($this->reveal()))); $exception->setObjectProphecy($this); - $this->callCenter->checkUnexpectedCalls(); - foreach ($this->methodProphecies as $prophecies) { foreach ($prophecies as $prophecy) { try { From 96b3de984ab17b1398940bdede11f4cdb878eef2 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 17 Mar 2021 16:01:53 +0100 Subject: [PATCH 3/6] Declare master as 2.x --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index de6b7c2b9..ab034e7dd 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "extra": { "branch-alias": { - "dev-master": "1.11.x-dev" + "dev-master": "2.0.x-dev" } } } From c044398d8c7243e89ce815e39dd37d704b9b6123 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 17 Mar 2021 16:15:46 +0100 Subject: [PATCH 4/6] Revert indentation change --- spec/Prophecy/Prophecy/MethodProphecySpec.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/Prophecy/Prophecy/MethodProphecySpec.php b/spec/Prophecy/Prophecy/MethodProphecySpec.php index 899e042f8..0156bb3f1 100644 --- a/spec/Prophecy/Prophecy/MethodProphecySpec.php +++ b/spec/Prophecy/Prophecy/MethodProphecySpec.php @@ -353,7 +353,7 @@ function it_records_even_failed_checked_predictions( $this->withArguments($arguments); try { - $this->callOnWrappedObject('shouldHave', array($prediction)); + $this->callOnWrappedObject('shouldHave', array($prediction)); } catch (\Exception $e) {} $this->getCheckedPredictions()->shouldReturn(array($prediction)); From 614160ed8daaad7bd0d1a7a977e7e7b3d9af5b1c Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 17 Mar 2021 16:20:13 +0100 Subject: [PATCH 5/6] Revert declaration of 2.x --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ab034e7dd..de6b7c2b9 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "1.11.x-dev" } } } From 1dabaf862e455cddf8985d1fa5749cb71600e3e2 Mon Sep 17 00:00:00 2001 From: Dzianis Hrynko Date: Fri, 15 Oct 2021 17:31:23 +0200 Subject: [PATCH 6/6] #527 Fix. Add static type --- src/Prophecy/Doubler/Generator/Node/TypeNodeAbstract.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Prophecy/Doubler/Generator/Node/TypeNodeAbstract.php b/src/Prophecy/Doubler/Generator/Node/TypeNodeAbstract.php index e6b10dd62..97fc54978 100644 --- a/src/Prophecy/Doubler/Generator/Node/TypeNodeAbstract.php +++ b/src/Prophecy/Doubler/Generator/Node/TypeNodeAbstract.php @@ -56,6 +56,7 @@ protected function getRealType(string $type): string // built in types case 'self': + case 'static': case 'array': case 'callable': case 'bool':