Skip to content

Commit 529decd

Browse files
authored
Merge pull request #1211 from snapshotpl/fix-tests
Fix falling tests
2 parents e8a1cfc + f00127c commit 529decd

File tree

6 files changed

+53
-11
lines changed

6 files changed

+53
-11
lines changed

pkg/dbal/Tests/Functional/DbalConsumerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ private function getQuerySize(): int
173173
{
174174
return (int) $this->context->getDbalConnection()
175175
->executeQuery('SELECT count(*) FROM '.$this->context->getTableName())
176-
->fetchColumn(0)
176+
->fetchOne()
177177
;
178178
}
179179
}

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

+22-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use Doctrine\Persistence\ManagerRegistry;
77
use Enqueue\Consumption\Context\MessageReceived;
88
use Enqueue\Consumption\MessageReceivedExtensionInterface;
9+
use ErrorException;
10+
use Throwable;
911

1012
class DoctrinePingConnectionExtension implements MessageReceivedExtensionInterface
1113
{
@@ -27,7 +29,7 @@ public function onMessageReceived(MessageReceived $context): void
2729
continue;
2830
}
2931

30-
if ($connection->ping()) {
32+
if ($this->ping($connection)) {
3133
continue;
3234
}
3335

@@ -43,4 +45,23 @@ public function onMessageReceived(MessageReceived $context): void
4345
);
4446
}
4547
}
48+
49+
private function ping(Connection $connection): bool
50+
{
51+
set_error_handler(static function (int $severity, string $message, string $file, int $line): bool {
52+
throw new ErrorException($message, $severity, $severity, $file, $line);
53+
});
54+
55+
try {
56+
$dummySelectSQL = $connection->getDatabasePlatform()->getDummySelectSQL();
57+
58+
$connection->executeQuery($dummySelectSQL);
59+
60+
return true;
61+
} catch (Throwable $exception) {
62+
return false;
63+
} finally {
64+
restore_error_handler();
65+
}
66+
}
4667
}

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

+22-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Enqueue\Bundle\Tests\Unit\Consumption\Extension;
44

55
use Doctrine\DBAL\Connection;
6+
use Doctrine\DBAL\Platforms\AbstractPlatform;
67
use Doctrine\Persistence\ManagerRegistry;
78
use Enqueue\Bundle\Consumption\Extension\DoctrinePingConnectionExtension;
89
use Enqueue\Consumption\Context\MessageReceived;
@@ -29,10 +30,17 @@ public function testShouldNotReconnectIfConnectionIsOK()
2930
->method('isConnected')
3031
->willReturn(true)
3132
;
33+
34+
$abstractPlatform = $this->createMock(AbstractPlatform::class);
35+
$abstractPlatform->expects($this->once())
36+
->method('getDummySelectSQL')
37+
->willReturn('dummy')
38+
;
39+
3240
$connection
3341
->expects($this->once())
34-
->method('ping')
35-
->willReturn(true)
42+
->method('getDatabasePlatform')
43+
->willReturn($abstractPlatform)
3644
;
3745
$connection
3846
->expects($this->never())
@@ -68,10 +76,11 @@ public function testShouldDoesReconnectIfConnectionFailed()
6876
->method('isConnected')
6977
->willReturn(true)
7078
;
79+
7180
$connection
7281
->expects($this->once())
73-
->method('ping')
74-
->willReturn(false)
82+
->method('getDatabasePlatform')
83+
->willThrowException(new \Exception())
7584
;
7685
$connection
7786
->expects($this->once())
@@ -118,7 +127,7 @@ public function testShouldSkipIfConnectionWasNotOpened()
118127
;
119128
$connection1
120129
->expects($this->never())
121-
->method('ping')
130+
->method('getDatabasePlatform')
122131
;
123132

124133
// 2nd connection was opened in the past
@@ -128,10 +137,16 @@ public function testShouldSkipIfConnectionWasNotOpened()
128137
->method('isConnected')
129138
->willReturn(true)
130139
;
140+
$abstractPlatform = $this->createMock(AbstractPlatform::class);
141+
$abstractPlatform->expects($this->once())
142+
->method('getDummySelectSQL')
143+
->willReturn('dummy')
144+
;
145+
131146
$connection2
132147
->expects($this->once())
133-
->method('ping')
134-
->willReturn(true)
148+
->method('getDatabasePlatform')
149+
->willReturn($abstractPlatform)
135150
;
136151

137152
$context = $this->createContext();

pkg/enqueue-bundle/composer.json

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
"source": "https://github.com/php-enqueue/enqueue-dev",
2121
"docs": "https://github.com/php-enqueue/enqueue-dev/blob/master/docs/index.md"
2222
},
23+
"repositories": [
24+
{
25+
"type": "git",
26+
"url": "https://github.com/andrewmy/php-rabbitmq-management-api.git"
27+
}
28+
],
2329
"require-dev": {
2430
"phpunit/phpunit": "^9.5",
2531
"enqueue/stomp": "0.10.x-dev",

pkg/job-queue/Tests/Functional/Entity/Job.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class Job extends BaseJob
9595
/**
9696
* @var array
9797
*
98-
* @ORM\Column(name="data", type="json_array", nullable=true)
98+
* @ORM\Column(name="data", type="json", nullable=true)
9999
*/
100100
protected $data;
101101

pkg/null/.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ jobs:
2626
with:
2727
composer-options: "--prefer-source"
2828

29-
- run: vendor/bin/phpunit --exlude-group=functional
29+
- run: vendor/bin/phpunit --exclude-group=functional

0 commit comments

Comments
 (0)