Programmatically disable certain PHP functions for testing

I have a function that makes HTTP requests with cURL, which returns to file_get_contents() if cURL is not available on the system.

I would like to write unit tests for this function (using PHPUnit), where cURL is available for some tests and not available for others.

Is it possible to programmatically disable PHP functions such as curl_init() ?

I know that I can use the disable_functions parameter in php.ini, but I was hoping to find a way to conduct unit tests without reconfiguring PHP between runs.

+4
source share
1 answer

You can use runkit_function_remove to remove any specific function, I think:

 runkit_function_remove('curl_init'); 

And according to the documentation:

Note. By default, only user-space functions can be deleted, renamed, or changed. To override internal functions, you must include the runkit.internal_override parameter in php.ini .

+4
source

Source: https://habr.com/ru/post/1397633/


All Articles