RuleTestCase   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 28
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testValidationFailed() 0 9 1
A testValidationPassed() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Tests\Rule\Base;
6
7
use PHPUnit\Framework\TestCase;
8
use Yiisoft\Validator\RuleInterface;
9
use Yiisoft\Validator\Validator;
10
11
abstract class RuleTestCase extends TestCase
12
{
13
    abstract public function dataValidationPassed(): array;
14
15
    /**
16
     * @dataProvider dataValidationPassed
17
     */
18
    public function testValidationPassed(mixed $data, ?array $rules = null): void
19
    {
20
        $result = (new Validator())->validate($data, $rules);
21
22
        $this->assertSame([], $result->getErrorMessagesIndexedByPath());
23
    }
24
25
    abstract public function dataValidationFailed(): array;
26
27
    /**
28
     * @dataProvider dataValidationFailed
29
     */
30
    public function testValidationFailed(
31
        mixed $data,
32
        array|RuleInterface|null $rules,
33
        array $errorMessagesIndexedByPath
34
    ): void {
35
        $result = (new Validator())->validate($data, $rules);
36
37
        $this->assertFalse($result->isValid());
38
        $this->assertSame($errorMessagesIndexedByPath, $result->getErrorMessagesIndexedByPath());
39
    }
40
}
41