0

I am testing the recurring framework in Drupal commerce on my local mamp environment and I want to test the recurring payments. How to I trick my Drupal site into thinking it's a day later so it will trigger the recurring payment?

4
  • 2
    What about changing system date and running cron? – sanzante Mar 29 '14 at 15:56
  • Why not change the interval the recurring payments happen at? Say set them to an hour or a minute. That's usually my go to for testing rules scheduling. – Dominic Woodman Mar 30 '14 at 15:21
  • Not directly an answer, but might help - check out Commerce Dunning which will allow you to test failure of recurring payments. Other than that, I agree with @tunic. – Aram Boyajyan Mar 30 '14 at 18:12
  • @Dominic Woodman the lowest interval in 1 day in the module I am using. – Nigel Waters Apr 4 '14 at 17:23
3
+50

Change the time of your system/server and run cron manually. PHP reads the time from your system settings and cron is what executes the recurring product functions at the required time.

3

If you are working with 5.3+ you can do a trick with namespaces: implementing a new time() function inside your current namespace and create a shared resource where you set the return value in your tests.

You can found a complete description in this blog post:

PHP: “Mocking” built-in functions like time() in Unit Tests

1

i think you can change the PHP time zone to force a time zone then change your local machine to a day later it may help

0

Using PHP timezone function change the timezone first. See the links for more detail about timezone.

https://php.net/manual/en/timezones.php and https://php.net/manual/en/timezones.africa.php

Calculate day later time using

date_default_timezone_set('America/Los_Angeles');
$new_date = date('Y-m-d H:i:s', strtotime('+1 day', $current_date); 

similar functions. which will help you to test the recurring system by setting manual time to drupal.

Drupal provide default time zone functions just so you can setting timezone and calculate the time in your hook_cron(). while trigger will get fired Cron processing will work based on your condition.

Hope it will help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.