diff --git a/library/Mockery/Mock.php b/library/Mockery/Mock.php index a5fb75cba..12daa297a 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 Specify 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; } }