Skip to content

Commit 0c87bce

Browse files
committed
Rule chain factory method QueryRule::key fixed
1 parent 1a3e0ec commit 0c87bce

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/Model/Server/QueryRule.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ public function key(string $key): StringTypedKey
3333
/** @var Validated<mixed> $validated */
3434
$validated = $this->queryParams;
3535
$ruleChain = new RuleChain();
36+
$valueName = 'Request query parameter: '.$key;
3637
return new StringTypedKey(
3738
$this->exceptionFactory,
3839
$ruleChain,
3940
$validated,
40-
'Request query parameter: '.$key,
41-
new Key($this->exceptionFactory, $ruleChain, $validated, '', '')
41+
$valueName,
42+
new Key($this->exceptionFactory, $ruleChain, $validated, $valueName, $key)
4243
);
4344
}
4445
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
6+
use PHPUnit\Framework\TestCase;
7+
use SimpleAsFuck\ApiToolkit\Model\Server\QueryRule;
8+
use SimpleAsFuck\Validator\Factory\UnexpectedValueException as UnexpectedValueException;
9+
use SimpleAsFuck\Validator\Model\Validated as Validated;
10+
11+
/**
12+
* @covers \SimpleAsFuck\ApiToolkit\Model\Server\QueryRule
13+
*/
14+
final class QueryRuleTest extends TestCase
15+
{
16+
private QueryRule $rule;
17+
18+
public function setUp(): void
19+
{
20+
/** @var array<mixed> $queryData */
21+
$queryData = ['test' => 'someValue'];
22+
23+
$this->rule = new QueryRule(new UnexpectedValueException(), new Validated($queryData));
24+
}
25+
26+
public function testKey(): void
27+
{
28+
$value = $this->rule->key('test')->string()->notNull();
29+
self::assertSame('someValue', $value);
30+
31+
$this->expectExceptionMessage('Request query parameter: testNotExist must be not null');
32+
$this->rule->key('testNotExist')->string()->notNull();
33+
}
34+
}

0 commit comments

Comments
 (0)