Completed
Push — master ( ff8f52...ed8581 )
by
unknown
12:31 queued 10s
created

providerForUnCachedMethods()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 53

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 53
rs 9.0254
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
declare(strict_types=1);
8
9
namespace eZ\Publish\Core\Persistence\Cache\Tests;
10
11
use eZ\Publish\SPI\Persistence\Notification\CreateStruct;
12
use eZ\Publish\SPI\Persistence\Notification\Handler as SPINotificationHandler;
13
use eZ\Publish\API\Repository\Values\Notification\Notification;
14
use eZ\Publish\SPI\Persistence\Notification\Notification as SPINotification;
15
use eZ\Publish\SPI\Persistence\Notification\UpdateStruct;
16
17
/**
18
 * Test case for Persistence\Cache\NotificationHandler.
19
 */
20
class NotificationHandlerTest extends AbstractCacheHandlerTest
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function getHandlerMethodName(): string
26
    {
27
        return 'notificationHandler';
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function getHandlerClassName(): string
34
    {
35
        return SPINotificationHandler::class;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function providerForUnCachedMethods(): array
42
    {
43
        $ownerId = 7;
44
        $notificationId = 5;
45
        $notification = new Notification([
46
            'id' => $notificationId,
47
            'ownerId' => $ownerId,
48
        ]);
49
50
        // string $method, array $arguments, array? $tags, string? $key, mixed? $returnValue
51
        return [
52
            [
53
                'createNotification',
54
                [
55
                    new CreateStruct(['ownerId' => $ownerId]),
56
                ],
57
                null,
58
                [
59
                    'ez-notification-count-' . $ownerId,
60
                    'ez-notification-pending-count-' . $ownerId,
61
                ],
62
                new SPINotification(),
63
            ],
64
            [
65
                'updateNotification',
66
                [
67
                    $notification,
68
                    new UpdateStruct(['isPending' => false]),
69
                ],
70
                null,
71
                [
72
                    'ez-notification-' . $notificationId,
73
                    'ez-notification-pending-count-' . $ownerId,
74
                ],
75
                new SPINotification(),
76
            ],
77
            [
78
                'delete',
79
                [
80
                    $notification,
81
                ],
82
                null,
83
                [
84
                    'ez-notification-' . $notificationId,
85
                    'ez-notification-count-' . $ownerId,
86
                    'ez-notification-pending-count-' . $ownerId,
87
                ],
88
            ],
89
            [
90
                'loadUserNotifications', [$ownerId, 0, 25], null, null, [],
91
            ],
92
        ];
93
    }
94
95
    /**
96
     * {@inheritdoc}
97
     */
98
    public function providerForCachedLoadMethods(): array
99
    {
100
        $notificationId = 5;
101
        $ownerId = 7;
102
        $notificationCount = 10;
103
        $notificationCountPending = 5;
104
105
        // string $method, array $arguments, string $key, mixed? $data
106
        return [
107
            [
108
                'countPendingNotifications',
109
                [
110
                    $ownerId,
111
                ],
112
                'ez-notification-pending-count-' . $ownerId,
113
                $notificationCount,
114
            ],
115
            [
116
                'countNotifications',
117
                [
118
                    $ownerId,
119
                ],
120
                'ez-notification-count-' . $ownerId,
121
                $notificationCountPending,
122
            ],
123
            [
124
                'getNotificationById',
125
                [
126
                    $notificationId,
127
                ],
128
                'ez-notification-' . $notificationId,
129
                new SPINotification(['id' => $notificationId]),
130
            ],
131
        ];
132
    }
133
}
134