WhenNullTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testBase() 0 5 1
A dataBase() 0 17 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Tests\EmptyCondition;
6
7
use PHPUnit\Framework\TestCase;
8
use Yiisoft\Validator\EmptyCondition\WhenNull;
9
use Yiisoft\Validator\Rule\Number;
10
use Yiisoft\Validator\RuleInterface;
11
use Yiisoft\Validator\Validator;
12
13
final class WhenNullTest extends TestCase
14
{
15
    public function dataBase(): array
16
    {
17
        return [
18
            [
19
                [],
20
                null,
21
                new Number(skipOnEmpty: new WhenNull()),
22
            ],
23
            [
24
                [],
25
                [],
26
                ['property' => new Number(skipOnEmpty: new WhenNull())],
27
            ],
28
            [
29
                ['Value must be a number.'],
30
                '',
31
                new Number(skipOnEmpty: new WhenNull()),
32
            ],
33
        ];
34
    }
35
36
    /**
37
     * @dataProvider dataBase
38
     */
39
    public function testBase(array $expectedMessages, mixed $data, array|RuleInterface|null $rules = null): void
40
    {
41
        $result = (new Validator())->validate($data, $rules);
42
43
        $this->assertSame($expectedMessages, $result->getErrorMessages());
44
    }
45
}
46