| 148 |
lars |
1 |
.. index::
|
|
|
2 |
single: Mocking; Magic Methods
|
|
|
3 |
|
|
|
4 |
PHP Magic Methods
|
|
|
5 |
=================
|
|
|
6 |
|
|
|
7 |
PHP magic methods which are prefixed with a double underscore, e.g.
|
|
|
8 |
``__set()``, pose a particular problem in mocking and unit testing in general.
|
|
|
9 |
It is strongly recommended that unit tests and mock objects do not directly
|
|
|
10 |
refer to magic methods. Instead, refer only to the virtual methods and
|
|
|
11 |
properties these magic methods simulate.
|
|
|
12 |
|
|
|
13 |
Following this piece of advice will ensure we are testing the real API of
|
|
|
14 |
classes and also ensures there is no conflict should Mockery override these
|
|
|
15 |
magic methods, which it will inevitably do in order to support its role in
|
|
|
16 |
intercepting method calls and properties.
|