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
|
|
|
* @author Alex Patterson <[email protected]>
|
15
|
|
|
* @package ArpTest\EventDispatcher\Event
|
16
|
|
|
*/
|
17
|
|
|
final class NamedEventTest extends TestCase
|
18
|
|
|
{
|
19
|
|
|
/**
|
20
|
|
|
* Assert that the class implements EventNameAwareInterface.
|
21
|
|
|
*
|
22
|
|
|
* @covers \Arp\EventDispatcher\Event\NamedEvent
|
23
|
|
|
*/
|
24
|
|
|
public function testImplementsEventNameAwareInterface(): void
|
25
|
|
|
{
|
26
|
|
|
$namedEvent = new NamedEvent('test');
|
27
|
|
|
|
28
|
|
|
$this->assertInstanceOf(EventNameAwareInterface::class, $namedEvent);
|
29
|
|
|
}
|
30
|
|
|
|
31
|
|
|
/**
|
32
|
|
|
* Assert that getEventName() will return the name of the event.
|
33
|
|
|
*
|
34
|
|
|
* @covers \Arp\EventDispatcher\Event\NamedEvent::getEventName
|
35
|
|
|
*/
|
36
|
|
|
public function testGetEventNameWillReturnEventName(): void
|
37
|
|
|
{
|
38
|
|
|
$namedEvent = new NamedEvent('foo');
|
39
|
|
|
|
40
|
|
|
$this->assertSame('foo', $namedEvent->getEventName());
|
41
|
|
|
}
|
42
|
|
|
|
43
|
|
|
/**
|
44
|
|
|
* Assert that a empty parameters collection is set by default.
|
45
|
|
|
*
|
46
|
|
|
* @covers \Arp\EventDispatcher\Event\AbstractEvent::__construct
|
47
|
|
|
* @covers \Arp\EventDispatcher\Event\NamedEvent::setParameters
|
48
|
|
|
* @covers \Arp\EventDispatcher\Event\NamedEvent::getParameters
|
49
|
|
|
*/
|
50
|
|
|
public function testSetAndGetParameters(): void
|
51
|
|
|
{
|
52
|
|
|
$params = ['foo' => 'bar'];
|
53
|
|
|
|
54
|
|
|
$namedEvent = new NamedEvent('foo', $params);
|
55
|
|
|
|
56
|
|
|
$this->assertSame($params, $namedEvent->getParameters()->getParams());
|
57
|
|
|
|
58
|
|
|
/** @var ParametersInterface|MockObject $parameters */
|
59
|
|
|
$parameters = $this->getMockForAbstractClass(ParametersInterface::class);
|
60
|
|
|
|
61
|
|
|
$namedEvent->setParameters($parameters);
|
62
|
|
|
|
63
|
|
|
$this->assertSame($parameters, $namedEvent->getParameters());
|
64
|
|
|
}
|
65
|
|
|
}
|
66
|
|
|
|