minor #30857 [Messenger] test DoctrineTransport on travis and appveyor (vincenttouzet)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[Messenger] test DoctrineTransport on travis and appveyor

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes ? WIP
| Fixed tickets |
| License       | MIT
| Doc PR        |

Currently tests on the `Symfony\Component\Messenger\Tests\Transport\Doctrine\DoctrineIntegrationTest` are skipped because there is no `MESSENGER_DOCTRINE_DSN` environment variable is not defined.

This PR update the travis and AppVeyor configuration to run these tests.

This is a WIP. I'm not a Travis/AppVeyor user so this clearly need more work

Commits
-------

8f81f55a46 [Messenger] test DoctrineTransport on travis and appveyor
This commit is contained in:
Samuel ROZE 2019-04-06 11:50:34 +02:00
commit 550a569725
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

@ -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');
}
}

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