|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of graze/parallel-process. |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright © 2018 Nature Delivered Ltd. <https://www.graze.com> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
* |
|
10
|
|
|
* @license https://github.com/graze/parallel-process/blob/master/LICENSE.md |
|
11
|
|
|
* @link https://github.com/graze/parallel-process |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Graze\ParallelProcess\Test\Unit\Event; |
|
15
|
|
|
|
|
16
|
|
|
use Graze\ParallelProcess\Test\EventDispatcherFake; |
|
17
|
|
|
use Graze\ParallelProcess\Test\TestCase; |
|
18
|
|
|
use Symfony\Component\EventDispatcher\Event; |
|
19
|
|
|
|
|
20
|
|
|
class EventDispatcherTest extends TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
/** @var EventDispatcherFake */ |
|
23
|
|
|
private $dispatcher; |
|
24
|
|
|
|
|
25
|
|
|
public function setUp() |
|
26
|
|
|
{ |
|
27
|
|
|
$this->dispatcher = new EventDispatcherFake(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testValidNameAddListener() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->assertSame( |
|
33
|
|
|
$this->dispatcher, |
|
34
|
|
|
$this->dispatcher->addListener( |
|
35
|
|
|
EventDispatcherFake::EVENT_VALID, |
|
36
|
|
|
function () { |
|
37
|
|
|
} |
|
38
|
|
|
) |
|
39
|
|
|
); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @expectedException \InvalidArgumentException |
|
44
|
|
|
*/ |
|
45
|
|
|
public function testInvalidNameAddListenerThrowsAnException() |
|
46
|
|
|
{ |
|
47
|
|
|
$this->dispatcher->addListener( |
|
48
|
|
|
EventDispatcherFake::EVENT_INVALID, |
|
49
|
|
|
function () { |
|
50
|
|
|
} |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testValidNameDispatch() |
|
55
|
|
|
{ |
|
56
|
|
|
$this->dispatcher->doDispatch(EventDispatcherFake::EVENT_VALID, new Event()); |
|
57
|
|
|
|
|
58
|
|
|
// no exceptions should be thrown |
|
59
|
|
|
$this->assertTrue(true); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @expectedException \InvalidArgumentException |
|
64
|
|
|
*/ |
|
65
|
|
|
public function testInvalidNameDispatchThrowsAnException() |
|
66
|
|
|
{ |
|
67
|
|
|
$this->dispatcher->doDispatch(EventDispatcherFake::EVENT_INVALID, new Event()); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|