diff --git a/lib/Models/ScheduledTask.php b/lib/Models/ScheduledTask.php index 9a1eebe7e1..d2e26f73aa 100644 --- a/lib/Models/ScheduledTask.php +++ b/lib/Models/ScheduledTask.php @@ -36,7 +36,7 @@ class ScheduledTask extends Model { public function __construct() { parent::__construct(); - $this->wp = new WPFunctions(); + $this->wp = WPFunctions::get(); } public function subscribers() { diff --git a/tests/integration/AutomaticEmails/WooCommerce/Events/AbandonedCartTest.php b/tests/integration/AutomaticEmails/WooCommerce/Events/AbandonedCartTest.php index a56d54e807..467aa0b389 100644 --- a/tests/integration/AutomaticEmails/WooCommerce/Events/AbandonedCartTest.php +++ b/tests/integration/AutomaticEmails/WooCommerce/Events/AbandonedCartTest.php @@ -50,7 +50,13 @@ class AbandonedCartTest extends \MailPoetTest { Carbon::setTestNow($this->currentTime); $this->wp = $this->makeEmpty(WPFunctions::class, [ - 'currentTime' => $this->currentTime->getTimestamp(), + 'currentTime' => function ($arg) { + if ($arg === 'timestamp') { + return $this->currentTime->getTimestamp(); + } elseif ($arg === 'mysql') { + return $this->currentTime->format('Y-m-d H:i:s'); + } + }, ]); WPFunctions::set($this->wp); diff --git a/tests/integration/Cron/Workers/SchedulerTest.php b/tests/integration/Cron/Workers/SchedulerTest.php index a427ba7483..62ed056012 100644 --- a/tests/integration/Cron/Workers/SchedulerTest.php +++ b/tests/integration/Cron/Workers/SchedulerTest.php @@ -317,8 +317,14 @@ class SchedulerTest extends \MailPoetTest { } public function testItReschedulesQueueDeliveryWhenMailpoetSubscriberHasNotConfirmedSubscription() { - $currentTime = Carbon::createFromTimestamp(WPFunctions::get()->currentTime('timestamp')); + $timestamp = WPFunctions::get()->currentTime('timestamp'); + $wpFunctions = $this->make(WPFunctions::class, [ + 'currentTime' => $timestamp, + ]); + WPFunctions::set($wpFunctions); + $currentTime = Carbon::createFromTimestamp($timestamp); Carbon::setTestNow($currentTime); // mock carbon to return current time + $subscriber = $this->_createSubscriber($wpUserId = null, 'unconfirmed'); $segment = $this->_createSegment(); $subscriberSegment = $this->_createSubscriberSegment($subscriber->id, $segment->id); @@ -344,6 +350,7 @@ class SchedulerTest extends \MailPoetTest { expect(Carbon::parse($updatedQueue->scheduledAt))->equals( $currentTime->addMinutes(ScheduledTask::BASIC_RESCHEDULE_TIMEOUT) ); + WPFunctions::set(new WPFunctions()); } public function testItDoesntRunQueueDeliveryWhenMailpoetSubscriberHasUnsubscribed() {