5

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

I would like to write unit tests for this function (utilizing 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 I can use the disable_functions setting in php.ini, but I was hoping to find a way to do unit tests without reconfiguring PHP in between runs.

2
  • Does ini_set('disable_functions', '...'); work? Commented Feb 21, 2012 at 15:43
  • @Crozin, No, disable_functions is only available for php.ini. php.net/manual/en/ini.list.php Commented Feb 21, 2012 at 15:44

1 Answer 1

4

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

runkit_function_remove('curl_init');

And, as per the documentation:

Note: By default, only userspace functions may be removed, renamed, or modified. In order to override internal functions, you must enable the runkit.internal_override setting in php.ini.

Sign up to request clarification or add additional context in comments.

1 Comment

That will work, thanks! I don't have runkit currently installed, but I will snag it in a bit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.