Passed
Push — master ( 8aca81...ddc766 )
by Alexander
01:59
created

CallbackTest_Object::privateMethod()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
rs 10
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