Skip to content

Commit

Permalink
Allow Symfony 5 (#91)
Browse files Browse the repository at this point in the history
* Allow Symfony 5

* Fix signature issue

* Add Travis job to test against SF5

* Fix docker compose config

* Fix argument widening for PHP < 7.4 and Symfony 3.4

* Widen symfony/console dev requirement

* Bump matthiasnoback/symfony-dependency-injection-test

* Fix unit test

* Revert wrong indentation
  • Loading branch information
Jean85 authored Apr 1, 2020
1 parent c545d0a commit 543971a
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 17 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ env:
- PHP_IMG="php-7.2-mongoext-1.3.0-20200327" MONGO_IMG="mongo:3.4" SYMFONY="3.4.*"
- PHP_IMG="php-7.2-mongoext-1.3.0-20200327" MONGO_IMG="mongo:3.4" SYMFONY="4.3.*"
- PHP_IMG="php-7.2-mongoext-1.3.0-20200327" MONGO_IMG="mongo:3.4" SYMFONY="4.4.*"
- PHP_IMG="php-7.2-mongoext-1.3.0-20200327" MONGO_IMG="mongo:3.4" SYMFONY="5.*"
- PHP_IMG="php-7.2-mongoext-1.5.3-20200327" MONGO_IMG="percona/percona-server-mongodb:4.0"
- PHP_IMG="php-7.3-mongoext-1.5.3-20200327" MONGO_IMG="mongo:4.0"
- PHP_IMG="php-7.3-mongoext-1.5.3-20200327" MONGO_IMG="percona/percona-server-mongodb:4.0"
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
"php": "^7.2",
"ext-mongodb": "^1.1.5",
"mongodb/mongodb": "^1.0",
"symfony/framework-bundle": "^3.4 || ^4.3"
"symfony/framework-bundle": "^3.4 || ^4.3 || ^5.0"
},
"require-dev": {
"matthiasnoback/symfony-dependency-injection-test": "^4",
"symfony/web-profiler-bundle": "^3.4 || ^4.3",
"symfony/console": "^3.4 || ^4.3",
"symfony/web-profiler-bundle": "^3.4 || ^4.3 || ^5.0",
"symfony/console": "^3.4 || ^4.3 || ^5.0",
"phpunit/phpunit": "^8.5.2",
"symfony/phpunit-bridge": "^4.2",
"symfony/phpunit-bridge": "^5.0",
"facile-it/facile-coding-standard": "^0.3.1",
"phpstan/phpstan": "^0.12"
},
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.1"

services:
php:
image: ilariopierbattista/mongodb-bundle-php:base-7.2-mongoext-1.3.0
image: ilariopierbattista/mongodb-bundle-php:php-7.2-mongoext-1.3.0-20200327
volumes:
- ./:/home/user-dev/project
tty: true
Expand Down
10 changes: 9 additions & 1 deletion src/DataCollector/MongoDbDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,16 @@ public function setLogger(DataCollectorLoggerInterface $logger)
$this->logger = $logger;
}

public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, $exception = null)
{
if ($exception && ! $exception instanceof \Throwable) {
throw new \InvalidArgumentException(sprintf(
'Argument 3 passed to %s must be an instance of \Throwable or null, %s given',
__METHOD__,
is_object($exception) ? 'instance of ' . get_class($exception) : gettype($exception)
));
}

while ($this->logger->hasLoggedEvents()) {
/** @var Query $event */
$event = $this->logger->getLoggedEvent();
Expand Down
19 changes: 17 additions & 2 deletions tests/Unit/DataCollector/MongoDbDataCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Facile\MongoDbBundle\Tests\unit\DataCollector;
namespace Facile\MongoDbBundle\Tests\Unit\DataCollector;

use Facile\MongoDbBundle\DataCollector\MongoDbDataCollector;
use Facile\MongoDbBundle\Models\Query;
Expand Down Expand Up @@ -37,14 +37,29 @@ public function test_construction_logger()
self::assertEquals(1, $collector->getQueryCount());
self::assertNotEmpty($collector->getQueries());

self::assertTrue(is_float($collector->getTime()));
self::assertIsFloat($collector->getTime());

self::assertNotEmpty($collector->getConnections());
self::assertEquals(1, $collector->getConnectionsCount());

self::assertEquals('mongodb', $collector->getName());
}

public function testCollectWithWrongType(): void
{
$collector = new MongoDbDataCollector();
$collector->setLogger(new MongoQueryLogger());

self::expectException(\InvalidArgumentException::class);
self::expectExceptionMessage('must be an instance of \\Throwable');

$collector->collect(
$this->prophesize(Request::class)->reveal(),
$this->prophesize(Response::class)->reveal(),
new \DateTime()
);
}

public function getUtcDateTime()
{
if (phpversion('mongodb') === '1.2.0-dev') {
Expand Down
31 changes: 22 additions & 9 deletions tests/Unit/Services/ClientRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@

namespace Facile\MongoDbBundle\Tests\Unit\Services;

use Facile\MongoDbBundle\Event\ConnectionEvent;
use Facile\MongoDbBundle\Services\ClientRegistry;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;

class ClientRegistryTest extends TestCase
{
public function test_client_connection_url_provided_manually()
{
$ed = $this->prophesize(EventDispatcherInterface::class);

$registry = new ClientRegistry($ed->reveal(), false, null);
$registry = new ClientRegistry($this->mockEventDispatcher(), false, null);

$testConf = [
'test_client' => [
Expand All @@ -40,9 +41,7 @@ public function test_client_connection_url_provided_manually()

public function test_client_connection_url_generation_singlehost()
{
$ed = $this->prophesize(EventDispatcherInterface::class);

$registry = new ClientRegistry($ed->reveal(), false, null);
$registry = new ClientRegistry($this->mockEventDispatcher(), false, null);

$testConf = [
'test_client' => [
Expand Down Expand Up @@ -70,9 +69,7 @@ public function test_client_connection_url_generation_singlehost()

public function test_client_connection_url_generation_multihost()
{
$ed = $this->prophesize(EventDispatcherInterface::class);

$registry = new ClientRegistry($ed->reveal(), false, null);
$registry = new ClientRegistry($this->mockEventDispatcher(), false, null);

$testConf = [
'test_client' => [
Expand All @@ -96,4 +93,20 @@ public function test_client_connection_url_generation_multihost()

$this->assertEquals('mongodb://host1:8080,host2:8081', $client->__debugInfo()['uri']);
}

private function mockEventDispatcher(): EventDispatcherInterface
{
$ed = $this->prophesize(EventDispatcherInterface::class);

if (class_exists(LegacyEventDispatcherProxy::class)) {
$ed->dispatch(Argument::type(ConnectionEvent::class), ConnectionEvent::CLIENT_CREATED)
->shouldBeCalledOnce()
->willReturnArgument(0);
} else {
$ed->dispatch(ConnectionEvent::CLIENT_CREATED, Argument::type(ConnectionEvent::class))
->shouldBeCalledOnce();
}

return $ed->reveal();
}
}

0 comments on commit 543971a

Please sign in to comment.