A
A
Aleks_ja2013-07-23 16:08:19
PHP
Aleks_ja, 2013-07-23 16:08:19

Checking how the site works in the future

Is it possible to translate the date purely for php and mysql? without changing the system time.

For example, the project has monthly payments on the 1st day of each month. To check that the billing will go well and evaluate what will happen, we can only locally move the system time forward and see what happens.

But testers somehow need to check on their server - this will not work there. And in general, some kind of automated testing should be done for such tasks.

Is there a solution to this problem?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nikita Gusakov, 2013-07-23
@Aleks_ja

the more “it’s all complicated there” - the more difficult it will be for you to maintain in the future. You can use php.net/manual/ru/book.runkit.php , so you can replace the native php functions, and give the date a month later, for example. Although if there is such a need, it would be better if you made a wrapper for DateTime, which you can mock in tests and do whatever you need with it

M
Murloc, 2013-07-23
@Murloc

Alternatively, you can change the time in the system to the desired one at the beginning of the request, and set it back at the end of the request. If you want in php, then specify your mktime for the date(format,mktime) function, if you use the DateTime class, set the date using DateTime::setDate. But it is better, of course, to change the time in the system if you have something complex and unchangeable. Or adapt your script/program for tests.

E
Evgeny Neverov, 2013-07-23
@deMone

Depends on how you run the billing calculation every first day.
Let's say, if you just have some script set to execute in cron, you can run it manually before the appointed time. However, there can be a lot of problems, because it is not known exactly how your script is written, and what will happen if it is not run on time.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question