On 16.08.2017 at 22:02, Ryan Jentzsch wrote:
> I am aware of Advanced PHP debugger but what I need this type of
> functionality for is mocking and testing.
>
> As an example I want to use PHPUnit mocking feature to create a mock of a
> class. However in the constructor of this class is the following line to
> get the expected JSON string:
>
> $result = file_get_contents('php://input');
>
> I can not override the file_get_contents() function. The work around is to
> monkey patch the class as a mock and override the constructor (copying ALL
> logic from the constructor to the mock allowing for $result to be taken
> from the constructor's argument list).
>
> This is awkward and in my use case the constructor also makes calls to
> static methods in other objects which the latest version of PHPUnit does
> not allow you to mock static methods.
>
> ADP is not acceptable to override functions in that it requires a binary to
> be installed and php.ini to be configured as well as no support for this in
> Windows.
>
> Is there an RFC that I didn't find that allows for easily overriding
> built-in functions? For example:
>
> @function file_get_contents($string)
> {
> return 'mock string';
> }
>
> My C skills are quite rusty and understanding the Zend engine is a daunting
> task or I'd create an RFC myself. The devil is in the details. The real
> question I am asking is HOW DIFFICULT would something like this be to code
> and include in the PHP core?
There are already runkit and uopz which allow to override existing
functions:
* <https://pecl.php.net/package/runkit>
* <https://pecl.php.net/package/uopz>
--
Christoph M. Becker
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php