From c87f4add5fd67dfd3c634f49a7b04c0bb5c10b16 Mon Sep 17 00:00:00 2001 From: Phillip Davis Date: Tue, 14 Jul 2026 21:15:48 +0930 Subject: [PATCH 1/2] test: add testListenersOrder This tests the change in #162 that makes sure not to sort listeners that are of equal priority, but to preserve the order in which they were created. Signed-off-by: Phillip Davis --- tests/Event/WildcardEmitterTest.php | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/Event/WildcardEmitterTest.php b/tests/Event/WildcardEmitterTest.php index 145185c..a51dcc8 100644 --- a/tests/Event/WildcardEmitterTest.php +++ b/tests/Event/WildcardEmitterTest.php @@ -4,6 +4,8 @@ namespace Sabre\Event; +use PHPUnit\Framework\Attributes\DataProvider; + class WildcardEmitterTest extends \PHPUnit\Framework\TestCase { public function testInit() @@ -24,6 +26,46 @@ public function testListeners() $this->assertEquals([$callback2, $callback1], $ee->listeners('foo')); } + public function aMethod(int $number): int + { + return $number * 2; + } + + public function bMethod(int $number): int + { + return $number * 4; + } + + /** + * @return array> + */ + public static function listenersOrderDataProvider(): array + { + // Regardless of the alphabetical order of the method names, + // when the event priority is the same, the order of the + // event listeners remains in the order specified and is not + // "accidentally" sorted. + return [ + ['aMethod', 'bMethod'], + ['bMethod', 'aMethod'], + ]; + } + + #[DataProvider('listenersOrderDataProvider')] + public function testListenersOrder(string $methodName1, string $methodName2): void + { + $ee = new WildcardEmitter(); + + $event1 = [$this, $methodName1]; + $event2 = [$this, $methodName2]; + // @phpstan-ignore argument.type + $ee->on('bar', $event1, 200); + // @phpstan-ignore argument.type + $ee->on('bar', $event2, 200); + + self::assertEquals([$event1, $event2], $ee->listeners('bar')); + } + public function testWildcardListeners() { $ee = new WildcardEmitter(); From 54ac5547802746f8b7ba91061ffb3a6309c2d919 Mon Sep 17 00:00:00 2001 From: Phillip Davis Date: Tue, 14 Jul 2026 22:04:24 +0930 Subject: [PATCH 2/2] test: revert back to old dataProvider syntax Signed-off-by: Phillip Davis --- tests/Event/WildcardEmitterTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Event/WildcardEmitterTest.php b/tests/Event/WildcardEmitterTest.php index a51dcc8..0add1a3 100644 --- a/tests/Event/WildcardEmitterTest.php +++ b/tests/Event/WildcardEmitterTest.php @@ -4,8 +4,6 @@ namespace Sabre\Event; -use PHPUnit\Framework\Attributes\DataProvider; - class WildcardEmitterTest extends \PHPUnit\Framework\TestCase { public function testInit() @@ -51,7 +49,9 @@ public static function listenersOrderDataProvider(): array ]; } - #[DataProvider('listenersOrderDataProvider')] + /** + * @dataProvider listenersOrderDataProvider + */ public function testListenersOrder(string $methodName1, string $methodName2): void { $ee = new WildcardEmitter();