Skip to content

Commit 35a6bb3

Browse files
authored
Adapt to last changes in yiisoft/validator (#159)
1 parent 8dc4280 commit 35a6bb3

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

.editorconfig

+4
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,9 @@ trim_trailing_whitespace = true
1313
[*.md]
1414
trim_trailing_whitespace = false
1515

16+
[*.php]
17+
ij_php_space_before_short_closure_left_parenthesis = true
18+
ij_php_space_after_type_cast = true
19+
1620
[*.yml]
1721
indent_size = 2

src/Collector/ValidatorInterfaceProxy.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Yiisoft\Validator\Result;
88
use Yiisoft\Validator\RulesProviderInterface;
9+
use Yiisoft\Validator\ValidationContext;
910
use Yiisoft\Validator\ValidatorInterface;
1011

1112
final class ValidatorInterfaceProxy implements ValidatorInterface
@@ -16,9 +17,12 @@ public function __construct(
1617
) {
1718
}
1819

19-
public function validate(mixed $data, iterable|object|string|null $rules = null): Result
20-
{
21-
$result = $this->validator->validate($data, $rules);
20+
public function validate(
21+
mixed $data,
22+
iterable|object|string|null $rules = null,
23+
?ValidationContext $context = null
24+
): Result {
25+
$result = $this->validator->validate($data, $rules, $context);
2226

2327
if ($rules === null && $data instanceof RulesProviderInterface) {
2428
$rules = (array) $data->getRules();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Yiisoft\Yii\Debug\Tests\Collector;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Yiisoft\Translator\Translator;
9+
use Yiisoft\Validator\Rule\Number;
10+
use Yiisoft\Validator\SimpleRuleHandlerContainer;
11+
use Yiisoft\Validator\Validator;
12+
use Yiisoft\Yii\Debug\Collector\ValidatorCollector;
13+
use Yiisoft\Yii\Debug\Collector\ValidatorInterfaceProxy;
14+
15+
final class ValidatorInterfaceProxyTest extends TestCase
16+
{
17+
public function testBase(): void
18+
{
19+
$validator = new Validator(new SimpleRuleHandlerContainer(), new Translator());
20+
$collector = new ValidatorCollector();
21+
22+
$proxy = new ValidatorInterfaceProxy($validator, $collector);
23+
24+
$collector->startup();
25+
$proxy->validate(1, [new Number(min: 7)]);
26+
27+
$this->assertSame(
28+
['validator' => ['total' => 1, 'valid' => 0, 'invalid' => 1]],
29+
$collector->getIndexData()
30+
);
31+
}
32+
}

0 commit comments

Comments
 (0)