Skip to content

Commit

Permalink
Merge pull request #37 from MacPaw/feat/fixDeprecatedDbalPing
Browse files Browse the repository at this point in the history
feat: fix use deprecated dbal connection function ping
  • Loading branch information
Yozhef committed Dec 15, 2021
2 parents dbdd811 + 644bdb9 commit 6ae3139
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/Check/DoctrineCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public function check(): array
}

try {
$entityManager->getConnection()->ping();
$con = $entityManager->getConnection();
$con->executeQuery($con->getDatabasePlatform()->getDummySelectSQL())->free();
} catch (Throwable $e) {
return array_merge($result, [self::CHECK_RESULT_KEY => false]);
}
Expand Down
15 changes: 15 additions & 0 deletions tests/Integration/Mock/AbstractPlatformMock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace SymfonyHealthCheckBundle\Tests\Integration\Mock;

class AbstractPlatformMock
{
public function getDummySelectSQL(): string
{
$expression = func_num_args() > 0 ? func_get_arg(0) : '1';

return sprintf('SELECT %s', $expression);
}
}
9 changes: 7 additions & 2 deletions tests/Integration/Mock/ConnectionMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@

class ConnectionMock
{
public function ping(): bool
public function getDatabasePlatform(): AbstractPlatformMock
{
return true;
return new AbstractPlatformMock();
}

public function executeQuery(): ExecuteQueryMock
{
return new ExecuteQueryMock();
}
}
12 changes: 12 additions & 0 deletions tests/Integration/Mock/ExecuteQueryMock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace SymfonyHealthCheckBundle\Tests\Integration\Mock;

class ExecuteQueryMock
{
public function free(): void
{
}
}
2 changes: 1 addition & 1 deletion tests/Integration/Unit/Check/DoctrineCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function testDoctrineFailPing(): void
->willReturn($connectionMock);

$connectionMock
->method('ping')
->method('getDatabasePlatform')
->with()
->will(self::throwException(new Exception()));

Expand Down

0 comments on commit 6ae3139

Please sign in to comment.