Adds unit test

This commit is contained in:
Vlad
2018-03-20 16:15:57 -04:00
parent 44b96aa9a7
commit d317eb4fbd
4 changed files with 27 additions and 1 deletions

View File

@ -8,6 +8,7 @@ use MailPoet\Mailer\MailerLog;
use MailPoet\Models\ScheduledTask;
use MailPoet\Models\ScheduledTaskSubscriber;
use MailPoet\Models\SendingQueue;
use MailPoet\WP\Functions as WPFunctions;
if(!defined('ABSPATH')) exit;
@ -242,6 +243,6 @@ class Migration extends SimpleWorker {
static function getNextRunDate() {
// run migration immediately
return Carbon::createFromTimestamp(current_time('timestamp'));
return Carbon::createFromTimestamp(WPFunctions::currentTime('timestamp'));
}
}

View File

@ -22,6 +22,10 @@ class Functions {
return self::callWithFallback('wp_remote_retrieve_response_message', func_get_args());
}
static function currentTime() {
return self::callWithFallback('current_time', func_get_args());
}
private static function callWithFallback($func, $args) {
$local_func = __NAMESPACE__ . '\\' . $func;
if(function_exists($local_func)) {

View File

@ -71,3 +71,7 @@ function wp_remote_post() {
function wp_remote_get() {
return override(__FUNCTION__, func_get_args());
}
function current_time() {
return override(__FUNCTION__, func_get_args());
}

View File

@ -2,6 +2,7 @@
namespace MailPoet\Test\Cron\Workers;
use Carbon\Carbon;
use Helper\WordPress as WordPressHelper;
use MailPoet\Cron\Workers\SendingQueue\Migration;
use MailPoet\Mailer\MailerLog;
use MailPoet\Models\ScheduledTask;
@ -107,6 +108,20 @@ class MigrationTest extends \MailPoetTest {
expect(MailerLog::isSendingPaused())->false();
}
function testItUsesWPTimeToReturnNextRunDate() {
$timestamp = 1514801410; // 01/01/2018 @ 10:10am (UTC)
WordPressHelper::interceptFunction('current_time', function($time) use($timestamp) {
// "timestamp" string is passed as an argument
expect($time)->equals('timestamp');
return $timestamp;
});
$next_run_date = Migration::getNextRunDate();
expect($next_run_date->timestamp)->equals($timestamp);
}
private function createScheduledTask() {
$task = ScheduledTask::create();
$task->type = Migration::TASK_TYPE;
@ -185,5 +200,7 @@ class MigrationTest extends \MailPoetTest {
$this->restoreTable();
$this->altered = false;
}
WordPressHelper::releaseAllFunctions();
}
}