Skip to content

Commit 2496069

Browse files
committed
Fix DBAL 4.x compatibility issue in testShouldReconnect
In DBAL 4.x, Doctrine\DBAL\Exception became an interface instead of a concrete class. The test was trying to instantiate 'new Exception('')' which fails with 'Cannot instantiate interface Doctrine\DBAL\Exception'. Fixed by using ConnectionException mock which implements the Exception interface, preserving the exact same test logic and coverage as the original DBAL 3.x version.
1 parent f9f6c79 commit 2496069

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

tests/Unit/Repository/MySQLRepositoryTest.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Doctrine\DBAL\Connection;
1010
use Doctrine\DBAL\Exception;
11+
use Doctrine\DBAL\Exception\ConnectionException;
1112
use Doctrine\DBAL\Platforms\MySQLPlatform;
1213
use MySQLReplication\Repository\FieldDTOCollection;
1314
use MySQLReplication\Repository\MasterStatusDTO;
@@ -96,13 +97,17 @@ public function testShouldGetMasterStatus(): void
9697
self::assertEquals(MasterStatusDTO::makeFromArray($expected), $this->mySQLRepositoryTest->getMasterStatus());
9798
}
9899

99-
public function testShouldReconnect(): void
100+
public function testShouldReconnect(): void
100101
{
101102
// just to cover private getConnection
103+
$exception = $this->createMock(ConnectionException::class);
104+
102105
$this->connection->method('executeQuery')
103-
->willReturnCallback(static function () {
104-
throw new Exception('');
105-
});
106+
->willThrowException($exception);
107+
108+
$this->connection->method('fetchAssociative')
109+
->willReturn(['Value' => 'NONE']);
110+
106111
$this->mySQLRepositoryTest->isCheckSum();
107112
self::assertTrue(true);
108113
}

0 commit comments

Comments
 (0)