Fix flakey scheduler test

[MAILPOET-2896]
This commit is contained in:
Pavel Dohnal
2020-06-09 09:42:20 +02:00
committed by Veljko V
parent 6e7b7b5da8
commit b1cd785dfe
3 changed files with 16 additions and 3 deletions

View File

@@ -36,7 +36,7 @@ class ScheduledTask extends Model {
public function __construct() { public function __construct() {
parent::__construct(); parent::__construct();
$this->wp = new WPFunctions(); $this->wp = WPFunctions::get();
} }
public function subscribers() { public function subscribers() {

View File

@@ -50,7 +50,13 @@ class AbandonedCartTest extends \MailPoetTest {
Carbon::setTestNow($this->currentTime); Carbon::setTestNow($this->currentTime);
$this->wp = $this->makeEmpty(WPFunctions::class, [ $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); WPFunctions::set($this->wp);

View File

@@ -317,8 +317,14 @@ class SchedulerTest extends \MailPoetTest {
} }
public function testItReschedulesQueueDeliveryWhenMailpoetSubscriberHasNotConfirmedSubscription() { 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 Carbon::setTestNow($currentTime); // mock carbon to return current time
$subscriber = $this->_createSubscriber($wpUserId = null, 'unconfirmed'); $subscriber = $this->_createSubscriber($wpUserId = null, 'unconfirmed');
$segment = $this->_createSegment(); $segment = $this->_createSegment();
$subscriberSegment = $this->_createSubscriberSegment($subscriber->id, $segment->id); $subscriberSegment = $this->_createSubscriberSegment($subscriber->id, $segment->id);
@@ -344,6 +350,7 @@ class SchedulerTest extends \MailPoetTest {
expect(Carbon::parse($updatedQueue->scheduledAt))->equals( expect(Carbon::parse($updatedQueue->scheduledAt))->equals(
$currentTime->addMinutes(ScheduledTask::BASIC_RESCHEDULE_TIMEOUT) $currentTime->addMinutes(ScheduledTask::BASIC_RESCHEDULE_TIMEOUT)
); );
WPFunctions::set(new WPFunctions());
} }
public function testItDoesntRunQueueDeliveryWhenMailpoetSubscriberHasUnsubscribed() { public function testItDoesntRunQueueDeliveryWhenMailpoetSubscriberHasUnsubscribed() {