Skip to content

Commit 489badc

Browse files
committed
Fix the method visibility check
1 parent 34b73c9 commit 489badc

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

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 {

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)