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

UserPreferenceServiceTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 59
c 0
b 0
f 0
rs 10
wmc 2
lcom 1
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testSetUserPreferenceEvents() 0 24 1
A testSetUserPreferenceStopPropagationInBeforeEvents() 0 31 1
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\API\Repository\Events\UserPreference\BeforeSetUserPreferenceEvent as BeforeSetUserPreferenceEventInterface;
10
use eZ\Publish\API\Repository\Events\UserPreference\SetUserPreferenceEvent as SetUserPreferenceEventInterface;
11
use eZ\Publish\API\Repository\UserPreferenceService as UserPreferenceServiceInterface;
12
use eZ\Publish\Core\Event\UserPreferenceService;
13
14
class UserPreferenceServiceTest extends AbstractServiceTest
15
{
16
    public function testSetUserPreferenceEvents()
17
    {
18
        $traceableEventDispatcher = $this->getEventDispatcher(
19
            BeforeSetUserPreferenceEventInterface::class,
20
            SetUserPreferenceEventInterface::class
21
        );
22
23
        $parameters = [
24
            [],
25
        ];
26
27
        $innerServiceMock = $this->createMock(UserPreferenceServiceInterface::class);
28
29
        $service = new UserPreferenceService($innerServiceMock, $traceableEventDispatcher);
30
        $service->setUserPreference(...$parameters);
31
32
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
33
34
        $this->assertSame($calledListeners, [
35
            [BeforeSetUserPreferenceEventInterface::class, 0],
36
            [SetUserPreferenceEventInterface::class, 0],
37
        ]);
38
        $this->assertSame([], $traceableEventDispatcher->getNotCalledListeners());
39
    }
40
41
    public function testSetUserPreferenceStopPropagationInBeforeEvents()
42
    {
43
        $traceableEventDispatcher = $this->getEventDispatcher(
44
            BeforeSetUserPreferenceEventInterface::class,
45
            SetUserPreferenceEventInterface::class
46
        );
47
48
        $parameters = [
49
            [],
50
        ];
51
52
        $innerServiceMock = $this->createMock(UserPreferenceServiceInterface::class);
53
54
        $traceableEventDispatcher->addListener(BeforeSetUserPreferenceEventInterface::class, function (BeforeSetUserPreferenceEventInterface $event) {
55
            $event->stopPropagation();
56
        }, 10);
57
58
        $service = new UserPreferenceService($innerServiceMock, $traceableEventDispatcher);
59
        $service->setUserPreference(...$parameters);
60
61
        $calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
62
        $notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());
63
64
        $this->assertSame($calledListeners, [
65
            [BeforeSetUserPreferenceEventInterface::class, 10],
66
        ]);
67
        $this->assertSame($notCalledListeners, [
68
            [BeforeSetUserPreferenceEventInterface::class, 0],
69
            [SetUserPreferenceEventInterface::class, 0],
70
        ]);
71
    }
72
}
73