Skip to content

Commit

Permalink
Merge branch '5.4' into 6.3
Browse files Browse the repository at this point in the history
* 5.4:
  [FrameworkBundle] Configure `logger` as error logger if the Monolog Bundle is not registered
  DX: PHP CS Fixer - drop explicit nullable_type_declaration_for_default_null_value config, as it's part of ruleset anyway
  Revert "Add keyword `dev` to leverage composer hint"
  [Validator] Add missing Ukrainian translations #51960
  [Validator] Add missing translations for Indonesian (id)
  [Validator] Add missing translations for Vietnamese (VI)
  Add missing Validator translations - Croatian (hr)
  Run high-deps tests with ORM 3 and DBAL 4
  [FrameworkBundle] Fix calling Kernel::warmUp() when running cache:warmup
  • Loading branch information
nicolas-grekas committed Oct 12, 2023
2 parents f1c253e + 07ad5f6 commit 9fec1e5
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 22 deletions.
48 changes: 34 additions & 14 deletions Tests/Transport/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MariaDBPlatform;
use Doctrine\DBAL\Platforms\MySQL57Platform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\SQLServer2012Platform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Query\QueryBuilder;
use Doctrine\DBAL\Result;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
Expand Down Expand Up @@ -98,7 +100,7 @@ public function testItThrowsATransportExceptionIfItCannotAcknowledgeMessage()
{
$this->expectException(TransportException::class);
$driverConnection = $this->getDBALConnectionMock();
$driverConnection->method('delete')->willThrowException(new DBALException());
$driverConnection->method('delete')->willThrowException($this->createStub(DBALException::class));

$connection = new Connection([], $driverConnection);
$connection->ack('dummy_id');
Expand All @@ -108,7 +110,7 @@ public function testItThrowsATransportExceptionIfItCannotRejectMessage()
{
$this->expectException(TransportException::class);
$driverConnection = $this->getDBALConnectionMock();
$driverConnection->method('delete')->willThrowException(new DBALException());
$driverConnection->method('delete')->willThrowException($this->createStub(DBALException::class));

$connection = new Connection([], $driverConnection);
$connection->reject('dummy_id');
Expand Down Expand Up @@ -385,7 +387,7 @@ public function testGeneratedSql(AbstractPlatform $platform, string $expectedSql
public static function providePlatformSql(): iterable
{
yield 'MySQL' => [
new MySQL57Platform(),
class_exists(MySQLPlatform::class) ? new MySQLPlatform() : new MySQL57Platform(),
'SELECT m.* FROM messenger_messages m WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?) ORDER BY available_at ASC LIMIT 1 FOR UPDATE',
];

Expand All @@ -397,14 +399,23 @@ public static function providePlatformSql(): iterable
}

yield 'SQL Server' => [
new SQLServer2012Platform(),
class_exists(SQLServerPlatform::class) && !class_exists(SQLServer2012Platform::class) ? new SQLServerPlatform() : new SQLServer2012Platform(),
'SELECT m.* FROM messenger_messages m WITH (UPDLOCK, ROWLOCK) WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?) ORDER BY available_at ASC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY ',
];

yield 'Oracle' => [
new OraclePlatform(),
'SELECT w.id AS "id", w.body AS "body", w.headers AS "headers", w.queue_name AS "queue_name", w.created_at AS "created_at", w.available_at AS "available_at", w.delivered_at AS "delivered_at" FROM messenger_messages w WHERE w.id IN (SELECT a.id FROM (SELECT m.id FROM messenger_messages m WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?) ORDER BY available_at ASC) a WHERE ROWNUM <= 1) FOR UPDATE',
];
if (!class_exists(MySQL57Platform::class)) {
// DBAL >= 4
yield 'Oracle' => [
new OraclePlatform(),
'SELECT w.id AS "id", w.body AS "body", w.headers AS "headers", w.queue_name AS "queue_name", w.created_at AS "created_at", w.available_at AS "available_at", w.delivered_at AS "delivered_at" FROM messenger_messages w WHERE w.id IN (SELECT m.id FROM messenger_messages m WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?) ORDER BY available_at ASC FETCH NEXT 1 ROWS ONLY) FOR UPDATE',
];
} else {
// DBAL < 4
yield 'Oracle' => [
new OraclePlatform(),
'SELECT w.id AS "id", w.body AS "body", w.headers AS "headers", w.queue_name AS "queue_name", w.created_at AS "created_at", w.available_at AS "available_at", w.delivered_at AS "delivered_at" FROM messenger_messages w WHERE w.id IN (SELECT a.id FROM (SELECT m.id FROM messenger_messages m WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?) ORDER BY available_at ASC) a WHERE ROWNUM <= 1) FOR UPDATE',
];
}
}

public function testConfigureSchema()
Expand Down Expand Up @@ -473,7 +484,7 @@ public function testFindAllSqlGenerated(AbstractPlatform $platform, string $expe
public function provideFindAllSqlGeneratedByPlatform(): iterable
{
yield 'MySQL' => [
new MySQL57Platform(),
class_exists(MySQLPlatform::class) ? new MySQLPlatform() : new MySQL57Platform(),
'SELECT m.* FROM messenger_messages m WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?) LIMIT 50',
];

Expand All @@ -485,13 +496,22 @@ public function provideFindAllSqlGeneratedByPlatform(): iterable
}

yield 'SQL Server' => [
new SQLServer2012Platform(),
class_exists(SQLServerPlatform::class) && !class_exists(SQLServer2012Platform::class) ? new SQLServerPlatform() : new SQLServer2012Platform(),
'SELECT m.* FROM messenger_messages m WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?) ORDER BY (SELECT 0) OFFSET 0 ROWS FETCH NEXT 50 ROWS ONLY',
];

yield 'Oracle' => [
new OraclePlatform(),
'SELECT a.* FROM (SELECT m.id AS "id", m.body AS "body", m.headers AS "headers", m.queue_name AS "queue_name", m.created_at AS "created_at", m.available_at AS "available_at", m.delivered_at AS "delivered_at" FROM messenger_messages m WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?)) a WHERE ROWNUM <= 50',
];
if (!class_exists(MySQL57Platform::class)) {
// DBAL >= 4
yield 'Oracle' => [
new OraclePlatform(),
'SELECT m.id AS "id", m.body AS "body", m.headers AS "headers", m.queue_name AS "queue_name", m.created_at AS "created_at", m.available_at AS "available_at", m.delivered_at AS "delivered_at" FROM messenger_messages m WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?) FETCH NEXT 50 ROWS ONLY',
];
} else {
// DBAL < 4
yield 'Oracle' => [
new OraclePlatform(),
'SELECT a.* FROM (SELECT m.id AS "id", m.body AS "body", m.headers AS "headers", m.queue_name AS "queue_name", m.created_at AS "created_at", m.available_at AS "available_at", m.delivered_at AS "delivered_at" FROM messenger_messages m WHERE (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) AND (m.queue_name = ?)) a WHERE ROWNUM <= 50',
];
}
}
}
12 changes: 10 additions & 2 deletions Tests/Transport/DoctrineTransportFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ public function testCreateTransport()
$schemaConfig = $this->createMock(SchemaConfig::class);
$platform = $this->createMock(AbstractPlatform::class);
$schemaManager->method('createSchemaConfig')->willReturn($schemaConfig);
$driverConnection->method('getSchemaManager')->willReturn($schemaManager);
$driverConnection->method(
method_exists(\Doctrine\DBAL\Connection::class, 'createSchemaManager')
? 'createSchemaManager'
: 'getSchemaManager'
)->willReturn($schemaManager);
$driverConnection->method('getDatabasePlatform')->willReturn($platform);
$registry = $this->createMock(ConnectionRegistry::class);

Expand All @@ -70,7 +74,11 @@ public function testCreateTransportNotifyWithPostgreSQLPlatform()
$schemaConfig = $this->createMock(SchemaConfig::class);
$platform = $this->createMock(PostgreSQLPlatform::class);
$schemaManager->method('createSchemaConfig')->willReturn($schemaConfig);
$driverConnection->method('getSchemaManager')->willReturn($schemaManager);
$driverConnection->method(
method_exists(\Doctrine\DBAL\Connection::class, 'createSchemaManager')
? 'createSchemaManager'
: 'getSchemaManager'
)->willReturn($schemaManager);
$driverConnection->method('getDatabasePlatform')->willReturn($platform);
$driverConnection->method('executeStatement')->willReturn(1);
$registry = $this->createMock(ConnectionRegistry::class);
Expand Down
7 changes: 2 additions & 5 deletions Transport/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,8 @@ public function get(): ?array

// Append pessimistic write lock to FROM clause if db platform supports it
$sql = $query->getSQL();
if (($fromPart = $query->getQueryPart('from'))
&& ($table = $fromPart[0]['table'] ?? null)
&& ($alias = $fromPart[0]['alias'] ?? null)
) {
$fromClause = sprintf('%s %s', $table, $alias);
if (preg_match('/FROM (.+) WHERE/', (string) $sql, $matches)) {
$fromClause = $matches[1];
$sql = str_replace(
sprintf('FROM %s WHERE', $fromClause),
sprintf('FROM %s WHERE', $this->driverConnection->getDatabasePlatform()->appendLockHint($fromClause, LockMode::PESSIMISTIC_WRITE)),
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],
"require": {
"php": ">=8.1",
"doctrine/dbal": "^2.13|^3.0",
"doctrine/dbal": "^2.13|^3|^4",
"symfony/messenger": "^5.4|^6.0",
"symfony/service-contracts": "^2.5|^3"
},
Expand Down

0 comments on commit 9fec1e5

Please sign in to comment.