Re: [Discussion] Add date_test_set_now() function

From: Date: Tue, 02 Jul 2024 04:39:14 +0000
Subject: Re: [Discussion] Add date_test_set_now() function
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-124170@lists.php.net to get a copy of this message
> > > https://github.com/colopl/php-colopl_timeshifter > > However, this Extension has some problems. > > The first is that there's no way to determine whether the format passed to > the ext-date parser is relative or absolute time, resulting in a dirty hack > using usleep. The second is that it depends on timelib, so it breaks when > upstream changes related to timelib are made. > > So, how about adding a date_set_test_now(\DateInterval > $shiftInterval) > function to ext-date? > > This function would treat the current time as shifted by the passed > DateInterval. Since it's implemented on the ext-date side, there's no need > for dirty hacks using usleep. > > I can see how this would be useful on legacy applications, not forcing many changes everywhere. However, I think that we should not encourage this and keep it out of php core offering. Having it as a separate php extension sounds good to me, and as long as that php extension is loaded and used only while running tests, it helps with not possibly impacting production in any way. Indeed, it mighty have some limitations but I think we can work around them. An alternative solution would be to have namespaced functions and classes and use rector to automate the replacement of native ones just before running tests and package everything as a testing php library. Alex

« previous php.internals (#124170) next »