Skip to content

Commit 0b221f1

Browse files
committed
Add "__" to rule IDS
1 parent 78afca9 commit 0b221f1

18 files changed

+91
-91
lines changed

library/Message/StandardFormatter.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function array(Result $result, array $templates, Translator $translator):
104104

105105
$children = [];
106106
foreach ($this->extractDeduplicatedChildren($result) as $child) {
107-
$childKey = $child->path ?? $child->id;
107+
$childKey = $child->path ?? '__' . $child->id;
108108

109109
$children[$childKey] = $this->array(
110110
$child,
@@ -120,7 +120,7 @@ public function array(Result $result, array $templates, Translator $translator):
120120
}
121121

122122
if (count($children) === 0 || $this->isFinalTemplate($result, $selectedTemplates)) {
123-
return [$result->path ?? $result->id => $messages['__root']];
123+
return [$result->path ?? '__' . $result->id => $messages['__root']];
124124
}
125125

126126
if ($result->path !== null) {
@@ -172,7 +172,7 @@ private function getTemplated(Result $result, array $templates): Result
172172
return $result;
173173
}
174174

175-
foreach ([$result->path, $result->name, $result->id, '__root'] as $key) {
175+
foreach ([$result->path, $result->name, '__' . $result->id, '__root'] as $key) {
176176
if (!isset($templates[$key])) {
177177
continue;
178178
}
@@ -194,7 +194,7 @@ private function getTemplated(Result $result, array $templates): Result
194194
*/
195195
private function isFinalTemplate(Result $result, array $templates): bool
196196
{
197-
$keys = [$result->path, $result->name, $result->id];
197+
$keys = [$result->path, $result->name, '__'.$result->id];
198198
foreach ($keys as $key) {
199199
if (isset($templates[$key]) && is_string($templates[$key])) {
200200
return true;
@@ -221,7 +221,7 @@ private function isFinalTemplate(Result $result, array $templates): bool
221221
*/
222222
private function selectTemplates(Result $result, array $templates): array
223223
{
224-
foreach ([$result->path, $result->name, $result->id] as $key) {
224+
foreach ([$result->path, $result->name, '__'.$result->id] as $key) {
225225
if (isset($templates[$key]) && is_array($templates[$key])) {
226226
return $templates[$key];
227227
}

library/Rules/KeyExists.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function getKey(): int|string
3838

3939
public function evaluate(mixed $input): Result
4040
{
41-
return new Result($this->hasKey($input), $input, $this, name: (string) $this->key, id: (string) $this->key);
41+
return new Result($this->hasKey($input), $input, $this, name: (string) $this->key, path: $this->key);
4242
}
4343

4444
private function hasKey(mixed $input): bool

library/Rules/PropertyExists.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct(
3232
public function evaluate(mixed $input): Result
3333
{
3434
if (!is_object($input)) {
35-
return Result::failed($input, $this)->withNameIfMissing($this->propertyName)->withId($this->propertyName);
35+
return Result::failed($input, $this)->withNameIfMissing($this->propertyName)->withPath($this->propertyName);
3636
}
3737

3838
$reflection = new ReflectionObject($input);
@@ -42,7 +42,7 @@ public function evaluate(mixed $input): Result
4242
$input,
4343
$this,
4444
name: $this->propertyName,
45-
id: $this->propertyName
45+
path: $this->propertyName
4646
);
4747
}
4848
}

tests/feature/AssertWithTemplatesTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,26 @@
1111
fn() => v::alwaysInvalid()->setTemplate('My string template in the chain')->assert(1),
1212
'My string template in the chain',
1313
'- My string template in the chain',
14-
['alwaysInvalid' => 'My string template in the chain']
14+
['__alwaysInvalid' => 'My string template in the chain']
1515
));
1616

1717
test('Template as an array in the chain', expectAll(
18-
fn() => v::alwaysInvalid()->setTemplates(['alwaysInvalid' => 'My array template in the chain'])->assert(1),
18+
fn() => v::alwaysInvalid()->setTemplates(['__alwaysInvalid' => 'My array template in the chain'])->assert(1),
1919
'My array template in the chain',
2020
'- My array template in the chain',
21-
['alwaysInvalid' => 'My array template in the chain']
21+
['__alwaysInvalid' => 'My array template in the chain']
2222
));
2323

2424
test('Runtime template as string', expectAll(
2525
fn() => v::alwaysInvalid()->assert(1, 'My runtime template as string'),
2626
'My runtime template as string',
2727
'- My runtime template as string',
28-
['alwaysInvalid' => 'My runtime template as string']
28+
['__alwaysInvalid' => 'My runtime template as string']
2929
));
3030

3131
test('Runtime template as an array', expectAll(
32-
fn() => v::alwaysInvalid()->assert(1, ['alwaysInvalid' => 'My runtime template an array']),
32+
fn() => v::alwaysInvalid()->assert(1, ['__alwaysInvalid' => 'My runtime template an array']),
3333
'My runtime template an array',
3434
'- My runtime template an array',
35-
['alwaysInvalid' => 'My runtime template an array']
35+
['__alwaysInvalid' => 'My runtime template an array']
3636
));

tests/feature/Issues/Issue1289Test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959
'__root' => 'These rules must pass for `["default": 2, "description": [], "children": ["nope"]]`',
6060
'default' => [
6161
'__root' => 'Only one of these rules must pass for default',
62-
'stringType' => 'default must be a string',
63-
'boolType' => 'default must be a boolean',
62+
'__stringType' => 'default must be a string',
63+
'__boolType' => 'default must be a boolean',
6464
],
6565
'description' => 'description must be a string value',
6666
],

tests/feature/Issues/Issue1333Test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
FULL_MESSAGE,
1818
[
1919
'__root' => 'All the required rules must pass for User Email',
20-
'noWhitespace' => 'User Email must not contain whitespaces',
21-
'email' => 'User Email must be a valid email address',
20+
'__noWhitespace' => 'User Email must not contain whitespaces',
21+
'__email' => 'User Email must be a valid email address',
2222
]
2323
));

tests/feature/Issues/Issue1469Test.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ function (): void {
4040
FULL_MESSAGE,
4141
[
4242
'__root' => 'These rules must pass for `["order_items": [["product_title": test(?string $description = null, ?Closure $closure = null): Pest\Support\Hig ... ]`',
43-
'keySet' => [
43+
'__keySet' => [
4444
'__root' => '`["order_items": [["product_title": test(?string $description = null, ?Closure $closure = null): Pest\Support\Hig ... ]` validation failed',
45-
'each' => [
45+
'__each' => [
4646
'__root' => 'Each item in order_items must be valid',
4747
0 => [
4848
'__root' => 'order_items validation failed',
4949
'quantity' => [
5050
'__root' => 'These rules must pass for quantity',
51-
'intVal' => 'quantity must be an integer value',
51+
'__intVal' => 'quantity must be an integer value',
5252
],
5353
],
5454
1 => [

tests/feature/Issues/Issue619Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
fn() => v::instance(stdClass::class)->setTemplate('invalid object')->assert('test'),
1212
'invalid object',
1313
'- invalid object',
14-
['instance' => 'invalid object']
14+
['__instance' => 'invalid object']
1515
));

tests/feature/Issues/Issue739Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
fn() => v::when(v::alwaysInvalid(), v::alwaysValid())->assert('foo'),
1212
'"foo" is invalid',
1313
'- "foo" is invalid',
14-
['alwaysInvalid' => '"foo" is invalid']
14+
['__alwaysInvalid' => '"foo" is invalid']
1515
));

tests/feature/Issues/Issue799Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
FULL_MESSAGE,
2727
[
2828
'__root' => 'All the required rules must pass for 1',
29-
'arrayVal' => '1 must be an array value',
29+
'__arrayVal' => '1 must be an array value',
3030
'scheme' => 'scheme must be present',
3131
]
3232
));

0 commit comments

Comments
 (0)