Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions tests/Event/WildcardEmitterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Sabre\Event;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Depends;

class WildcardEmitterTest extends \PHPUnit\Framework\TestCase
Expand All @@ -26,6 +27,46 @@ public function testListeners(): void
self::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<int, array<int, string>>
*/
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(): void
{
$ee = new WildcardEmitter();
Expand Down