Completed
Push — master ( 94b0d2...722970 )
by Andrey
02:01
created

EventTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 67
rs 10
1
<?php
2
3
namespace Tests;
4
5
use Psr\EventManager\EventInterface;
6
use Tests\EventTestSuite;
7
8
final class EventTest extends EventTestSuite
9
{
10
    public function testCanEventObjectCreated()
11
    {
12
        $this->assertNotEmpty($this->event);
13
        $this->assertInstanceOf(EventInterface::class, $this->event);
14
        $this->assertObjectHasAttribute('name', $this->event);
15
        $this->assertObjectHasAttribute('params', $this->event);
16
        $this->assertObjectHasAttribute('target', $this->event);
17
        $this->assertObjectHasAttribute('isPropagationStopped', $this->event);
18
    }
19
20
    public function testSetAndGetEventParam()
21
    {
22
        $oneParam = 10;
23
        $twoParam = 'Hello';
24
        $twoParamEdited = 'World';
25
26
        $params = [
27
            'oneParam' => $oneParam,
28
            'twoParam' => $twoParam
29
        ];
30
31
        $this->event->setParams($params);
32
        
33
        $this->assertSame($this->event->getParams(), $params);
34
        $this->assertSame($this->event->getParam('oneParam'), $oneParam);
35
    }
36
37
    public function testSetAndGetEventTarget()
38
    {
39
        $target = (object) function () {
40
        };
41
42
        $this->event->setTarget($target);
43
        
44
        $this->assertSame($this->event->getTarget(), $target);
45
    }
46
47
    public function testSetAndGetEventPropagation()
48
    {
49
        $flag = true;
50
51
        $this->event->stopPropagation($flag);
52
        
53
        $this->assertTrue($this->event->isPropagationStopped());
54
    }
55
56
    public function testSetAndGetEventName()
57
    {
58
        $newName = "new.event.name";
59
60
        $this->event->setName($newName);
61
        
62
        $this->assertSame($this->event->getName(), $newName);
63
    }
64
65
    public function testSetEventInvalidNameBehavior()
66
    {
67
        $invalidName = "new%name";
68
69
        $this->assertRegExp('/[^(A-z0-9_.)]/', $invalidName);
70
71
        $this->expectException(\InvalidArgumentException::class);
72
        $this->event->setName($invalidName);
73
    }
74
}
75