mirror of
https://github.com/danog/amp.git
synced 2024-12-03 09:57:51 +01:00
parent
0d1b882707
commit
ee03245281
@ -62,4 +62,12 @@ class Mediator {
|
|||||||
return \count($results);
|
return \count($results);
|
||||||
})());
|
})());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function __debugInfo() {
|
||||||
|
$info = [];
|
||||||
|
foreach ($this->eventSubscriberMap as $eventName => $callbacks) {
|
||||||
|
$info[$eventName] = \count($callbacks);
|
||||||
|
}
|
||||||
|
return $info;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,4 +81,34 @@ class MediatorTest extends TestCase {
|
|||||||
$this->assertTrue($caughtExpected);
|
$this->assertTrue($caughtExpected);
|
||||||
$this->assertSame(2, $invocations);
|
$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"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user