I am working on a refactoring tool, which produces php files. Those generated files can contain variables, functions and classes too.
I would like to write unit tests, to test if those files are working as expected, but I have no idea how should I do it.
If I require an incorrect file with if (! @require('my_new_file.php') ) {, I still get a parse error, which I am not able to catch.
I call require inside a function, but the definitions in the required files are still available outside of my function. How could I avoid that? Is it possible to require a file in a scope, so it will not pollute the global namespace?
Even if I call eval(file_get_contents('my_new_file.php')) inside a function, the functions defined in my_new_file.php are available globally.
from How is it possible to test generated php files?
No comments:
Post a Comment