EmittingTraitTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 19
dl 0
loc 32
rs 10
c 1
b 1
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testDispatchReturnsSameEvent() 0 6 1
A testDispatch() 0 21 1
1
<?php
2
3
namespace ByTIC\EventDispatcher\Tests\Dispatcher\Traits;
4
5
use ByTIC\EventDispatcher\Events\EventInterface;
6
use ByTIC\EventDispatcher\Tests\AbstractTest;
7
use ByTIC\EventDispatcher\Tests\Fixtures\Events\Event;
8
use ByTIC\EventDispatcher\Tests\Fixtures\Listeners\SimpleListener;
9
10
/**
11
 * Class EmittingTraitTest
12
 * @package ByTIC\EventDispatcher\Tests\Dispatcher\Traits
13
 */
14
class EmittingTraitTest extends AbstractTest
15
{
16
    public function testDispatch()
17
    {
18
        $dispatcher = $this->newMockDispatcher();
19
        $listener = new SimpleListener();
20
21
        $dispatcher->addListener('preFoo', $listener);
22
        $dispatcher->addListener('postFoo', $listener);
23
24
        $event = Event::named('preFoo');
25
        $dispatcher->dispatch($event, 'preFoo');
26
27
        static::assertTrue($listener->invoked('preFoo'));
28
        static::assertFalse($listener->invoked('postFoo'));
29
30
        static::assertInstanceOf(
31
            Event::class,
32
            $dispatcher->dispatch(Event::named('noevent'))
33
        );
34
        static::assertInstanceOf(
35
            EventInterface::class,
36
            $dispatcher->dispatch(new Event())
37
        );
38
    }
39
40
    public function testDispatchReturnsSameEvent()
41
    {
42
        $this->dispatcher = $this->newMockDispatcher();
0 ignored issues
show
Bug Best Practice introduced by
The property dispatcher does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
43
        $event = new Event();
44
        $return = $this->dispatcher->dispatch($event);
45
        static::assertSame($event, $return);
46
    }
47
48
}
49