Passed
Push — master ( 71b580...625333 )
by Harry
01:57
created

EventDispatcherTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 14
dl 0
loc 48
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testValidNameAddListener() 0 7 1
A setUp() 0 3 1
A testInvalidNameDispatchThrowsAnException() 0 3 1
A testValidNameDispatch() 0 6 1
A testInvalidNameAddListenerThrowsAnException() 0 5 1
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