Skip to content

Commit 65c7385

Browse files
committed
Fix the method visibility check
1 parent 7ff8cb8 commit 65c7385

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

pkg/dbal/ManagerRegistryConnectionFactory.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Doctrine\Persistence\ManagerRegistry;
99
use Interop\Queue\ConnectionFactory;
1010
use Interop\Queue\Context;
11+
use ReflectionMethod;
1112

1213
class ManagerRegistryConnectionFactory implements ConnectionFactory
1314
{
@@ -61,7 +62,10 @@ private function establishConnection(): Connection
6162
{
6263
/** @var Connection $connection */
6364
$connection = $this->registry->getConnection($this->config['connection_name']);
64-
if (method_exists($connection, 'connect')) {
65+
if (
66+
method_exists($connection, 'connect')
67+
&& (new ReflectionMethod($connection, 'connect'))->isPublic()
68+
) {
6569
// DBAL < 4
6670
$connection->connect();
6771
} else {

pkg/enqueue-bundle/Consumption/Extension/DoctrinePingConnectionExtension.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Doctrine\Persistence\ManagerRegistry;
77
use Enqueue\Consumption\Context\MessageReceived;
88
use Enqueue\Consumption\MessageReceivedExtensionInterface;
9+
use ReflectionMethod;
910

1011
class DoctrinePingConnectionExtension implements MessageReceivedExtensionInterface
1112
{
@@ -36,7 +37,10 @@ public function onMessageReceived(MessageReceived $context): void
3637
);
3738

3839
$connection->close();
39-
if (method_exists($connection, 'connect')) {
40+
if (
41+
method_exists($connection, 'connect')
42+
&& (new ReflectionMethod($connection, 'connect'))->isPublic()
43+
) {
4044
// DBAL < 4
4145
$connection->connect();
4246
} else {

pkg/enqueue-bundle/Tests/Unit/Consumption/Extension/DoctrinePingConnectionExtensionTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Interop\Queue\Processor;
1515
use PHPUnit\Framework\MockObject\MockObject;
1616
use PHPUnit\Framework\TestCase;
17+
use ReflectionMethod;
1718

1819
class DoctrinePingConnectionExtensionTest extends TestCase
1920
{
@@ -41,7 +42,10 @@ public function testShouldNotReconnectIfConnectionIsOK()
4142
->expects($this->never())
4243
->method('close')
4344
;
44-
if (method_exists(Connection::class, 'connect')) {
45+
if (
46+
method_exists(Connection::class, 'connect')
47+
&& (new ReflectionMethod(Connection::class, 'connect'))->isPublic()
48+
) {
4549
// DBAL < 4
4650
$connection->expects($this->never())
4751
->method('connect');
@@ -87,7 +91,10 @@ public function testShouldDoesReconnectIfConnectionFailed()
8791
->expects($this->once())
8892
->method('close')
8993
;
90-
if (method_exists(Connection::class, 'connect')) {
94+
if (
95+
method_exists(Connection::class, 'connect')
96+
&& (new ReflectionMethod(Connection::class, 'connect'))->isPublic()
97+
) {
9198
// DBAL < 4
9299
$connection->expects($this->once())
93100
->method('connect');

0 commit comments

Comments
 (0)