|
12 | 12 | namespace Symfony\Component\Messenger\Bridge\Doctrine\Tests\Transport;
|
13 | 13 |
|
14 | 14 | use Doctrine\DBAL\Abstraction\Result as AbstractionResult;
|
| 15 | +use Doctrine\DBAL\Configuration; |
15 | 16 | use Doctrine\DBAL\Connection as DBALConnection;
|
16 | 17 | use Doctrine\DBAL\DBALException;
|
17 | 18 | use Doctrine\DBAL\Driver\Result as DriverResult;
|
|
25 | 26 | use Doctrine\DBAL\Schema\AbstractSchemaManager;
|
26 | 27 | use Doctrine\DBAL\Schema\Schema;
|
27 | 28 | use Doctrine\DBAL\Schema\SchemaConfig;
|
| 29 | +use Doctrine\DBAL\Schema\TableDiff; |
28 | 30 | use Doctrine\DBAL\Statement;
|
| 31 | +use Doctrine\DBAL\Types\Types; |
29 | 32 | use PHPUnit\Framework\TestCase;
|
30 | 33 | use Symfony\Component\Messenger\Bridge\Doctrine\Tests\Fixtures\DummyMessage;
|
31 | 34 | use Symfony\Component\Messenger\Bridge\Doctrine\Transport\Connection;
|
@@ -406,6 +409,56 @@ public function providePlatformSql(): iterable
|
406 | 409 | ];
|
407 | 410 | }
|
408 | 411 |
|
| 412 | + /** |
| 413 | + * @dataProvider setupIndicesProvider |
| 414 | + */ |
| 415 | + public function testSetupIndices(string $platformClass, array $expectedIndices) |
| 416 | + { |
| 417 | + $driverConnection = $this->createMock(DBALConnection::class); |
| 418 | + $driverConnection->method('getConfiguration')->willReturn(new Configuration()); |
| 419 | + |
| 420 | + $schemaManager = $this->createMock(AbstractSchemaManager::class); |
| 421 | + $schema = new Schema(); |
| 422 | + $expectedTable = $schema->createTable('messenger_messages'); |
| 423 | + $expectedTable->addColumn('id', Types::BIGINT); |
| 424 | + $expectedTable->setPrimaryKey(['id']); |
| 425 | + // Make sure columns for indices exists so addIndex() will not throw |
| 426 | + foreach (array_unique(array_merge(...$expectedIndices)) as $columnName) { |
| 427 | + $expectedTable->addColumn($columnName, Types::STRING); |
| 428 | + } |
| 429 | + foreach ($expectedIndices as $indexColumns) { |
| 430 | + $expectedTable->addIndex($indexColumns); |
| 431 | + } |
| 432 | + $schemaManager->method('createSchema')->willReturn($schema); |
| 433 | + $driverConnection->method('getSchemaManager')->willReturn($schemaManager); |
| 434 | + |
| 435 | + $platformMock = $this->createMock($platformClass); |
| 436 | + $platformMock |
| 437 | + ->expects(self::once()) |
| 438 | + ->method('getAlterTableSQL') |
| 439 | + ->with(self::callback(static function (TableDiff $tableDiff): bool { |
| 440 | + return 0 === \count($tableDiff->addedIndexes) && 0 === \count($tableDiff->changedIndexes) && 0 === \count($tableDiff->removedIndexes); |
| 441 | + })) |
| 442 | + ->willReturn([]); |
| 443 | + $driverConnection->method('getDatabasePlatform')->willReturn($platformMock); |
| 444 | + |
| 445 | + $connection = new Connection([], $driverConnection); |
| 446 | + $connection->setup(); |
| 447 | + } |
| 448 | + |
| 449 | + public function setupIndicesProvider(): iterable |
| 450 | + { |
| 451 | + yield 'MySQL' => [ |
| 452 | + MySQL57Platform::class, |
| 453 | + [['delivered_at']], |
| 454 | + ]; |
| 455 | + |
| 456 | + yield 'Other platforms' => [ |
| 457 | + AbstractPlatform::class, |
| 458 | + [['queue_name'], ['available_at'], ['delivered_at']], |
| 459 | + ]; |
| 460 | + } |
| 461 | + |
409 | 462 | public function testConfigureSchema()
|
410 | 463 | {
|
411 | 464 | $driverConnection = $this->getDBALConnectionMock();
|
|
0 commit comments