From 50c31e797a1b37f32f4eb404646720017a3c34d4 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sat, 17 Oct 2020 04:21:01 +0200 Subject: [PATCH 1/2] Allow shouldIgnoreMissing() to behave in a recursive fashion --- library/Mockery/Mock.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/library/Mockery/Mock.php b/library/Mockery/Mock.php index a5fb75cba..9f335f35b 100644 --- a/library/Mockery/Mock.php +++ b/library/Mockery/Mock.php @@ -52,6 +52,14 @@ class Mock implements MockInterface */ protected $_mockery_ignoreMissing = false; + /** + * Flag to indicate whether we want to set the ignoreMissing flag on + * mocks generated form this calls to this one + * + * @var bool + */ + protected $_mockery_ignoreMissingRecursive = false; + /** * Flag to indicate whether we can defer method calls missing from our * expectations @@ -308,11 +316,13 @@ public function shouldAllowMockingMethod($method) /** * Set mock to ignore unexpected methods and return Undefined class * @param mixed $returnValue the default return value for calls to missing functions on this mock + * @param bool $recursive Speficy if returned mocks should also have shouldIgnoreMissing set * @return Mock */ - public function shouldIgnoreMissing($returnValue = null) + public function shouldIgnoreMissing($returnValue = null, $recursive = false) { $this->_mockery_ignoreMissing = true; + $this->_mockery_ignoreMissingRecursive = $recursive; $this->_mockery_defaultReturnValue = $returnValue; return $this; } @@ -739,10 +749,18 @@ public function mockery_returnValueForMethod($name) return null; case 'object': - return \Mockery::mock(); + $mock = \Mockery::mock(); + if ($this->_mockery_ignoreMissingRecursive) { + $mock->shouldIgnoreMissing($this->_mockery_defaultReturnValue, true); + } + return $mock; default: - return \Mockery::mock($returnType); + $mock = \Mockery::mock($returnType); + if ($this->_mockery_ignoreMissingRecursive) { + $mock->shouldIgnoreMissing($this->_mockery_defaultReturnValue, true); + } + return $mock; } } From ccaaa0ba5ad3e658deef5ae08406bba53be7290f Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sun, 24 Jan 2021 22:19:28 +0100 Subject: [PATCH 2/2] Correct typo --- library/Mockery/Mock.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Mockery/Mock.php b/library/Mockery/Mock.php index 9f335f35b..12daa297a 100644 --- a/library/Mockery/Mock.php +++ b/library/Mockery/Mock.php @@ -316,7 +316,7 @@ public function shouldAllowMockingMethod($method) /** * Set mock to ignore unexpected methods and return Undefined class * @param mixed $returnValue the default return value for calls to missing functions on this mock - * @param bool $recursive Speficy if returned mocks should also have shouldIgnoreMissing set + * @param bool $recursive Specify if returned mocks should also have shouldIgnoreMissing set * @return Mock */ public function shouldIgnoreMissing($returnValue = null, $recursive = false)