Blame | Letzte Änderung | Log anzeigen | RSS feed
.. index::single: Cookbook; Big Parent ClassBig Parent Class================In some application code, especially older legacy code, we can come across someclasses that extend a "big parent class" - a parent class that knows and doestoo much:.. code-block:: phpclass BigParentClass{public function doesEverything(){// sets up database connections// writes to log files}}class ChildClass extends BigParentClass{public function doesOneThing(){// but calls on BigParentClass methods$result = $this->doesEverything();// does something with $resultreturn $result;}}We want to test our ``ChildClass`` and its ``doesOneThing`` method, but theproblem is that it calls on ``BigParentClass::doesEverything()``. One way tohandle this would be to mock out **all** of the dependencies ``BigParentClass``has and needs, and then finally actually test our ``doesOneThing`` method. It'san awful lot of work to do that.What we can do, is to do something... unconventional. We can create a runtimepartial test double of the ``ChildClass`` itself and mock only the parent's``doesEverything()`` method:.. code-block:: php$childClass = \Mockery::mock('ChildClass')->makePartial();$childClass->shouldReceive('doesEverything')->andReturn('some result from parent');$childClass->doesOneThing(); // string("some result from parent");With this approach we mock out only the ``doesEverything()`` method, and all theunmocked methods are called on the actual ``ChildClass`` instance.