8000 [Messenger] test DoctrineTransport on travis and appveyor · symfony/symfony@8f81f55 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8f81f55

Browse files
vincenttouzetnicolas-grekas
authored andcommitted
[Messenger] test DoctrineTransport on travis and appveyor
1 parent de7d7a9 commit 8f81f55

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineIntegrationTest.php

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,31 @@
1717
use Symfony\Component\Messenger\Transport\Doctrine\Connection;
1818

1919
/**
20-
* @requires pdo_mysql
20+
* @requires extension pdo_sqlite
2121
*/
2222
class DoctrineIntegrationTest extends TestCase
2323
{
2424
private $driverConnection;
2525
private $connection;
2626

27-
protected function setUp()
27+
/**
28+
* @after
29+
*/
30+
public function cleanup()
2831
{
29-
parent::setUp();
32+
@unlink(sys_get_temp_dir().'/symfony.messenger.sqlite');
33+
}
3034

31-
if (!getenv('MESSENGER_DOCTRINE_DSN')) {
32-
$this->markTestSkipped('The "MESSENGER_DOCTRINE_DSN" environment variable is required.');
35+
/**
36+
* @before
37+
*/
38+
public function createConnection()
39+
{
40+
if ($dsn = getenv('MESSENGER_DOCTRINE_DSN')) {
41+
$this->driverConnection = DriverManager::getConnection(['url' => $dsn]);
42+
} else {
43+
$this->driverConnection = DriverManager::getConnection(['pdo' => new \PDO('sqlite:'.sys_get_temp_dir().'/symfony.messenger.sqlite')]);
3344
}
34-
$dsn = getenv('MESSENGER_DOCTRINE_DSN');
35-
$this->driverConnection = DriverManager::getConnection(['url' => $dsn]);
3645
$this->connection = new Connection([], $this->driverConnection);
3746
// call send to auto-setup the table
3847
$this->connection->setup();
@@ -62,7 +71,7 @@ public function testSendWithDelay()
6271

6372
$available_at = new \DateTime($available_at);
6473

65-
$now = \DateTime::createFromFormat('U.u', microtime(true));
74+
$now = new \DateTime();
6675
$now->modify('+60 seconds');
6776
$this->assertGreaterThan($now, $available_at);
6877
}
@@ -77,7 +86,7 @@ public function testItRetrieveTheFirstAvailableMessage()
7786
'queue_name' => 'default',
7887
'created_at' => Connection::formatDateTime(new \DateTime('2019-03-15 12:00:00')),
7988
'available_at' => Connection::formatDateTime(new \DateTime('2019-03-15 12:00:00')),
80-
'delivered_at' => Connection::formatDateTime(\DateTime::createFromFormat('U.u', microtime(true))),
89+
'delivered_at' => Connection::formatDateTime(new \DateTime()),
8190
]);
8291
// one available later
8392
$this->driverConnection->insert('messenger_messages', [
@@ -110,7 +119,7 @@ public function testItCountMessages()
110119
'queue_name' => 'default',
111120
'created_at' => Connection::formatDateTime(new \DateTime('2019-03-15 12:00:00')),
112121
'available_at' => Connection::formatDateTime(new \DateTime('2019-03-15 12:00:00')),
113-
'delivered_at' => Connection::formatDateTime(\DateTime::createFromFormat('U.u', microtime(true))),
122+
'delivered_at' => Connection::formatDateTime(new \DateTime()),
114123
]);
115124
// one available later
116125
$this->driverConnection->insert('messenger_messages', [

src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public static function buildConfiguration($dsn, array $options = [])
103103
*/
104104
public function send(string $body, array $headers, int $delay = 0): void
105105
{
106-
$now = (\DateTime::createFromFormat('U.u', microtime(true)));
106+
$now = new \DateTime();
107107
$availableAt = (clone $now)->modify(sprintf('+%d seconds', $delay / 1000));
108108

109109
$queryBuilder = $this->driverConnection->createQueryBuilder()
@@ -151,7 +151,7 @@ public function get(): ?array
151151
->update($this->configuration['table_name'])
152152
->set('delivered_at', ':delivered_at')
153153
->where('id = :id');
154-
$now = \DateTime::createFromFormat('U.u', microtime(true));
154+
$now = new \DateTime();
155155
$this->executeQuery($queryBuilder->getSQL(), [
156156
':id' => $doctrineEnvelope['id'],
157157
':delivered_at' => self::formatDateTime($now),
@@ -202,7 +202,7 @@ public function getMessageCount(): int
202202

203203
private function createAvailableMessagesQueryBuilder(): QueryBuilder
204204
{
205-
$now = \DateTime::createFromFormat('U.u', microtime(true));
205+
$now = new \DateTime();
206206
$redeliverLimit = (clone $now)->modify(sprintf('-%d seconds', $this->configuration['redeliver_timeout']));
207207

208208
return $this->driverConnection->createQueryBuilder()
@@ -268,6 +268,6 @@ private function getSchema(): Schema
268268

269269
public static function formatDateTime(\DateTimeInterface $dateTime)
270270
{
271-
return $dateTime->format('Y-m-d\TH:i:s.uZ');
271+
return $dateTime->format('Y-m-d\TH:i:s');
272272
}
273273
}

src/Symfony/Component/Messenger/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"psr/log": "~1.0"
2121
},
2222
"require-dev": {
23-
"doctrine/dbal": "~2.4",
23+
"doctrine/dbal": "^2.5",
2424
"psr/cache": "~1.0",
2525
"symfony/console": "~3.4|~4.0",
2626
"symfony/dependency-injection": "~3.4.19|^4.1.8",

0 commit comments

Comments
 (0)
0