diff --git a/rules-tests/Rector/ClassMethod/ConsecutiveMockExpectationRector/Fixture/twice_called_will_return.php.inc b/rules-tests/Rector/ClassMethod/ConsecutiveMockExpectationRector/Fixture/twice_called_will_return.php.inc new file mode 100644 index 00000000..2a4f8188 --- /dev/null +++ b/rules-tests/Rector/ClassMethod/ConsecutiveMockExpectationRector/Fixture/twice_called_will_return.php.inc @@ -0,0 +1,34 @@ +set('first_key')->willReturn(100); + $mockedType->set('second_key')->willReturn(200); + } +} + +?> +----- +expects($this->exactly(2))->method('set')->willReturnMap([['first_key', 100], ['second_key', 200]]); + } +} + +?> diff --git a/src/NodeFactory/WillReturnMapMethodCallFactory.php b/src/NodeFactory/WillReturnMapMethodCallFactory.php index 2f3bedc6..64b084a6 100644 --- a/src/NodeFactory/WillReturnMapMethodCallFactory.php +++ b/src/NodeFactory/WillReturnMapMethodCallFactory.php @@ -93,6 +93,13 @@ private function createConsecutiveItemsArray( PhpSpecMethodName::SHOULD_RETURN ); + if (empty($returnArgs)) { + $returnArgs = $this->resolveInputArgs( + $consecutiveMethodCall->getMethodCall(), + PhpSpecMethodName::WILL_RETURN + ); + } + $arrayItems = $this->createArrayItemsFromArgs([...$inputArgs, ...$returnArgs]); $singleCallArray = new Array_($arrayItems);