Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Make a test fail if a mocked method is not expected to be invoked #9

Closed
sebastianbergmann opened this issue May 25, 2010 · 2 comments
Closed

Comments

@sebastianbergmann
Copy link
Owner

Copied from http://www.phpunit.de/ticket/854

@whatthejeff
Copy link
Collaborator

Making a change like this would break many existing tests. Remember that PHPUnit_Framework_TestCase::getMock() is not only used for creating mocks, but for the entire spectrum of test doubles.

If you read http://www.phpunit.de/manual/current/en/test-doubles.html, this is expected behavior. By default PHPUnit_Framework_TestCase::getMock() returns a stub object that just returns null for all methods. It's really up to you as the programmer to decide how to use this object. To force a programmer to mock every possible invocation of every method in this object would be unreasonable in many situations.

For what it's worth, the invocation recorders like PHPUnit_Framework_TestCase::once() and PHPUnit_Framework_TestCase::exactly() are set up specifically for the type of situation you are describing. If you want to assert that a mocked method is only called once, you should use PHPUnit_Framework_TestCase::once().

@sebastianbergmann
Copy link
Owner Author

Closing.

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants