Completed
Push — master ( b9492e...31cd44 )
by Alexander
11:15
created

AggregateTest::testProvidesAllListeners()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 34
rs 9.376
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A AggregateTest.php$0 ➔ getListenersForEvent() 0 6 1
A AggregateTest.php$1 ➔ getListenersForEvent() 0 6 1
1
<?php
2
namespace Yiisoft\EventDispatcher\Tests\Provider;
3
4
use PHPUnit\Framework\TestCase;
5
use Psr\EventDispatcher\ListenerProviderInterface;
6
use Yiisoft\EventDispatcher\Provider\Aggregate;
7
use Yiisoft\EventDispatcher\Tests\Event\Event;
8
9
class AggregateTest extends TestCase
10
{
11
    public function testProvidesAllListeners(): void
12
    {
13
        $event = new Event();
14
15
        $provider1 = new class implements ListenerProviderInterface
16
        {
17
            public function getListenersForEvent(object $event): iterable
18
            {
19
                yield function (Event $event) {
20
                    $event->register(1);
21
                };
22
            }
23
        };
24
25
        $provider2 = new class implements ListenerProviderInterface
26
        {
27
            public function getListenersForEvent(object $event): iterable
28
            {
29
                yield function (Event $event) {
30
                    $event->register(2);
31
                };
32
            }
33
        };
34
35
        $aggregate = new Aggregate();
36
37
        $aggregate->attach($provider1);
38
        $aggregate->attach($provider2);
39
40
        foreach ($aggregate->getListenersForEvent($event) as $listener) {
41
            $listener($event);
42
        }
43
        $this->assertEquals([1, 2], $event->registered());
44
    }
45
}
46