使用 phpunit 实现自定义 setcookie
我试图使用 test_helpers PECL 扩展覆盖 setcookie 实现,但没有任何运气。
$username = 'test';
set_setcookie_overload(function() { error_log('setcookie called'); return FALSE; });
setcookie('username', $userName, time()+60*60*24*365, '/');
unset_setcookie_overload();
我收到此错误: PHP 致命错误:调用未定义的函数 set_setcookie_overload()
我验证了该扩展与此处的示例运行良好: https://github.com/sebastianbergmann/php-test-helpers
谢谢。
更新:为了进一步说明,听起来 test_helpers 扩展允许覆盖内置的 PHP 函数,例如 setcookie。在上面的链接中,作者提供了一个使用 set_exit_overload() 重写退出方法的示例。我试图使用 set_setcookie_overload() 对 setcookie() 做同样的事情,但没有任何运气。
I'm trying to override the setcookie implementation using the test_helpers PECL extension without any luck.
$username = 'test';
set_setcookie_overload(function() { error_log('setcookie called'); return FALSE; });
setcookie('username', $userName, time()+60*60*24*365, '/');
unset_setcookie_overload();
I get this error:
PHP Fatal error: Call to undefined function set_setcookie_overload()
I verified that the extension is working well with the example here: https://github.com/sebastianbergmann/php-test-helpers
Thanks.
Update: For further clarification, it sounds like the test_helpers extension allows to override in-built PHP functions like setcookie. In the link above, the author has provided an example to override the exit method using set_exit_overload(). I'm trying to do the same for setcookie() using set_setcookie_overload() without any luck.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可用的函数可以在源代码中找到 < strong>
在 github
。以PHP_FUNCTION
开头的所有内容都公开给用户调用。所以是的。 php-test-helpers 中没有
set_setcookie_overload()
。你必须找到另一种解决方法。遗憾的是
rename_function
也无法帮助您,因为它不适用于内部函数。test_helpers扩展的完整功能列表
The functions that are available in can be found in the source
over at github
. Everything starting withPHP_FUNCTION
is exposed to the user to call.So yeah. There just is no
set_setcookie_overload()
in php-test-helpers. You have to find another workaround.Sadly
rename_function
can't help you either as it doesn't work with internal functions.Complete function list of the test_helpers extension