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 createPartialMock() to not mock any methods. #2270

Closed
wants to merge 1 commit into from

Conversation

corphi
Copy link
Contributor

@corphi corphi commented Aug 17, 2016

Right now, createPartialMock($class, []) does the same thing as createMock($class); it mocks all methods. This is somewhat counter-intuitive and caused by the API of the mock builder, where calling setMethods(null) has the expected effect.

As a first idea, I allowed passing null as a parameter value for consistency. But there is no need for createPartialMock to return a complete one - createMock already does that. [] also expresses the meaning better than null (“exactly these methods”). As a bonus, the method signature doesn’t change.

Test included.

@sebastianbergmann
Copy link
Owner

Why would you want to not stub/mock any method?

@sebastianbergmann sebastianbergmann added the type/enhancement A new idea that should be implemented label Aug 17, 2016
@corphi
Copy link
Contributor Author

corphi commented Aug 17, 2016

I use such mock objects in tests for setters and getters; mostly it’s about avoiding a call to the constructor. The code to create such objects is the same as in createPartialMock() – except for the methods mocked. These tests could pass a random untested method name instead (in fact, that’s the way the tests work right now), but that’s a silly workaround and will likely break.

@sebastianbergmann
Copy link
Owner

Merged manually, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement A new idea that should be implemented
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants