加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 17:03:01 所属栏目:PHP教程 来源:网络整理
导读:我正在尝试使用 PHPUnit 3.4.9为一些遗留代码编写测试,但似乎我的所有全局变量都是不可见的. 如何在PHPUnit 3.4.9中访问全局变量? 解决方法 它们应该可用.但是,PHPUnit在测试之间备份全局状态: By default,PHPUnit runs your tests in a way where changes
我正在尝试使用 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章节

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读