[Messenger] test DoctrineTransport on travis and appveyor

This commit is contained in:
Vincent Touzet 2019-04-03 22:17:05 +02:00 committed by Nicolas Grekas
parent de7d7a9ceb
commit 8f81f55a46
3 changed files with 24 additions and 15 deletions

View File

@ -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', [

View File

@ -103,7 +103,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()
@ -151,7 +151,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),
@ -202,7 +202,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()
@ -268,6 +268,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');
}
}

View File

@ -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",