Skip to content

Commit

Permalink
Merge pull request #1097 from AJenbo/master
Browse files Browse the repository at this point in the history
Allow shouldIgnoreMissing() to behave in a recursive fashion
  • Loading branch information
davedevelopment committed Jan 26, 2021
2 parents 14a510d + ccaaa0b commit 59a0cd9
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions library/Mockery/Mock.php
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 59a0cd9

Please sign in to comment.