Passed
Pull Request — master (#500)
by Sergei
02:30
created

WhenMissingTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 31
rs 10
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\EmptyCriteria;
6
7
use PHPUnit\Framework\TestCase;
8
use Yiisoft\Validator\EmptyCriteria\WhenMissing;
9
use Yiisoft\Validator\Rule\Number;
10
use Yiisoft\Validator\RuleInterface;
11
use Yiisoft\Validator\Validator;
12
13
final class WhenMissingTest extends TestCase
14
{
15
    public function dataBase(): array
16
    {
17
        return [
18
            [
19
                ['The allowed types are integer, float and string.'],
20
                null,
21
                new Number(skipOnEmpty: new WhenMissing()),
22
            ],
23
            [
24
                [],
25
                [],
26
                ['property' => new Number(skipOnEmpty: new WhenMissing())],
27
            ],
28
            [
29
                ['Value must be a number.'],
30
                '',
31
                new Number(skipOnEmpty: new WhenMissing()),
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