-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
ListenerCollectionTest.php
50 lines (40 loc) · 1.54 KB
/
ListenerCollectionTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
declare(strict_types=1);
namespace Yiisoft\EventDispatcher\Tests\Provider;
use InvalidArgumentException;
use Yiisoft\EventDispatcher\Provider\ListenerCollection;
use PHPUnit\Framework\TestCase;
use Yiisoft\EventDispatcher\Tests\Event\Event;
class ListenerCollectionTest extends TestCase
{
public function testAddIsImmutable(): void
{
$listenerCollection = new ListenerCollection();
$newInstance = $listenerCollection->add(static function () {
}, Event::class);
$this->assertNotSame($newInstance, $listenerCollection);
}
public function testAdd(): void
{
$listenerCollection = (new ListenerCollection())
->add(static function (string $var): void {
});
$this->assertCount(1, iterator_to_array($listenerCollection->getForEvents('string')));
}
public function testAddCallableWithoutParameter(): void
{
$listenerCollection = new ListenerCollection();
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Listeners must accept an event object.');
$listenerCollection->add(static function (): void {
});
}
public function testAddCallableWithParameterWithoutTypeHint(): void
{
$listenerCollection = new ListenerCollection();
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Listeners must declare an object type they can accept.');
$listenerCollection->add(static function ($var): void {
});
}
}