Blame | Letzte Änderung | Log anzeigen | RSS feed
.. index::single: Mockery; GotchasGotchas!========Mocking objects in PHP has its limitations and gotchas. Some functionalitycan't be mocked or can't be mocked YET! If you locate such a circumstance,please please (pretty please with sugar on top) create a new issue on GitHubso it can be documented and resolved where possible. Here is a list to note:1. Classes containing public ``__wakeup()`` methods can be mocked but themocked ``__wakeup()`` method will perform no actions and cannot haveexpectations set for it. This is necessary since Mockery must serialize andunserialize objects to avoid some ``__construct()`` insanity and attemptingto mock a ``__wakeup()`` method as normal leads to a``BadMethodCallException`` being thrown.2. Mockery has two scenarios where real classes are replaced: Instance mocksand alias mocks. Both will generate PHP fatal errors if the real class isloaded, usually via a require or include statement. Only use these two mocktypes where autoloading is in place and where classes are not explicitlyloaded on a per-file basis using ``require()``, ``require_once()``, etc.3. Internal PHP classes are not entirely capable of being fully analysed using``Reflection``. For example, ``Reflection`` cannot reveal details ofexpected parameters to the methods of such internal classes. As a result,there will be problems where a method parameter is defined to accept avalue by reference (Mockery cannot detect this condition and will assume apass by value on scalars and arrays). If references as internal classmethod parameters are needed, you should use the``\Mockery\Configuration::setInternalClassMethodParamMap()`` method.Note, however that internal class parameter overriding is not available inPHP 8 since incompatible signatures have been reclassified as fatal errors.4. Creating a mock implementing a certain interface with incorrect case in theinterface name, and then creating a second mock implementing the sameinterface, but this time with the correct case, will have undefined behaviordue to PHP's ``class_exists`` and related functions being case insensitive.Using the ``::class`` keyword in PHP can help you avoid these mistakes.The gotchas noted above are largely down to PHP's architecture and are assumedto be unavoidable. But - if you figure out a solution (or a better one thanwhat may exist), let us know!