mardi 14 mars 2017

Mock exit() function in PHP

For a library I am writing I would like to be able to mock the exit PHP function.

I tried to use php-mock to provide a namespaced version of exit, something like

namespace MyNamespace;

function exit()
{
    // my mocked version of the function
}

But this creates problems to the parser, which throws the following ParseError: syntax error, unexpected 'exit' (T_EXIT), expecting '('.

Is there any other way to mock a built in function without incurring in parsing problems? Should I try to modify the AST with something like BetterReflection?





Aucun commentaire:

Enregistrer un commentaire