[英]Mock exit() function in PHP
For a library I am writing I would like to be able to mock the exit
PHP function. 对于我正在编写的库,我希望能够模拟exit
PHP函数。
I tried to use php-mock to provide a namespaced version of exit
, something like 我试图使用php-mock来提供exit
的命名空间版本,例如
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 '('
. 但这syntax error, unexpected 'exit' (T_EXIT), expecting '('
解析器带来问题,解析器抛出以下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 ? 我应该尝试用BetterReflection这样的东西来修改AST吗?
As per comments, I guess that mocking language constructs is not feasible. 根据评论,我猜嘲笑语言结构是不可行的。
To test exit()
I ended up spawning other processes with exec
and asserting on their output and exist status 为了测试exit()
我最终用exec
其他进程并在其输出和存在状态上断言
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.