If I have an delayed action in my code then how on Earth can I unit test this?
For example a membership transition?
CiviCRM Stack Exchange is a question and answer site for administrators and users of the CiviCRM Constituent Relationship Management software. It only takes a minute to sign up.Sign up to join this community
Totten, who is a complete legend, shared this pearl with me:
there are some examples like:
\CRM_Utils_Time::setTime('2013-11-30 01:00:00');however, these are the exception rather than the rule. there are lots of places where someone called
CRM_Utils_Timeto find the baseline.
You may not need to wait for a delayed action to occur. See if it is possible to test this without any delay.
JobTest::testCallSendReminderLimitTo() and some other scheduled reminder tests actually test a "scheduled" action, by creating the necessary circumstances to have it happen immediately.
A (slow!) integration test might verify that a membership renewal is triggered at twelve months after join, while a group of unit tests might verify each component of that chain (one tests that the membership expiry is set as expected, another tests that the membership expiry rollover happens, another tests that the membership reminder is triggered at rollover).