|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\Messenger\Bridge\Doctrine\Tests\Transport;
|
13 | 13 |
|
| 14 | +use Doctrine\DBAL\Cache\ArrayResult; |
| 15 | +use Doctrine\DBAL\Cache\ArrayStatement; |
| 16 | +use Doctrine\DBAL\Platforms\PostgreSQLPlatform; |
| 17 | +use Doctrine\DBAL\Query\QueryBuilder; |
| 18 | +use Doctrine\DBAL\Result; |
14 | 19 | use Doctrine\DBAL\Schema\Table;
|
15 | 20 | use PHPUnit\Framework\TestCase;
|
16 | 21 | use Symfony\Component\Messenger\Bridge\Doctrine\Transport\PostgreSqlConnection;
|
@@ -42,6 +47,68 @@ public function testUnserialize()
|
42 | 47 | $connection->__wakeup();
|
43 | 48 | }
|
44 | 49 |
|
| 50 | + public function testListenOnConnection() |
| 51 | + { |
| 52 | + $driverConnection = $this->createMock(\Doctrine\DBAL\Connection::class); |
| 53 | + |
| 54 | + $driverConnection |
| 55 | + ->expects(self::any()) |
| 56 | + ->method('getDatabasePlatform') |
| 57 | + ->willReturn(new PostgreSQLPlatform()); |
| 58 | + |
| 59 | + $driverConnection |
| 60 | + ->expects(self::any()) |
| 61 | + ->method('createQueryBuilder') |
| 62 | + ->willReturn(new QueryBuilder($driverConnection)); |
| 63 | + |
| 64 | + $wrappedConnection = new class() { |
| 65 | + private $notifyCalls = 0; |
| 66 | + |
| 67 | + public function pgsqlGetNotify() |
| 68 | + { |
| 69 | + ++$this->notifyCalls; |
| 70 | + |
| 71 | + return false; |
| 72 | + } |
| 73 | + |
| 74 | + public function countNotifyCalls() |
| 75 | + { |
| 76 | + return $this->notifyCalls; |
| 77 | + } |
| 78 | + }; |
| 79 | + |
| 80 | + // dbal 2.x |
| 81 | + if (interface_exists(Result::class)) { |
| 82 | + $driverConnection |
| 83 | + ->expects(self::exactly(2)) |
| 84 | + ->method('getWrappedConnection') |
| 85 | + ->willReturn($wrappedConnection); |
| 86 | + |
| 87 | + $driverConnection |
| 88 | + ->expects(self::any()) |
| 89 | + ->method('executeQuery') |
| 90 | + ->willReturn(new ArrayStatement([])); |
| 91 | + } else { |
| 92 | + // dbal 3.x |
| 93 | + $driverConnection |
| 94 | + ->expects(self::exactly(2)) |
| 95 | + ->method('getNativeConnection') |
| 96 | + ->willReturn($wrappedConnection); |
| 97 | + |
| 98 | + $driverConnection |
| 99 | + ->expects(self::any()) |
| 100 | + ->method('executeQuery') |
| 101 | + ->willReturn(new Result(new ArrayResult([]), $driverConnection)); |
| 102 | + } |
| 103 | + $connection = new PostgreSqlConnection(['table_name' => 'queue_table'], $driverConnection); |
| 104 | + |
| 105 | + $connection->get(); // first time we have queueEmptiedAt === null, fallback on the parent implementation |
| 106 | + $connection->get(); |
| 107 | + $connection->get(); |
| 108 | + |
| 109 | + $this->assertSame(2, $wrappedConnection->countNotifyCalls()); |
| 110 | + } |
| 111 | + |
45 | 112 | public function testGetExtraSetupSql()
|
46 | 113 | {
|
47 | 114 | $driverConnection = $this->createMock(\Doctrine\DBAL\Connection::class);
|
|
0 commit comments