1
0
mirror of https://github.com/danog/amp.git synced 2024-12-02 09:27:46 +01:00

Revert "remove __debugInfo()"

This reverts commit 0d1b882707.
This commit is contained in:
Daniel Lowrey 2018-01-07 10:43:26 -05:00
parent 0d1b882707
commit ee03245281
2 changed files with 38 additions and 0 deletions

View File

@ -62,4 +62,12 @@ class Mediator {
return \count($results);
})());
}
public function __debugInfo() {
$info = [];
foreach ($this->eventSubscriberMap as $eventName => $callbacks) {
$info[$eventName] = \count($callbacks);
}
return $info;
}
}

View File

@ -81,4 +81,34 @@ class MediatorTest extends TestCase {
$this->assertTrue($caughtExpected);
$this->assertSame(2, $invocations);
}
public function testSubscriberArrayRemovedWhenEmptyToAvoidLeakage() {
$mediator = new Mediator;
Loop::run(function () use ($mediator) {
$mediator->subscribe("event.foo", static function () {});
$mediator->subscribe("event.foo", static function () { return false; });
$mediator->subscribe("event.bar", static function () {});
$mediator->subscribe("event.baz", static function () { return false; });
yield $mediator->publish("event.foo", 42);
yield $mediator->publish("event.bar", 42);
yield $mediator->publish("event.baz", 42);
});
$debugInfo = $mediator->__debugInfo();
$this->assertSame(1, $debugInfo["event.foo"]);
$this->assertSame(1, $debugInfo["event.bar"]);
$this->assertFalse(isset($debugInfo["event.baz"]));
}
public function testDebugInfoMapsSubscriberCounts() {
$mediator = new Mediator;
$mediator->subscribe("event.foo", static function () {});
$mediator->subscribe("event.foo", static function () {});
$mediator->subscribe("event.bar", static function () {});
$debugInfo = $mediator->__debugInfo();
$this->assertSame(2, $debugInfo["event.foo"]);
$this->assertSame(1, $debugInfo["event.bar"]);
}
}