DispatcherTest::createEventHandlerMock()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 11
rs 10
1
<?php
2
3
/**
4
 * This file is part of CaptainHook.
5
 *
6
 * (c) Sebastian Feldmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace CaptainHook\App\Event;
13
14
use PHPUnit\Framework\TestCase;
15
use CaptainHook\App\Config\Mockery as ConfigMockery;
16
use CaptainHook\App\Console\IO\Mockery as IOMockery;
17
use CaptainHook\App\Mockery as CHMockery;
18
19
class DispatcherTest extends TestCase
20
{
21
    use ConfigMockery;
22
    use CHMockery;
23
    use IOMockery;
24
25
    public function testSubscribeHandlers(): void
26
    {
27
        $io      = $this->createIOMock();
28
        $config  = $this->createConfigMock();
29
        $repo    = $this->createRepositoryMock();
30
        $handler = $this->createEventHandlerMock();
31
32
        $dispatcher = new Dispatcher($io, $config, $repo);
33
        $dispatcher->subscribeHandlers([
34
            'onHookFailure' => [$handler]
35
        ]);
36
37
        $dispatcher->dispatch('onHookFailure');
38
    }
39
40
    /**
41
     * Creates an event handler mock
42
     *
43
     * @param  bool $executed
44
     * @return \CaptainHook\App\Event\Handler
45
     */
46
    private function createEventHandlerMock(bool $executed = true): Handler
47
    {
48
        $handler = $this->getMockBuilder(Handler::class)
49
                        ->disableOriginalConstructor()
50
                        ->getMock();
51
52
        if ($executed) {
53
            $handler->expects($this->once())->method('handle');
54
        }
55
56
        return $handler;
57
    }
58
}
59