我正在尝试学习 Codeception 并将其与 Yii 一起使用(我也是新手)。
开箱即用,我在运行测试时遇到了一些问题。我已经浏览了 quickstart guide当我通过终端运行它时,出现此错误:
Codeception PHP Testing Framework v1.6.6
Powered by PHPUnit 3.7.24 by Sebastian Bergmann.
[Exception]
DateTime::__construct(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date
_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the tim
ezone identifier. We selected 'America/Chicago' for 'CDT/-5.0/DST' instead
现在,我正在使用 MAMP,并在我的 php.ini 文件中设置了时区。我还尝试使用 _default_timezone_set('America/Chicago');
在 index.php 文件中手动设置它,但我仍然收到相同的消息。
当我使用 Yii 时,我已经尝试为 Codeception 启用 Yii 模块,但这似乎没有任何区别。
更新
我已经尝试在一个非基于 yii 的项目上安装 codeception,所以在一个直接的网站上,我得到了与上面完全相同的错误。
最佳答案
我遇到了同样的问题,发现在 php.ini 中设置 date.timezone
设置解决了问题。
- 打开 php.ini(在 Mac 上是/private/etc/php.ini)
- 搜索“时区”。第一次点击应该是这个设置
- 取消注释行
;date.timezone =
(删除 ;) - 将您的时区添加为字符串,例如
"America/New_York"
,所以整行显示为date.timezone = "America/New_York"
- 保存文件并重新启动您的网络服务器
时区选项列表在这里: http://www.php.net/manual/en/timezones.php
希望对您有所帮助。
关于php - 代码接收日期时间错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18768276/