Passed
Pull Request — master (#461)
by Sergei
03:12
created

SimpleRuleHandlerContainerTest.php$0 ➔ validate()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Tests\RuleHandlerResolver;
6
7
use PHPUnit\Framework\TestCase;
8
use Yiisoft\Validator\Exception\RuleHandlerInterfaceNotImplementedException;
9
use Yiisoft\Validator\Result;
10
use Yiisoft\Validator\RuleHandlerInterface;
11
use Yiisoft\Validator\RuleHandlerResolver\SimpleRuleHandlerContainer;
12
use Yiisoft\Validator\ValidationContext;
13
14
final class SimpleRuleHandlerContainerTest extends TestCase
15
{
16
    public function testInvalidInstance(): void
17
    {
18
        $this->expectException(RuleHandlerInterfaceNotImplementedException::class);
19
        $this->expectExceptionMessage('Expected instance of "Yiisoft\Validator\RuleHandlerInterface". Got "int".');
20
        new SimpleRuleHandlerContainer(['my-rule' => 72]);
21
    }
22
23
    public function testPredefinedHandler(): void
24
    {
25
        $handler = new class () implements RuleHandlerInterface {
26
            public function validate(mixed $value, object $rule, ValidationContext $context): Result
27
            {
28
                return new Result();
29
            }
30
        };
31
32
        $container = new SimpleRuleHandlerContainer(['test-handler' => $handler]);
33
34
        $this->assertSame($handler, $container->resolve('test-handler'));
35
    }
36
}
37