Skip to content

Fix falling tests #1211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/dbal/Tests/Functional/DbalConsumerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private function getQuerySize(): int
{
return (int) $this->context->getDbalConnection()
->executeQuery('SELECT count(*) FROM '.$this->context->getTableName())
->fetchColumn(0)
->fetchOne()
;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Doctrine\Persistence\ManagerRegistry;
use Enqueue\Consumption\Context\MessageReceived;
use Enqueue\Consumption\MessageReceivedExtensionInterface;
use ErrorException;
use Throwable;

class DoctrinePingConnectionExtension implements MessageReceivedExtensionInterface
{
Expand All @@ -27,7 +29,7 @@ public function onMessageReceived(MessageReceived $context): void
continue;
}

if ($connection->ping()) {
if ($this->ping($connection)) {
continue;
}

Expand All @@ -43,4 +45,23 @@ public function onMessageReceived(MessageReceived $context): void
);
}
}

private function ping(Connection $connection): bool
{
set_error_handler(static function (int $severity, string $message, string $file, int $line): bool {
throw new ErrorException($message, $severity, $severity, $file, $line);
});

try {
$dummySelectSQL = $connection->getDatabasePlatform()->getDummySelectSQL();

$connection->executeQuery($dummySelectSQL);

return true;
} catch (Throwable $exception) {
return false;
} finally {
restore_error_handler();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Enqueue\Bundle\Tests\Unit\Consumption\Extension;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\Persistence\ManagerRegistry;
use Enqueue\Bundle\Consumption\Extension\DoctrinePingConnectionExtension;
use Enqueue\Consumption\Context\MessageReceived;
Expand All @@ -29,10 +30,17 @@ public function testShouldNotReconnectIfConnectionIsOK()
->method('isConnected')
->willReturn(true)
;

$abstractPlatform = $this->createMock(AbstractPlatform::class);
$abstractPlatform->expects($this->once())
->method('getDummySelectSQL')
->willReturn('dummy')
;

$connection
->expects($this->once())
->method('ping')
->willReturn(true)
->method('getDatabasePlatform')
->willReturn($abstractPlatform)
;
$connection
->expects($this->never())
Expand Down Expand Up @@ -68,10 +76,11 @@ public function testShouldDoesReconnectIfConnectionFailed()
->method('isConnected')
->willReturn(true)
;

$connection
->expects($this->once())
->method('ping')
->willReturn(false)
->method('getDatabasePlatform')
->willThrowException(new \Exception())
;
$connection
->expects($this->once())
Expand Down Expand Up @@ -118,7 +127,7 @@ public function testShouldSkipIfConnectionWasNotOpened()
;
$connection1
->expects($this->never())
->method('ping')
->method('getDatabasePlatform')
;

// 2nd connection was opened in the past
Expand All @@ -128,10 +137,16 @@ public function testShouldSkipIfConnectionWasNotOpened()
->method('isConnected')
->willReturn(true)
;
$abstractPlatform = $this->createMock(AbstractPlatform::class);
$abstractPlatform->expects($this->once())
->method('getDummySelectSQL')
->willReturn('dummy')
;

$connection2
->expects($this->once())
->method('ping')
->willReturn(true)
->method('getDatabasePlatform')
->willReturn($abstractPlatform)
;

$context = $this->createContext();
Expand Down
6 changes: 6 additions & 0 deletions pkg/enqueue-bundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
"source": "https://github.com/php-enqueue/enqueue-dev",
"docs": "https://github.com/php-enqueue/enqueue-dev/blob/master/docs/index.md"
},
"repositories": [
{
"type": "git",
"url": "https://github.com/andrewmy/php-rabbitmq-management-api.git"
}
],
"require-dev": {
"phpunit/phpunit": "^9.5",
"enqueue/stomp": "0.10.x-dev",
Expand Down
2 changes: 1 addition & 1 deletion pkg/job-queue/Tests/Functional/Entity/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Job extends BaseJob
/**
* @var array
*
* @ORM\Column(name="data", type="json_array", nullable=true)
* @ORM\Column(name="data", type="json", nullable=true)
*/
protected $data;

Expand Down
2 changes: 1 addition & 1 deletion pkg/null/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:
with:
composer-options: "--prefer-source"

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