Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Messenger] test DoctrineTransport on travis and appveyor #30857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand All @@ -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', [
Expand Down Expand Up @@ -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', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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');
}
}
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Messenger/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.