Skip to content

Commit b462665

Browse files
committed
add a test for the listen
1 parent 8a0a4c1 commit b462665

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/PostgreSqlConnectionTest.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111

1212
namespace Symfony\Component\Messenger\Bridge\Doctrine\Tests\Transport;
1313

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;
1419
use Doctrine\DBAL\Schema\Table;
1520
use PHPUnit\Framework\TestCase;
1621
use Symfony\Component\Messenger\Bridge\Doctrine\Transport\PostgreSqlConnection;
@@ -42,6 +47,68 @@ public function testUnserialize()
4247
$connection->__wakeup();
4348
}
4449

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+
45112
public function testGetExtraSetupSql()
46113
{
47114
$driverConnection = $this->createMock(\Doctrine\DBAL\Connection::class);

0 commit comments

Comments
 (0)