0

I have a test where I have to compare the current_time to determine another time. Other than using Mocking (i.e. another method that returns the time I specify) is there another way I can change the system time to a specified time temporarily for another test. I want a simple way to have time() return another value.

rockstardev
  • 13,479
  • 39
  • 164
  • 296
  • 3
    Wrap the time() function in an object that you can inject your own logic into. Unfortunately you'll run into this problem with a lot of native php functions. Related: http://stackoverflow.com/questions/2371854/can-i-mock-time-in-phpunit – Mike B Nov 08 '13 at 12:55

1 Answers1

-2

If you install the runkit extension, you can archieve that, by using the runkit_function_redefine function.

From the PHP docs: In order to override internal functions, you must enable the runkit.internal_override setting in php.ini.

Then you can assign a code string as the function body.

regards

gontrollez
  • 6,372
  • 2
  • 28
  • 36