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

testPredefinedHandler()

Size

Total Lines 12
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 12

1 Method

Rating   Name   Duplication   Size   Complexity  
A SimpleRuleHandlerContainerTest.php$0 ➔ validate() 0 3 1
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