What exactly are you trying to do? If you are experiencing something, you should not rely on the system configuration at all - it is better to do something like:
my_function(\DateTime $now = null) { if($now === null) { return new \DateTime(); } else { return $now; } }
In your regular code, you just call my_function() , but in your test, you call
$now = \DateTime::createFromFormat(...); my_function($now);
A similar idea if this is for production code. Pass the date as a parameter, instead of leaving the function to receive it.
my_function(\DateTime $datetime) { // does stuff } call_my_function() { my_function(new \DateTime()); } other_way_to_call_my_function() { $datetime = \DateTime::createFromFormat(...); my_function($datetime); }
source share