Skip to content

Commit

Permalink
Fix wrong interface inheritance in command logger
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Sep 30, 2019
1 parent e95d3e8 commit da62a2a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
4 changes: 2 additions & 2 deletions APM/PSRCommandLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

namespace Doctrine\Bundle\MongoDBBundle\APM;

use Doctrine\ODM\MongoDB\APM\CommandLoggerInterface;
use MongoDB\Driver\Monitoring\CommandFailedEvent;
use MongoDB\Driver\Monitoring\CommandStartedEvent;
use MongoDB\Driver\Monitoring\CommandSubscriber;
use MongoDB\Driver\Monitoring\CommandSucceededEvent;
use Psr\Log\LoggerInterface;
use function json_encode;
use function MongoDB\Driver\Monitoring\addSubscriber;
use function MongoDB\Driver\Monitoring\removeSubscriber;

final class PSRCommandLogger implements CommandSubscriber
final class PSRCommandLogger implements CommandLoggerInterface
{
/** @var bool */
private $registered = false;
Expand Down
58 changes: 34 additions & 24 deletions Tests/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,36 +47,41 @@ public function testLoggerConfig(bool $expected, array $config, bool $debug)

$definition = $this->container->getDefinition('doctrine_mongodb.odm.command_logger');
$this->assertSame($expected, $definition->hasTag('doctrine_mongodb.odm.command_logger'));

$this->container->compile();

// Fetch the command logger registry to make sure the appropriate number of services has been registered
$this->container->get('doctrine_mongodb.odm.command_logger_registry');
}

public function provideLoggerConfigs()
{
$config = ['connections' => ['default' => []]];

return [
[
'Debug mode enabled' => [
// Logging is always enabled in debug mode
true,
[
'expected' => true,
'config' => [
'document_managers' => ['default' => []],
] + $config,
true,
'debug' => true,
],
[
'Debug mode disabled' => [
// Logging is disabled by default when not in debug mode
false,
[
'expected' => false,
'config' => [
'document_managers' => ['default' => []],
] + $config,
false,
'debug' => false,
],
[
'Logging enabled by config' => [
// Logging can be enabled by config
true,
[
'expected' => true,
'config' => [
'document_managers' => ['default' => ['logging' => true]],
] + $config,
false,
'debug' => false,
],
];
}
Expand All @@ -94,36 +99,41 @@ public function testDataCollectorConfig(bool $expected, array $config, bool $deb

$dataCollectorDefinition = $this->container->getDefinition('doctrine_mongodb.odm.data_collector');
$this->assertSame($expected, $dataCollectorDefinition->hasTag('data_collector'));

$this->container->compile();

// Fetch the command logger registry to make sure the appropriate number of services has been registered
$this->container->get('doctrine_mongodb.odm.command_logger_registry');
}

public function provideDataCollectorConfigs()
{
$config = ['connections' => ['default' => []]];

return [
[
'Debug mode enabled' => [
// Profiling is always enabled in debug mode
true,
[
'expected' => true,
'config' => [
'document_managers' => ['default' => []],
] + $config,
true,
'debug' => true,
],
[
'Debug mode disabled' => [
// Profiling is disabled by default when not in debug mode
false,
[
'expected' => false,
'config' => [
'document_managers' => ['default' => []],
] + $config,
false,
'debug' => false,
],
[
'Profiling enabled by config' => [
// Profiling can be enabled by config
true,
[
'expected' => true,
'config' => [
'document_managers' => ['default' => ['profiler' => true]],
] + $config,
false,
'debug' => false,
],
];
}
Expand Down

0 comments on commit da62a2a

Please sign in to comment.