Passed
Pull Request — master (#156)
by Wilmer
02:29
created

QueueCollectorTest::collectTestData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 20
rs 9.7666
c 0
b 0
f 0
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\IndexCollectorInterface;
11
use Yiisoft\Yii\Debug\Collector\QueueCollector;
12
use Yiisoft\Yii\Debug\Tests\Support\DummyQueue;
13
use Yiisoft\Yii\Queue\Message\Message;
14
15
final class QueueCollectorTest extends CollectorTestCase
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->getTooSmallMessage());
33
34
        $collector->collectStatus('12345');
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\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');
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\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\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(CollectorInterface $collector): void
57
    {
58
        parent::checkCollectedData($collector);
59
        [
60
            'pushes' => $pushes,
61
            'statuses' => $statuses,
62
            'processingMessages' => $processingMessages,
63
        ] = $collector->getCollected();
64
65
        $this->assertEquals(['chan1' => [$this->pushMessage], 'chan2' => [$this->pushMessage]], $pushes);
66
        $this->assertEquals(['12345'], $statuses);
67
        $this->assertEquals(
68
            [
69
                'chan1' => [$this->pushMessage, $this->pushMessage],
70
                'chan2' => [$this->pushMessage],
71
            ],
72
            $processingMessages
73
        );
74
    }
75
76
    protected function checkIndexData(CollectorInterface|IndexCollectorInterface $collector): void
77
    {
78
        parent::checkIndexData($collector);
79
        [
80
            'countPushes' => $countPushes,
81
            'countStatuses' => $countStatuses,
82
            'countProcessingMessages' => $countProcessingMessages,
83
        ] = $collector->getIndexData()['queue'];
0 ignored issues
show
Bug introduced by
The method getIndexData() does not exist on Yiisoft\Yii\Debug\Collector\CollectorInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Yiisoft\Yii\Debug\Collector\WebViewCollector. Are you sure you never get one of those? ( Ignorable by Annotation )

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

83
        ] = $collector->/** @scrutinizer ignore-call */ getIndexData()['queue'];
Loading history...
84
85
        $this->assertEquals(2, $countPushes);
86
        $this->assertEquals(1, $countStatuses);
87
        $this->assertEquals(3, $countProcessingMessages);
88
    }
89
}
90