Skip to content

Commit 6ae3139

Browse files
authored
Merge pull request #37 from MacPaw/feat/fixDeprecatedDbalPing
feat: fix use deprecated dbal connection function ping
2 parents dbdd811 + 644bdb9 commit 6ae3139

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

src/Check/DoctrineCheck.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public function check(): array
4242
}
4343

4444
try {
45-
$entityManager->getConnection()->ping();
45+
$con = $entityManager->getConnection();
46+
$con->executeQuery($con->getDatabasePlatform()->getDummySelectSQL())->free();
4647
} catch (Throwable $e) {
4748
return array_merge($result, [self::CHECK_RESULT_KEY => false]);
4849
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SymfonyHealthCheckBundle\Tests\Integration\Mock;
6+
7+
class AbstractPlatformMock
8+
{
9+
public function getDummySelectSQL(): string
10+
{
11+
$expression = func_num_args() > 0 ? func_get_arg(0) : '1';
12+
13+
return sprintf('SELECT %s', $expression);
14+
}
15+
}

tests/Integration/Mock/ConnectionMock.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66

77
class ConnectionMock
88
{
9-
public function ping(): bool
9+
public function getDatabasePlatform(): AbstractPlatformMock
1010
{
11-
return true;
11+
return new AbstractPlatformMock();
12+
}
13+
14+
public function executeQuery(): ExecuteQueryMock
15+
{
16+
return new ExecuteQueryMock();
1217
}
1318
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SymfonyHealthCheckBundle\Tests\Integration\Mock;
6+
7+
class ExecuteQueryMock
8+
{
9+
public function free(): void
10+
{
11+
}
12+
}

tests/Integration/Unit/Check/DoctrineCheckTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function testDoctrineFailPing(): void
104104
->willReturn($connectionMock);
105105

106106
$connectionMock
107-
->method('ping')
107+
->method('getDatabasePlatform')
108108
->with()
109109
->will(self::throwException(new Exception()));
110110

0 commit comments

Comments
 (0)