Mock

A mock replaces a code dependency with an object, to make testing easier. Mocks are used when the dependency is difficult to set in a reproducible state : for example, in a rare state, or after a long set up.

Mocks turns the dependency into another piece of code, with total control over its behavior.

On the other hand, mocks have to be coded to replace the dependency, and emulates its behavior as closely as possible : any change to the dependency behavior has to be back-ported.

Mock objects are also called test double.

Documentation

See also Test doubles, Mocking, Avoid mocking repositories by using in-memory implementations, Testing without mocking frameworks

Related : Test Data Provider

Related packages : mockery/mockery, phpspec/prophecy