Passed
Push — master ( f7ef7a...65c26d )
by Dmitriy
02:46
created

QueueCollectorTest::checkSummaryData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 12
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Tests\Collector;
6
7
use Yiisoft\Validator\Result;
8
use Yiisoft\Validator\Rule\Number;
9
use Yiisoft\Yii\Debug\Collector\CollectorInterface;
10
use Yiisoft\Yii\Debug\Collector\Queue\QueueCollector;
11
use Yiisoft\Yii\Debug\Tests\Support\DummyQueue;
12
use Yiisoft\Yii\Queue\Enum\JobStatus;
13
use Yiisoft\Yii\Queue\Message\Message;
14
15
final class QueueCollectorTest extends AbstractCollectorTestCase
16
{
17
    private Message $pushMessage;
18
19
    protected function setUp(): void
20
    {
21
        parent::setUp();
22
        $this->pushMessage = new Message('task', ['id' => 500]);
23
    }
24
25
    /**
26
     * @param CollectorInterface|QueueCollector $collector
27
     */
28
    protected function collectTestData(CollectorInterface $collector): void
29
    {
30
        $ruleNumber = new Number(min: 200);
31
        $result = new Result();
32
        $result->addError($ruleNumber->getLessThanMinMessage());
33
34
        $collector->collectStatus('12345', JobStatus::done());
0 ignored issues
show
Bug introduced by
The method collectStatus() does not exist on Yiisoft\Yii\Debug\Collector\CollectorInterface. It seems like you code against a sub-type of Yiisoft\Yii\Debug\Collector\CollectorInterface such as Yiisoft\Yii\Debug\Collector\Queue\QueueCollector. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
        $collector->/** @scrutinizer ignore-call */ 
35
                    collectStatus('12345', JobStatus::done());
Loading history...
35
        $collector->collectPush('chan1', $this->pushMessage);
0 ignored issues
show
Bug introduced by
The method collectPush() does not exist on Yiisoft\Yii\Debug\Collector\CollectorInterface. It seems like you code against a sub-type of Yiisoft\Yii\Debug\Collector\CollectorInterface such as Yiisoft\Yii\Debug\Collector\Queue\QueueCollector. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

35
        $collector->/** @scrutinizer ignore-call */ 
36
                    collectPush('chan1', $this->pushMessage);
Loading history...
36
        $collector->collectPush('chan2', $this->pushMessage);
37
        $collector->collectWorkerProcessing(
0 ignored issues
show
Bug introduced by
The method collectWorkerProcessing() does not exist on Yiisoft\Yii\Debug\Collector\CollectorInterface. It seems like you code against a sub-type of Yiisoft\Yii\Debug\Collector\CollectorInterface such as Yiisoft\Yii\Debug\Collector\Queue\QueueCollector. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
        $collector->/** @scrutinizer ignore-call */ 
38
                    collectWorkerProcessing(
Loading history...
38
            $this->pushMessage,
39
            new DummyQueue('chan1'),
40
        );
41
        $collector->collectWorkerProcessing(
42
            $this->pushMessage,
43
            new DummyQueue('chan1'),
44
        );
45
        $collector->collectWorkerProcessing(
46
            $this->pushMessage,
47
            new DummyQueue('chan2'),
48
        );
49
    }
50
51
    protected function getCollector(): CollectorInterface
52
    {
53
        return new QueueCollector();
54
    }
55
56
    protected function checkCollectedData(array $data): void
57
    {
58
        parent::checkCollectedData($data);
59
        [
60
            'pushes' => $pushes,
61
            'statuses' => $statuses,
62
            'processingMessages' => $processingMessages,
63
        ] = $data;
64
65
        $this->assertEquals([
66
            'chan1' => [
67
                [
68
                    'message' => $this->pushMessage,
69
                    'middlewares' => [],
70
                ],
71
            ],
72
            'chan2' => [
73
                [
74
                    'message' => $this->pushMessage,
75
                    'middlewares' => [],
76
                ],
77
            ],
78
        ], $pushes);
79
        $this->assertEquals([
80
            [
81
                'id' => '12345',
82
                'status' => 'done',
83
            ],
84
        ], $statuses);
85
        $this->assertEquals(
86
            [
87
                'chan1' => [
88
                    $this->pushMessage,
89
                    $this->pushMessage,
90
                ],
91
                'chan2' => [
92
                    $this->pushMessage,
93
                ],
94
            ],
95
            $processingMessages
96
        );
97
    }
98
99
    protected function checkSummaryData(array $data): void
100
    {
101
        parent::checkSummaryData($data);
102
        [
103
            'countPushes' => $countPushes,
104
            'countStatuses' => $countStatuses,
105
            'countProcessingMessages' => $countProcessingMessages,
106
        ] = $data['queue'];
107
108
        $this->assertEquals(2, $countPushes);
109
        $this->assertEquals(1, $countStatuses);
110
        $this->assertEquals(3, $countProcessingMessages);
111
    }
112
}
113