Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow shouldIgnoreMissing() to behave in a recursive fashion #1097

Merged
merged 2 commits into from Jan 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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