Skip to content

Commit

Permalink
Add traits to implement Command and SDAM subscriber methods
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Sep 18, 2024
1 parent 89fb97a commit 46d63f7
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Monitoring/CommandEvents.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace MongoDB\Monitoring;

use MongoDB\Driver\Monitoring\CommandFailedEvent;
use MongoDB\Driver\Monitoring\CommandStartedEvent;
use MongoDB\Driver\Monitoring\CommandSubscriber;
use MongoDB\Driver\Monitoring\CommandSucceededEvent;

/** @see CommandSubscriber */
trait CommandEvents
{
public function commandFailed(CommandFailedEvent $event): void
{
}

public function commandStarted(CommandStartedEvent $event): void
{
}

public function commandSucceeded(CommandSucceededEvent $event): void
{
}
}
54 changes: 54 additions & 0 deletions src/Monitoring/SDAMEvents.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace MongoDB\Monitoring;

use MongoDB\Driver\Monitoring\SDAMSubscriber;
use MongoDB\Driver\Monitoring\ServerChangedEvent;
use MongoDB\Driver\Monitoring\ServerClosedEvent;
use MongoDB\Driver\Monitoring\ServerHeartbeatFailedEvent;
use MongoDB\Driver\Monitoring\ServerHeartbeatStartedEvent;
use MongoDB\Driver\Monitoring\ServerHeartbeatSucceededEvent;
use MongoDB\Driver\Monitoring\ServerOpeningEvent;
use MongoDB\Driver\Monitoring\TopologyChangedEvent;
use MongoDB\Driver\Monitoring\TopologyClosedEvent;
use MongoDB\Driver\Monitoring\TopologyOpeningEvent;

/** @see SDAMSubscriber */
trait SDAMEvents
{
public function serverChanged(ServerChangedEvent $event): void
{
}

public function serverClosed(ServerClosedEvent $event): void
{
}

public function serverHeartbeatFailed(ServerHeartbeatFailedEvent $event): void
{
}

public function serverHeartbeatStarted(ServerHeartbeatStartedEvent $event): void
{
}

public function serverHeartbeatSucceeded(ServerHeartbeatSucceededEvent $event): void
{
}

public function serverOpening(ServerOpeningEvent $event): void
{
}

public function topologyChanged(TopologyChangedEvent $event): void
{
}

public function topologyClosed(TopologyClosedEvent $event): void
{
}

public function topologyOpening(TopologyOpeningEvent $event): void
{
}
}
42 changes: 42 additions & 0 deletions tests/MonitoringTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace MongoDB\Tests;

use MongoDB\Driver\Monitoring\CommandSubscriber;
use MongoDB\Driver\Monitoring\SDAMSubscriber;
use MongoDB\Driver\Monitoring\Subscriber;
use MongoDB\Monitoring\CommandEvents;
use MongoDB\Monitoring\SDAMEvents;

use function MongoDB\Driver\Monitoring\addSubscriber;
use function MongoDB\Driver\Monitoring\removeSubscriber;

class MonitoringTest extends TestCase
{
/**
* @doesNotPerformAssertions
*
* @dataProvider provideSubscribers
*/
public function testSubscriber(Subscriber $subscriber): void
{
// Fatal error if the trait does not implement all methods required by the interface
addSubscriber($subscriber);
removeSubscriber($subscriber);
}

public static function provideSubscribers(): iterable
{
yield 'Command' => [
new class implements CommandSubscriber {
use CommandEvents;
},
];

yield 'SDAM' => [
new class implements SDAMSubscriber {
use SDAMEvents;
},
];
}
}

0 comments on commit 46d63f7

Please sign in to comment.