|
12 | 12 | namespace Symfony\Component\Messenger\Tests\Transport\Doctrine;
|
13 | 13 |
|
14 | 14 | use Doctrine\DBAL\Abstraction\Result as AbstractionResult;
|
| 15 | +use Doctrine\DBAL\Connection as DBALConnection; |
15 | 16 | use Doctrine\DBAL\DBALException;
|
| 17 | +use Doctrine\DBAL\Driver\Result as DriverResult; |
| 18 | +use Doctrine\DBAL\Driver\ResultStatement; |
16 | 19 | use Doctrine\DBAL\Exception;
|
17 | 20 | use Doctrine\DBAL\Platforms\AbstractPlatform;
|
| 21 | +use Doctrine\DBAL\Platforms\MySQL57Platform; |
| 22 | +use Doctrine\DBAL\Platforms\SQLServer2012Platform; |
18 | 23 | use Doctrine\DBAL\Query\QueryBuilder;
|
19 | 24 | use Doctrine\DBAL\Result;
|
20 | 25 | use Doctrine\DBAL\Schema\AbstractSchemaManager;
|
@@ -117,7 +122,7 @@ public function testItThrowsATransportExceptionIfItCannotRejectMessage()
|
117 | 122 |
|
118 | 123 | private function getDBALConnectionMock()
|
119 | 124 | {
|
120 |
| - $driverConnection = $this->createMock(\Doctrine\DBAL\Connection::class); |
| 125 | + $driverConnection = $this->createMock(DBALConnection::class); |
121 | 126 | $platform = $this->createMock(AbstractPlatform::class);
|
122 | 127 | $platform->method('getWriteLockSQL')->willReturn('FOR UPDATE');
|
123 | 128 | $configuration = $this->createMock(\Doctrine\DBAL\Configuration::class);
|
@@ -345,4 +350,53 @@ public function testFindAll()
|
345 | 350 | $this->assertEquals('{"message":"Hi again"}', $doctrineEnvelopes[1]['body']);
|
346 | 351 | $this->assertEquals(['type' => DummyMessage::class], $doctrineEnvelopes[1]['headers']);
|
347 | 352 | }
|
| 353 | + |
| 354 | + /** |
| 355 | + * @dataProvider providePlatformSql |
| 356 | + */ |
| 357 | + public function testGeneratedSql(AbstractPlatform $platform, string $expectedSql) |
| 358 | + { |
| 359 | + $driverConnection = $this->createMock(DBALConnection::class); |
| 360 | + $driverConnection->method('getDatabasePlatform')->willReturn($platform); |
| 361 | + $driverConnection->method('createQueryBuilder')->willReturnCallback(function () use ($driverConnection) { |
| 362 | + return new QueryBuilder($driverConnection); |
| 363 | + }); |
| 364 | + |
| 365 | + if (interface_exists(DriverResult::class)) { |
| 366 | + $result = $this->createMock(DriverResult::class); |
| 367 | + $result->method('fetchAssociative')->willReturn(false); |
| 368 | + |
| 369 | + if (class_exists(Result::class)) { |
| 370 | + $result = new Result($result, $driverConnection); |
| 371 | + } |
| 372 | + } else { |
| 373 | + $result = $this->createMock(ResultStatement::class); |
| 374 | + $result->method('fetch')->willReturn(false); |
| 375 | + } |
| 376 | + |
| 377 | + $driverConnection->expects($this->once())->method('beginTransaction'); |
| 378 | + $driverConnection |
| 379 | + ->expects($this->once()) |
| 380 | + ->method('executeQuery') |
| 381 | + ->with($expectedSql) |
| 382 | + ->willReturn($result) |
| 383 | + ; |
| 384 | + $driverConnection->expects($this->once())->method('commit'); |
| 385 | + |
| 386 | + $connection = new Connection([], $driverConnection); |
| 387 | + $connection->get(); |
| 388 | + } |
| 389 | + |
| 390 | + public function providePlatformSql(): iterable |
| 391 | + { |
| 392 | + yield 'MySQL' => [ |
| 393 | + new MySQL57Platform(), |
| 394 | + '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', |
| 395 | + ]; |
| 396 | + |
| 397 | + yield 'SQL Server' => [ |
| 398 | + new SQLServer2012Platform(), |
| 399 | + '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 ', |
| 400 | + ]; |
| 401 | + } |
348 | 402 | }
|
0 commit comments