sebastianbergmann/phpunit-mock-objects — pull request #77 by mikey179 (2012-01-22 01:40:13+00:00)
Title: Support for mocking functions

Hi,

today I had the idea to mock functions. This pull request implements the idea, and is meant as a base for discussion of whether there is any interest in integrating it into phpunit-mock-objects.

With the help of function mocks I was able to increase code coverage of a class from below 30% to 100% which has not been possible before as the class uses socket functionality. See [the class to test](https://github.com/mikey179/stubbles-core/blob/functionmocks/src/main/php/net/stubbles/peer/Socket.php), and [test cases starting at line 200](https://github.com/mikey179/stubbles-core/blob/functionmocks/src/test/php/net/stubbles/peer/SocketTestCase.php) using this functionality.

The way it works is to create a new function with the same signature, but inside the same namespace of the class we want to test. Now if the class uses relative function calls this will lead the class to call the mock functions instead of the original ones. The original idea is described in [Mocking Global Php 5.3 Functions Using Namespaces](http://marcelog.github.com/articles/php_mock_global_functions_for_unit_tests_with_phpunit.html). Therefore this only works with PHP 5.3 and if the class to test is inside a namespace.

Regards,
Frank