Completed
Push — ezp-30616-follow-up ( 2e0607...b74676 )
by
unknown
35:08 queued 20:12
created

AbstractServiceTest::getEventDispatcher()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Publish\Core\Event\Tests;
8
9
use eZ\Publish\SPI\Repository\Event\AfterEvent;
10
use eZ\Publish\SPI\Repository\Event\BeforeEvent;
11
use PHPUnit\Framework\TestCase;
12
use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher;
13
use Symfony\Component\EventDispatcher\EventDispatcher;
14
use Symfony\Component\Stopwatch\Stopwatch;
15
16
abstract class AbstractServiceTest extends TestCase
17
{
18
    public function getEventDispatcher(string $beforeEventName, string $eventName): TraceableEventDispatcher
19
    {
20
        $eventDispatcher = new EventDispatcher();
21
        $eventDispatcher->addListener($beforeEventName, function (BeforeEvent $event) {});
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
22
        $eventDispatcher->addListener($eventName, function (AfterEvent $event) {});
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
23
24
        return new TraceableEventDispatcher(
25
            $eventDispatcher,
26
            new Stopwatch()
27
        );
28
    }
29
30
    public function getListenersStack(array $listeners): array
31
    {
32
        $stack = [];
33
34
        foreach ($listeners as $listener) {
35
            $stack[] = [$listener['event'], $listener['priority']];
36
        }
37
38
        return $stack;
39
    }
40
}
41