testGetEventNameWillReturnEventName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ArpTest\EventDispatcher\Event;
6
7
use Arp\EventDispatcher\Event\NamedEvent;
8
use Arp\EventDispatcher\Event\ParametersInterface;
9
use Arp\EventDispatcher\Resolver\EventNameAwareInterface;
10
use PHPUnit\Framework\MockObject\MockObject;
11
use PHPUnit\Framework\TestCase;
12
13
/**
14
 * @covers \Arp\EventDispatcher\Event\NamedEvent
15
 * @covers \Arp\EventDispatcher\Event\AbstractEvent
16
 */
17
final class NamedEventTest extends TestCase
18
{
19
    /**
20
     * Assert that the class implements EventNameAwareInterface
21
     */
22
    public function testImplementsEventNameAwareInterface(): void
23
    {
24
        $namedEvent = new NamedEvent('test');
25
26
        $this->assertInstanceOf(EventNameAwareInterface::class, $namedEvent);
27
    }
28
29
    /**
30
     * Assert that getEventName() will return the name of the event
31
     */
32
    public function testGetEventNameWillReturnEventName(): void
33
    {
34
        $namedEvent = new NamedEvent('foo');
35
36
        $this->assertSame('foo', $namedEvent->getEventName());
37
    }
38
39
    /**
40
     * Assert that a empty parameters collection is set by default
41
     */
42
    public function testSetAndGetParameters(): void
43
    {
44
        $params = ['foo' => 'bar'];
45
46
        $namedEvent = new NamedEvent('foo', $params);
47
48
        $this->assertSame($params, $namedEvent->getParameters()->getParams());
49
50
        /** @var ParametersInterface<mixed>&MockObject $parameters */
51
        $parameters = $this->createMock(ParametersInterface::class);
52
53
        $namedEvent->setParameters($parameters);
54
55
        $this->assertSame($parameters, $namedEvent->getParameters());
56
    }
57
58
    /**
59
     * Assert that parameters can be added and fetched from the event instance
60
     */
61
    public function testGetAndSetParam(): void
62
    {
63
        $event = new NamedEvent('foo');
64
65
        $this->assertNull($event->getParam('foo'));
66
        $this->assertFalse($event->getParam('foo', false));
67
68
        $event->setParam('test', 123);
69
        $event->setParam('hello', true);
70
71
        $this->assertSame(123, $event->getParam('test'));
72
        $this->assertTrue($event->getParam('hello'));
73
    }
74
}
75