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