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

Add shouldExpect() mocking method #302

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

LucasBrunner
Copy link

This PR adds the static shouldExpect method to the AsFake trait.

This exposes the behavior of Mockery's ->expects(). Users will now be able to use ::shouldExpect() to declare that a mocked action should run once and only once.

Fixes #278

@lorisleiva
Copy link
Owner

lorisleiva commented Dec 21, 2024

Thanks for this! I'm just not a great fan of the method name shouldExpect because that is not how the fluent API of expects is supposed to start with.

The current helper shouldRun makes sense because the underlying fluent API starts with shouldReceive.

I think expects would be better but would be more likely to cause a conflict with existing method names.

In any case this introduces a breaking change by adding a function to everyone's action class and I'm not sure this little change warrants a bump to v3.

@Wulfheart what do you think?

@Wulfheart
Copy link
Collaborator

@lorisleiva no opinion on that. However, if you say it is inconsistent that I would be against it in its current form and be open for another naming. It still seems useful on first thought.

@LucasBrunner
Copy link
Author

I agree that the name shouldExpect is not great and changing it is no problem.

It's a great point that since AsFake is a trait adding methods to it could result in namespace collisions with the class using it. Since this means a version bump I would like to take the opportunity to suggest a few further additions to improve the testing experience, but those ideas are more substantial changes than this so I will make dedicated issues for them.

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.

Idea: add shouldExpect() to an action mock
3 participants