diff --git a/src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineIntegrationTest.php b/src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineIntegrationTest.php index 08ae0d799e..aca22cf636 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\Tests\Fixtures\DummyMessage; 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 @@ class DoctrineIntegrationTest extends TestCase $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 @@ class DoctrineIntegrationTest extends TestCase '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 @@ class DoctrineIntegrationTest extends TestCase '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 701794f0b3..3191033f8e 100644 --- a/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php +++ b/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php @@ -106,7 +106,7 @@ class Connection */ 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() @@ -157,7 +157,7 @@ class Connection ->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), @@ -207,7 +207,7 @@ class Connection 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() @@ -273,6 +273,6 @@ class Connection 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 d3adb0271d..02d25efd5f 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",