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

Conversation

AJenbo
Copy link
Contributor

@AJenbo AJenbo commented Oct 17, 2020

When setting up lazy mocks I often run into issues where the test just breaks at the second link and I end up having to explicitly set expectations for the functions anyway, which requires knowledge about implementation details of things that are not relevant for the given test. This PR aims to solve that by allowing for shouldIgnoreMissing() to behave in a recursive fashion.

code:

class A {
    function now(): DateTime {
        return new DateTime();
    }
}
class Factory {
    function makeA(): A {
        return new A();
    }
}
class Subject {
    $factory;
    function __construct($factory) {
        $this->factory = $factory;
    }
    function testMe() {
        return $this->factory->makeA()->now()->format('c');
    }
}

Before:

$mockedFactory = Mockery::spy(Factory::class):
$aMock->allows('now')->andReturn(Mockery::spy(DateTime::class));
$mockedFactory->allows('makeA')->andReturn($aMock);

$subject = new Subject($mockedFactory);
$subject->testMe();

After:

$mockedFactory = Mockery::mock(Factory::class)->shouldIgnoreMissing(null, true):

$subject = new Subject($mockedFactory);
$subject->testMe();

library/Mockery/Mock.php Outdated Show resolved Hide resolved
@davedevelopment davedevelopment merged commit 59a0cd9 into mockery:master Jan 26, 2021
@davedevelopment
Copy link
Collaborator

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants