From 879befcc76e4aca3e6c9d2fea81e94f527e3b81c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lys=C3=BD?= Date: Mon, 10 Oct 2022 20:04:29 +0200 Subject: [PATCH] Add setting updatedAt to Subscriber factory [MAILPOET-4716] --- mailpoet/tests/DataFactories/Subscriber.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/mailpoet/tests/DataFactories/Subscriber.php b/mailpoet/tests/DataFactories/Subscriber.php index d3ccf99465..9858045bc8 100644 --- a/mailpoet/tests/DataFactories/Subscriber.php +++ b/mailpoet/tests/DataFactories/Subscriber.php @@ -183,6 +183,15 @@ class Subscriber { return $this; } + + /** + * @return $this + */ + public function withUpdatedAt(DateTimeInterface $updatedAt) { + $this->data['updatedAt'] = $updatedAt; + return $this; + } + /** * @throws \Exception */ @@ -226,6 +235,18 @@ class Subscriber { } $entityManager->flush(); + + // workaround for storing updatedAt because it's set in TimestampListener + if (isset($this->data['updatedAt'])) { + $subscribersTable = $entityManager->getClassMetadata(SubscriberEntity::class)->getTableName(); + $entityManager->getConnection()->executeQuery(" + UPDATE $subscribersTable + SET updated_at = '{$this->data['updatedAt']->format('Y-m-d H:i:s')}' + WHERE id = {$subscriber->getId()} + "); + $entityManager->refresh($subscriber); + } + return $subscriber; } }