I am working on a magento custom module , and trying to test if the emails are sent properly , the module sends emails after 48 hours of an event , how do i modify the magento date time to test if the module is sending the mails .

  • 2
    Would it not be easier to just change your module to send the email 1 minute after the event and then once you have confirmed emails are sending correctly, change it back to 48 hours? Magento date/time is based on timezones so it won't be easy to manually modify this to a custom configuration.
    – zigojacko
    Jun 3, 2016 at 11:39
  • The only way to change the Magento time would be to change your server time which wouldn't be recommended since it would mess up logs and database entries and such.
    – Mike
    Jun 3, 2016 at 22:05

2 Answers 2


If you are talking about manual testing, you could copy lib/Varien/Date.php to app/code/local/Varien/Date.php and adjust the now method to use a fixed date and time:

    public static function now($withoutTime = false)
        $format = $withoutTime ? self::DATE_PHP_FORMAT : self::DATETIME_PHP_FORMAT;
---        return date($format);
+++        return date($format, strtotime("2016-04-06 11:00"));

(I assume that you use Varien_Date::now() in your custom module and not PHP built-in functions)

If you are talking about unit testing, replace the class with a test stub. Unfortunately this does not work with static methods, so you would have to create an instantiated wrapper.

It could look like this:

class My_DateTime
    public function now($withoutTime = false)
        return Varien_Date::now($withoutTime);

Then inject an instance of My_DateTime in the class(es) that use the current date so that you can replace it with a mock object:

class My_Email_Scheduler
    /** @var My_DateTime */
    protected $_dateTime;
    public function __construct()
        $this->_dateTime = new My_DateTime;
    public function setDateTime(My_DateTime $dateTime) 
        $this->_dateTIme = $dateTime;

like what zigojacko told you, it is much easier for you to test it manually, find the cron job that you want to call, for example in your config.xml if you have:

<schedule><cron_expr>0,15,30,45 * * * *</cron_expr></schedule>

you can create a file or simply just use your cron.php file and do this:

    $model = Mage::getModel('module_email/emailcustomer');

then just run your file and your function will generate your desired results.

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.