Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stub PHP native methods

In my unit test, i'm looking to stub the behaviour of php's inbuilt file_get_contents() method.

Is there a way to stub native methods in PHP (such as file_get_contents() or print_r()) and the likes?

like image 292
DrPep Avatar asked Dec 21 '25 08:12

DrPep


1 Answers

If by "stub" you mean replace, there is a PHP override_function function; it's part of PECL though. You can also rename them.

like image 158
Ricket Avatar answered Dec 22 '25 22:12

Ricket



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!