微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在PHPUnit 3.4.9中访问全局变量?

我正在尝试使用 PHPUnit 3.4.9为一些遗留代码编写测试,但似乎我的所有全局变量都是不可见的.

如何在PHPUnit 3.4.9中访问全局变量

解决方法

它们应该可用.但是,PHPUnit在测试之间备份全局状态:

By default,PHPUnit runs your tests in a way where changes to global and super-global variables ($GLOBALS,$_ENV,$_POST,$_GET,$_COOKIE,$_SERVER,$_FILES,$_REQUEST) do not affect other tests. Optionally,this isolation can be extended to static attributes of classes.

所以这可能是一个问题.另请注意

Objects of some classes that are provided by PHP itself,such as PDO for example,cannot be serialized and the backup operation will break when such an object is stored in the $GLOBALS array,for instance.

请参阅Testing Global State in the PHPUnit Manual章节

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐