Completed
Push — master ( 97e94f...81eace )
by Dmitriy
15s queued 13s
created

ValidatorCollectorTest::checkSummaryData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 11
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Tests\Debug;
6
7
use Yiisoft\Validator\Debug\ValidatorCollector;
8
use Yiisoft\Validator\Result;
9
use Yiisoft\Validator\Rule\Number;
10
use Yiisoft\Yii\Debug\Collector\CollectorInterface;
11
use Yiisoft\Yii\Debug\Tests\Shared\AbstractCollectorTestCase;
12
13
final class ValidatorCollectorTest extends AbstractCollectorTestCase
14
{
15
    /**
16
     * @param CollectorInterface|ValidatorCollector $collector
17
     */
18
    protected function collectTestData(CollectorInterface|ValidatorCollector $collector): void
19
    {
20
        $ruleNumber = new Number(min: 200);
21
22
        $result = new Result();
23
        $result->addError($ruleNumber->getLessThanMinMessage());
24
25
        $collector->collect(123, $result, [$ruleNumber]);
0 ignored issues
show
Bug introduced by
The method collect() 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\Collec...mmaryCollectorInterface. 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

25
        $collector->/** @scrutinizer ignore-call */ 
26
                    collect(123, $result, [$ruleNumber]);
Loading history...
26
27
        $result = new Result();
28
29
        $collector->collect(500, $result, [$ruleNumber]);
30
    }
31
32
    protected function getCollector(): CollectorInterface
33
    {
34
        return new ValidatorCollector();
35
    }
36
37
    protected function checkSummaryData(array $data): void
38
    {
39
        $this->assertArrayHasKey('validator', $data);
40
41
        $this->assertArrayHasKey('total', $data['validator']);
42
        $this->assertArrayHasKey('valid', $data['validator']);
43
        $this->assertArrayHasKey('invalid', $data['validator']);
44
45
        $this->assertEquals(2, $data['validator']['total']);
46
        $this->assertEquals(1, $data['validator']['valid']);
47
        $this->assertEquals(1, $data['validator']['invalid']);
48
    }
49
}
50