instance_mocking.rst 805 B

12345678910111213141516171819202122
  1. .. index::
  2. single: Mocking; Instance
  3. Instance Mocking
  4. ================
  5. Instance mocking means that a statement like:
  6. .. code-block:: php
  7. $obj = new \MyNamespace\Foo;
  8. ...will actually generate a mock object. This is done by replacing the real
  9. class with an instance mock (similar to an alias mock), as with mocking public
  10. methods. The alias will import its expectations from the original mock of
  11. that type (note that the original is never verified and should be ignored
  12. after its expectations are setup). This lets you intercept instantiation where
  13. you can't simply inject a replacement object.
  14. As before, this does not prevent a require statement from including the real
  15. class and triggering a fatal PHP error. It's intended for use where
  16. autoloading is the primary class loading mechanism.