From 8f81f55a46c55c987fdfdaae6b71221d4c0323aa Mon Sep 17 00:00:00 2001 From: Vincent Touzet Date: Wed, 3 Apr 2019 22:17:05 +0200 Subject: [PATCH] [Messenger] test DoctrineTransport on travis and appveyor --- .../Doctrine/DoctrineIntegrationTest.php | 29 ++++++++++++------- .../Transport/Doctrine/Connection.php | 8 ++--- src/Symfony/Component/Messenger/composer.json | 2 +- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineIntegrationTest.php b/src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineIntegrationTest.php index bc826832c593b..7397c69b839dc 100644 --- a/src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineIntegrationTest.php +++ b/src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineIntegrationTest.php @@ -17,22 +17,31 @@ use Symfony\Component\Messenger\Transport\Doctrine\Connection; /** - * @requires pdo_mysql + * @requires extension pdo_sqlite */ class DoctrineIntegrationTest extends TestCase { private $driverConnection; private $connection; - protected function setUp() + /** + * @after + */ + public function cleanup() { - parent::setUp(); + @unlink(sys_get_temp_dir().'/symfony.messenger.sqlite'); + } - if (!getenv('MESSENGER_DOCTRINE_DSN')) { - $this->markTestSkipped('The "MESSENGER_DOCTRINE_DSN" environment variable is required.'); + /** + * @before + */ + public function createConnection() + { + if ($dsn = getenv('MESSENGER_DOCTRINE_DSN')) { + $this->driverConnection = DriverManager::getConnection(['url' => $dsn]); + } else { + $this->driverConnection = DriverManager::getConnection(['pdo' => new \PDO('sqlite:'.sys_get_temp_dir().'/symfony.messenger.sqlite')]); } - $dsn = getenv('MESSENGER_DOCTRINE_DSN'); - $this->driverConnection = DriverManager::getConnection(['url' => $dsn]); $this->connection = new Connection([], $this->driverConnection); // call send to auto-setup the table $this->connection->setup(); @@ -62,7 +71,7 @@ public function testSendWithDelay() $available_at = new \DateTime($available_at); - $now = \DateTime::createFromFormat('U.u', microtime(true)); + $now = new \DateTime(); $now->modify('+60 seconds'); $this->assertGreaterThan($now, $available_at); } @@ -77,7 +86,7 @@ public function testItRetrieveTheFirstAvailableMessage() 'queue_name' => 'default', 'created_at' => Connection::formatDateTime(new \DateTime('2019-03-15 12:00:00')), 'available_at' => Connection::formatDateTime(new \DateTime('2019-03-15 12:00:00')), - 'delivered_at' => Connection::formatDateTime(\DateTime::createFromFormat('U.u', microtime(true))), + 'delivered_at' => Connection::formatDateTime(new \DateTime()), ]); // one available later $this->driverConnection->insert('messenger_messages', [ @@ -110,7 +119,7 @@ public function testItCountMessages() 'queue_name' => 'default', 'created_at' => Connection::formatDateTime(new \DateTime('2019-03-15 12:00:00')), 'available_at' => Connection::formatDateTime(new \DateTime('2019-03-15 12:00:00')), - 'delivered_at' => Connection::formatDateTime(\DateTime::createFromFormat('U.u', microtime(true))), + 'delivered_at' => Connection::formatDateTime(new \DateTime()), ]); // one available later $this->driverConnection->insert('messenger_messages', [ diff --git a/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php b/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php index ad3ab192d5bd1..e9477ff79848c 100644 --- a/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php +++ b/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php @@ -103,7 +103,7 @@ public static function buildConfiguration($dsn, array $options = []) */ public function send(string $body, array $headers, int $delay = 0): void { - $now = (\DateTime::createFromFormat('U.u', microtime(true))); + $now = new \DateTime(); $availableAt = (clone $now)->modify(sprintf('+%d seconds', $delay / 1000)); $queryBuilder = $this->driverConnection->createQueryBuilder() @@ -151,7 +151,7 @@ public function get(): ?array ->update($this->configuration['table_name']) ->set('delivered_at', ':delivered_at') ->where('id = :id'); - $now = \DateTime::createFromFormat('U.u', microtime(true)); + $now = new \DateTime(); $this->executeQuery($queryBuilder->getSQL(), [ ':id' => $doctrineEnvelope['id'], ':delivered_at' => self::formatDateTime($now), @@ -202,7 +202,7 @@ public function getMessageCount(): int private function createAvailableMessagesQueryBuilder(): QueryBuilder { - $now = \DateTime::createFromFormat('U.u', microtime(true)); + $now = new \DateTime(); $redeliverLimit = (clone $now)->modify(sprintf('-%d seconds', $this->configuration['redeliver_timeout'])); return $this->driverConnection->createQueryBuilder() @@ -268,6 +268,6 @@ private function getSchema(): Schema public static function formatDateTime(\DateTimeInterface $dateTime) { - return $dateTime->format('Y-m-d\TH:i:s.uZ'); + return $dateTime->format('Y-m-d\TH:i:s'); } } diff --git a/src/Symfony/Component/Messenger/composer.json b/src/Symfony/Component/Messenger/composer.json index d3adb0271dd37..02d25efd5fc4f 100644 --- a/src/Symfony/Component/Messenger/composer.json +++ b/src/Symfony/Component/Messenger/composer.json @@ -20,7 +20,7 @@ "psr/log": "~1.0" }, "require-dev": { - "doctrine/dbal": "~2.4", + "doctrine/dbal": "^2.5", "psr/cache": "~1.0", "symfony/console": "~3.4|~4.0", "symfony/dependency-injection": "~3.4.19|^4.1.8", pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy