PHP - Alternatives to runkit for intercepting method calls
Posted
by
Radu
on Stack Overflow
See other posts from Stack Overflow
or by Radu
Published on 2011-05-27T15:26:36Z
Indexed on
2012/09/08
21:38 UTC
Read the original article
Hit count: 825
I have some very test-unfriendly code (to say the least) that I need to test. Refactoring unfortunately is not an option. I have to test the code as it is, without the possibility of changing it.
To do that, I was thinking of intercepting function calls and dynamically change what they do so I can run my tests, as I need some functions and methods to return known values, and I need others that make requests, connect to the database, etc, to stop doing that and return what I need them to return. Is there any way to do this without runkit_method_redefine()
, which is preferably not "EXPERIMENTAL" and still maintained? Maybe an alternative to runkit? Maybe a better way?
Edit: will use PHPUnit's test doubles and PHP 5.3.2's features for making private methods accessible, if I need that functionality.
© Stack Overflow or respective owner