PHPUnit抛出“警告:日期():它不安全……”

前端之家收集整理的这篇文章主要介绍了PHPUnit抛出“警告:日期():它不安全……”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当运行PHPunit –coverage-html时,我得到了关于时区的众所周知的警告.

PHP Warning: date(): 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 timezone identifier. We selected the timezone ‘UTC’ for
now,but please set date.timezone to select your timezone.

一切都按预期工作,但它变得非常烦人.

当然,我可以通过更改我的PHP.ini来解决这个问题,但如果可能的话,我宁愿避免使用它,以保持一些服务器不可知性.另外,我不希望在我的可测试代码触发时阻止出现此警告.

有没有办法只为内部PHPUnit操作定义默认时区?

我在bootstrap.PHP文件中设置了TimeZone.
<?PHP
// PHP and Web server settings
error_reporting(E_ALL | E_STRICT);
date_default_timezone_set("America/Toronto");       // Set the default timezone
$_SERVER['SERVER_NAME'] = 'http://myserver';       // Set Web Server name

// Process the Include Path to allow the additional application to be set.
$IncludePaths = explode( PATH_SEPARATOR,get_include_path() );
$NewIncludePaths = array_merge( $IncludePaths,array(dirname(__FILE__) ));
set_include_path( implode( PATH_SEPARATOR,array_unique($NewIncludePaths)));    // Update Include Path

//define('PHPUNIT_RUNNING',1); // Indicate to the code that Automated Testing is running.
?>
原文链接:https://www.f2er.com/php/138002.html

猜你在找的PHP相关文章