Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php中使用Carbon::setTestNow()?_Php_Unit Testing_Datetime_Time_Php Carbon - Fatal编程技术网

如何在php中使用Carbon::setTestNow()?

如何在php中使用Carbon::setTestNow()?,php,unit-testing,datetime,time,php-carbon,Php,Unit Testing,Datetime,Time,Php Carbon,出于测试目的,我想将日期设置为特定日期。我现在正尝试使用,但它无法做到: Carbon::setTestNow(Carbon::createFromDate(2000, 1, 1)); printf(date("Y-m-d H:i:s")); // prints 2018-06-28 13:21:06 我做错了什么?如何全局设置特定日期的时间?欢迎所有提示 是一个常规PHP函数,与碳和碳无关 不会改变系统时钟,因此这是预期的行为 我想你只是想一直使用碳: Carbon::setTestNow

出于测试目的,我想将日期设置为特定日期。我现在正尝试使用,但它无法做到:

Carbon::setTestNow(Carbon::createFromDate(2000, 1, 1));
printf(date("Y-m-d H:i:s"));  // prints 2018-06-28 13:21:06
我做错了什么?如何全局设置特定日期的时间?欢迎所有提示

是一个常规PHP函数,与碳和碳无关 不会改变系统时钟,因此这是预期的行为

我想你只是想一直使用碳:

Carbon::setTestNow(Carbon::createFromDate(2000, 1, 1));
echo Carbon::now();                     
是一个普通的PHP函数,与碳和碳无关 不会改变系统时钟,因此这是预期的行为

我想你只是想一直使用碳:

Carbon::setTestNow(Carbon::createFromDate(2000, 1, 1));
echo Carbon::now();                     

我也发现了同样的情况。不幸的是,我不能一直使用Carbon,因为在代码库中有许多对
time()
的调用。有什么方法可以全局更改所有php代码的时间吗?这意味着您的代码实际上是不可测试的,对不起。我刚刚发现了同样的问题。不幸的是,我不能一直使用Carbon,因为在代码库中有许多对
time()
的调用。是否有任何方法可以全局更改所有php代码的时间?这意味着您的代码实际上不可测试,对不起。关于如何在php中全局设置日期和时间,已经有一个问题:关于如何在php中全局设置日期和时间,已经有一个问题: