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

EventTest::testSetAndGetEventPropagation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
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