Passed
Pull Request — master (#186)
by Alexander
02:41
created

ValidatorInterfaceProxyTest::testBase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 13
rs 10
cc 1
nc 1
nop 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A ValidatorInterfaceProxyTest::collectTestData() 0 4 1
A ValidatorInterfaceProxyTest::getCollector() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Tests\Collector;
6
7
use Yiisoft\Validator\Error;
8
use Yiisoft\Validator\Result;
9
use Yiisoft\Validator\Rule\Number;
10
use Yiisoft\Yii\Debug\Collector\CollectorInterface;
11
use Yiisoft\Yii\Debug\Collector\ValidatorCollector;
12
13
final class ValidatorInterfaceProxyTest extends AbstractCollectorTestCase
14
{
15
    /**
16
     * @param CollectorInterface|ValidatorCollector $collector
17
     */
18
    protected function collectTestData(CollectorInterface $collector): void
19
    {
20
        $collector->collect(1, (new Result())->addError('Too low', ['arg1' => 'v1']), [new Number(min: 7)]);
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\Collector\QueueCollector. 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

20
        $collector->/** @scrutinizer ignore-call */ 
21
                    collect(1, (new Result())->addError('Too low', ['arg1' => 'v1']), [new Number(min: 7)]);
Loading history...
21
        $collector->collect(10, new Result(), [new Number(min: 7)]);
22
    }
23
24
    protected function getCollector(): CollectorInterface
25
    {
26
        return new ValidatorCollector();
27
    }
28
29
    protected function checkCollectedData(array $data): void
30
    {
31
        parent::checkCollectedData($data);
32
33
        $this->assertEquals(
34
            [
35
                [
36
                    'value' => 1,
37
                    'rules' => [
38
                        new Number(min: 7),
39
                    ],
40
                    'result' => false,
41
                    'errors' => [
42
                        new Error('Too low', ['arg1' => 'v1']),
43
                    ],
44
                ],
45
                [
46
                    'value' => 10,
47
                    'rules' => [
48
                        new Number(min: 7),
49
                    ],
50
                    'result' => true,
51
                    'errors' => [],
52
                ],
53
            ],
54
            $data
55
        );
56
    }
57
58
    protected function checkIndexData(array $data): void
59
    {
60
        parent::checkIndexData($data);
61
62
        $this->assertEquals(
63
            ['total' => 2, 'valid' => 1, 'invalid' => 1],
64
            $data['validator']
65
        );
66
    }
67
}
68