Passed
Pull Request — master (#72)
by Wilmer
11:03
created

CallbackTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 11
c 3
b 0
f 0
dl 0
loc 19
rs 10
wmc 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Tests\Rule;
6
7
use PHPUnit\Framework\TestCase;
8
use Yiisoft\Validator\Result;
9
use Yiisoft\Validator\Rule\Callback;
10
11
class CallbackTest extends TestCase
12
{
13
    public function testValidate(): void
14
    {
15
        $rule = new Callback(
16
            static function ($value): Result {
17
                $result = new Result();
18
                if ($value !== 42) {
19
                    $result->addError('Value should be 42!');
20
                }
21
                return $result;
22
            }
23
        );
24
25
        $result = $rule->validate(41);
26
27
        $this->assertFalse($result->isValid());
28
        $this->assertCount(1, $result->getErrors());
29
        $this->assertEquals('Value should be 42!', $result->getErrors()[0]);
30
    }
31
}
32