diff --git a/library/Message/Placeholder/Quoted.php b/library/Message/Placeholder/Quoted.php index 31781b3c9..381d922f6 100644 --- a/library/Message/Placeholder/Quoted.php +++ b/library/Message/Placeholder/Quoted.php @@ -16,6 +16,11 @@ public function __construct( ) { } + public static function fromPath(int|string $path): self + { + return new self('.' . $path); + } + public function getValue(): string { return $this->value; diff --git a/library/Message/StandardFormatter.php b/library/Message/StandardFormatter.php index d3d9a6b7d..1b4f8270b 100644 --- a/library/Message/StandardFormatter.php +++ b/library/Message/StandardFormatter.php @@ -35,13 +35,19 @@ public function __construct( } /** - * @param array $templates + * @param array $templates */ public function main(Result $result, array $templates, Translator $translator): string { $selectedTemplates = $this->selectTemplates($result, $templates); if (!$this->isFinalTemplate($result, $selectedTemplates)) { foreach ($this->extractDeduplicatedChildren($result) as $child) { + if ($result->path !== null && $child->path !== null) { + $child = $child->withPath(sprintf('%s.%s', $result->path, $child->path)); + } elseif ($result->path !== null && $child->path === null) { + $child = $child->withPath($result->path); + } + return $this->main($child, $selectedTemplates, $translator); } } @@ -50,7 +56,7 @@ public function main(Result $result, array $templates, Translator $translator): } /** - * @param array $templates + * @param array $templates */ public function full( Result $result, @@ -91,9 +97,9 @@ public function full( } /** - * @param array $templates + * @param array $templates * - * @return array + * @return array */ public function array(Result $result, array $templates, Translator $translator): array { @@ -101,22 +107,26 @@ public function array(Result $result, array $templates, Translator $translator): $deduplicatedChildren = $this->extractDeduplicatedChildren($result); if (count($deduplicatedChildren) === 0 || $this->isFinalTemplate($result, $selectedTemplates)) { return [ - $result->id => $this->renderer->render($this->getTemplated($result, $selectedTemplates), $translator), + $result->path ?? $result->id => $this->renderer->render( + $this->getTemplated($result, $selectedTemplates), + $translator + ), ]; } $messages = []; foreach ($deduplicatedChildren as $child) { - $messages[$child->id] = $this->array( + $key = $child->path ?? $child->id; + $messages[$key] = $this->array( $child, $this->selectTemplates($child, $selectedTemplates), $translator ); - if (count($messages[$child->id]) !== 1) { + if (count($messages[$key]) !== 1) { continue; } - $messages[$child->id] = current($messages[$child->id]); + $messages[$key] = current($messages[$key]); } if (count($messages) > 1) { @@ -165,56 +175,66 @@ private function isAlwaysVisible(Result $result, Result ...$siblings): bool ); } - /** @param array $templates */ + /** @param array $templates */ private function getTemplated(Result $result, array $templates): Result { if ($result->hasCustomTemplate()) { return $result; } - if (!isset($templates[$result->id]) && isset($templates['__root__'])) { - return $result->withTemplate($templates['__root__']); - } + foreach ([$result->path, $result->name, $result->id, '__root__'] as $key) { + if (!isset($templates[$key])) { + continue; + } - if (!isset($templates[$result->id])) { - return $result; - } + if (is_string($templates[$key])) { + return $result->withTemplate($templates[$key]); + } - $template = $templates[$result->id]; - if (is_string($template)) { - return $result->withTemplate($template); + throw new ComponentException( + sprintf('Template for "%s" must be a string, %s given', $key, stringify($templates[$key])) + ); } - throw new ComponentException( - sprintf('Template for "%s" must be a string, %s given', $result->id, stringify($template)) - ); + return $result; } /** - * @param array $templates + * @param array $templates */ private function isFinalTemplate(Result $result, array $templates): bool { - if (isset($templates[$result->id]) && is_string($templates[$result->id])) { - return true; + $keys = [$result->path, $result->name, $result->id]; + foreach ($keys as $key) { + if (isset($templates[$key]) && is_string($templates[$key])) { + return true; + } } if (count($templates) !== 1) { return false; } - return isset($templates['__root__']) || isset($templates[$result->id]); + foreach ($keys as $key) { + if (isset($templates[$key])) { + return true; + } + } + + return isset($templates['__root__']); } /** - * @param array $templates + * @param array $templates * - * @return array + * @return array */ - private function selectTemplates(Result $message, array $templates): array + private function selectTemplates(Result $result, array $templates): array { - if (isset($templates[$message->id]) && is_array($templates[$message->id])) { - return $templates[$message->id]; + foreach ([$result->path, $result->name, $result->id] as $key) { + if (isset($templates[$key]) && is_array($templates[$key])) { + return $templates[$key]; + } } return $templates; @@ -227,16 +247,16 @@ private function extractDeduplicatedChildren(Result $result): array $deduplicatedResults = []; $duplicateCounters = []; foreach ($result->children as $child) { - $id = $child->id; + $id = $child->path ?? $child->id; if (isset($duplicateCounters[$id])) { $id .= '.' . ++$duplicateCounters[$id]; } elseif (array_key_exists($id, $deduplicatedResults)) { - $deduplicatedResults[$id . '.1'] = $deduplicatedResults[$id]?->withId($id . '.1'); + $deduplicatedResults[$id . '.1'] = $child->path ? $deduplicatedResults[$id]?->withPath($id . '.1') : $deduplicatedResults[$id]?->withId($id . '.1'); unset($deduplicatedResults[$id]); $duplicateCounters[$id] = 2; $id .= '.2'; } - $deduplicatedResults[$id] = $child->isValid ? null : $child->withId($id); + $deduplicatedResults[$id] = $child->isValid ? null : ($child->path ? $child->withPath((string) $id) : $child->withId((string) $id)); } return array_values(array_filter($deduplicatedResults)); diff --git a/library/Message/StandardRenderer.php b/library/Message/StandardRenderer.php index 9251fa384..b08def893 100644 --- a/library/Message/StandardRenderer.php +++ b/library/Message/StandardRenderer.php @@ -35,7 +35,7 @@ public function __construct( public function render(Result $result, Translator $translator, ?string $template = null): string { $parameters = $result->parameters; - $parameters['name'] ??= $result->name ?? $this->placeholder('input', $result->input, $translator); + $parameters['name'] ??= $result->name ?? ($result->path !== null ? Quoted::fromPath($result->path) : null) ?? $this->placeholder('input', $result->input, $translator); $parameters['input'] = $result->input; $rendered = (string) preg_replace_callback( diff --git a/library/Result.php b/library/Result.php index 4a78edba7..f54890ec7 100644 --- a/library/Result.php +++ b/library/Result.php @@ -39,7 +39,7 @@ public function __construct( public readonly ?string $name = null, ?string $id = null, public readonly ?Result $adjacent = null, - public readonly bool $unchangeableId = false, + public readonly string|int|null $path = null, Result ...$children, ) { $this->id = $id ?? lcfirst(substr((string) strrchr($rule::class, '\\'), 1)); @@ -102,10 +102,6 @@ public function withExtraParameters(array $parameters): self public function withId(string $id): self { - if ($this->unchangeableId) { - return $this; - } - return $this->clone(id: $id); } @@ -114,14 +110,14 @@ public function withIdFrom(Rule $rule): self return $this->clone(id: lcfirst(substr((string) strrchr($rule::class, '\\'), 1))); } - public function withUnchangeableId(string $id): self + public function withPath(string|int $path): self { - return $this->clone(id: $id, unchangeableId: true); + return $this->clone(adjacent: $this->adjacent?->withPath($path), path: $path); } public function withPrefix(string $prefix): self { - if ($this->id === $this->name || $this->unchangeableId) { + if ($this->id === $this->name || $this->path !== null) { return $this; } @@ -136,10 +132,10 @@ public function withChildren(Result ...$children): self public function withName(string $name): self { return $this->clone( - name: $this->rule instanceof Renameable ? $name : ($this->name ?? $name), + name: $this->name ?? $name, adjacent: $this->adjacent?->withName($name), children: array_map( - static fn (Result $child) => $child->withName($child->name ?? $name), + static fn (Result $child) => $child->path === null ? $child->withName($child->name ?? $name) : $child, $this->children ), ); @@ -223,7 +219,7 @@ private function clone( ?string $name = null, ?string $id = null, ?Result $adjacent = null, - ?bool $unchangeableId = null, + string|int|null $path = null, ?array $children = null ): self { return new self( @@ -236,7 +232,7 @@ private function clone( $name ?? $this->name, $id ?? $this->id, $adjacent ?? $this->adjacent, - $unchangeableId ?? $this->unchangeableId, + $path ?? $this->path, ...($children ?? $this->children) ); } diff --git a/library/Rules/Core/Renameable.php b/library/Rules/Core/Renameable.php deleted file mode 100644 index a8c60ac2e..000000000 --- a/library/Rules/Core/Renameable.php +++ /dev/null @@ -1,14 +0,0 @@ - - * SPDX-License-Identifier: MIT - */ - -declare(strict_types=1); - -namespace Respect\Validation\Rules\Core; - -interface Renameable -{ -} diff --git a/library/Rules/Each.php b/library/Rules/Each.php index ee1dad562..6ccb2f234 100644 --- a/library/Rules/Each.php +++ b/library/Rules/Each.php @@ -28,7 +28,7 @@ protected function evaluateNonEmptyArray(array $input): Result { $children = []; foreach ($input as $key => $value) { - $children[] = $this->rule->evaluate($value)->withUnchangeableId((string) $key); + $children[] = $this->rule->evaluate($value)->withPath($key); } $isValid = array_reduce($children, static fn ($carry, $childResult) => $carry && $childResult->isValid, true); diff --git a/library/Rules/Key.php b/library/Rules/Key.php index bebe073c4..2fe90fe76 100644 --- a/library/Rules/Key.php +++ b/library/Rules/Key.php @@ -13,7 +13,6 @@ use Respect\Validation\Result; use Respect\Validation\Rule; use Respect\Validation\Rules\Core\KeyRelated; -use Respect\Validation\Rules\Core\Nameable; use Respect\Validation\Rules\Core\Wrapper; #[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)] @@ -35,21 +34,9 @@ public function evaluate(mixed $input): Result { $keyExistsResult = (new KeyExists($this->key))->evaluate($input); if (!$keyExistsResult->isValid) { - return $keyExistsResult->withName($this->getName()); + return $keyExistsResult->withNameFrom($this->rule); } - return $this->rule - ->evaluate($input[$this->key]) - ->withName($this->getName()) - ->withUnchangeableId((string) $this->key); - } - - private function getName(): string - { - if ($this->rule instanceof Nameable) { - return $this->rule->getName() ?? ((string) $this->key); - } - - return (string) $this->key; + return $this->rule->evaluate($input[$this->key])->withPath($this->key); } } diff --git a/library/Rules/KeyExists.php b/library/Rules/KeyExists.php index 3d79e3876..6c8f6509e 100644 --- a/library/Rules/KeyExists.php +++ b/library/Rules/KeyExists.php @@ -25,7 +25,7 @@ '{{name}} must be present', '{{name}} must not be present', )] -final class KeyExists extends Standard implements KeyRelated, Renameable +final class KeyExists extends Standard implements KeyRelated { public function __construct( private readonly int|string $key @@ -39,7 +39,7 @@ public function getKey(): int|string public function evaluate(mixed $input): Result { - return new Result($this->hasKey($input), $input, $this, name: (string) $this->key, id: (string) $this->key); + return new Result($this->hasKey($input), $input, $this, path: $this->key); } private function hasKey(mixed $input): bool diff --git a/library/Rules/Property.php b/library/Rules/Property.php index 0eaac24b4..365413b61 100644 --- a/library/Rules/Property.php +++ b/library/Rules/Property.php @@ -13,7 +13,6 @@ use ReflectionObject; use Respect\Validation\Result; use Respect\Validation\Rule; -use Respect\Validation\Rules\Core\Nameable; use Respect\Validation\Rules\Core\Wrapper; #[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)] @@ -30,22 +29,12 @@ public function evaluate(mixed $input): Result { $propertyExistsResult = (new PropertyExists($this->propertyName))->evaluate($input); if (!$propertyExistsResult->isValid) { - return $propertyExistsResult->withName($this->getName()); + return $propertyExistsResult->withNameFrom($this->rule); } return $this->rule ->evaluate($this->extractPropertyValue($input, $this->propertyName)) - ->withName($this->getName()) - ->withUnchangeableId($this->propertyName); - } - - private function getName(): string - { - if ($this->rule instanceof Nameable) { - return $this->rule->getName() ?? $this->propertyName; - } - - return $this->propertyName; + ->withPath($this->propertyName); } private function extractPropertyValue(object $input, string $property): mixed diff --git a/library/Rules/PropertyExists.php b/library/Rules/PropertyExists.php index 3a8a66c61..d7ecc1d55 100644 --- a/library/Rules/PropertyExists.php +++ b/library/Rules/PropertyExists.php @@ -23,7 +23,7 @@ '{{name}} must be present', '{{name}} must not be present', )] -final class PropertyExists extends Standard implements Renameable +final class PropertyExists extends Standard { public function __construct( private readonly string $propertyName @@ -36,8 +36,7 @@ public function evaluate(mixed $input): Result $this->hasProperty($input), $input, $this, - name: $this->propertyName, - id: $this->propertyName + path: $this->propertyName, ); } diff --git a/library/Transformers/DeprecatedKeyValue.php b/library/Transformers/DeprecatedKeyValue.php index acca88599..61d8ef1ff 100644 --- a/library/Transformers/DeprecatedKeyValue.php +++ b/library/Transformers/DeprecatedKeyValue.php @@ -9,6 +9,7 @@ namespace Respect\Validation\Transformers; +use Respect\Validation\Message\Placeholder\Quoted; use Respect\Validation\Rules\AlwaysInvalid; use Respect\Validation\Rules\Key; use Respect\Validation\Rules\KeyExists; @@ -52,8 +53,8 @@ static function ($input) use ($comparedKey, $ruleName, $baseKey) { } catch (Throwable) { return new Templated( new AlwaysInvalid(), - '{{baseKey|raw}} must be valid to validate {{comparedKey|raw}}', - ['comparedKey' => $comparedKey, 'baseKey' => $baseKey] + '{{baseKey}} must be valid to validate {{comparedKey}}', + ['comparedKey' => Quoted::fromPath($comparedKey), 'baseKey' => Quoted::fromPath($baseKey)] ); } } diff --git a/tests/feature/AssertWithKeysTest.php b/tests/feature/AssertWithKeysTest.php index e1705c7a2..338a75993 100644 --- a/tests/feature/AssertWithKeysTest.php +++ b/tests/feature/AssertWithKeysTest.php @@ -38,15 +38,15 @@ ]), <<<'FULL_MESSAGE' - All the required rules must pass for the given data - - All the required rules must pass for mysql - - host must be a string - - user must be present - - password must be present - - schema must be a string - - All the required rules must pass for postgresql - - host must be present - - user must be a string - - password must be a string - - schema must be present + - All the required rules must pass for `.mysql` + - `.host` must be a string + - `.user` must be present + - `.password` must be present + - `.schema` must be a string + - All the required rules must pass for `.postgresql` + - `.host` must be present + - `.user` must be a string + - `.password` must be a string + - `.schema` must be present FULL_MESSAGE, )); diff --git a/tests/feature/AssertWithPropertiesTest.php b/tests/feature/AssertWithPropertiesTest.php index 8e953d626..75f64e7fd 100644 --- a/tests/feature/AssertWithPropertiesTest.php +++ b/tests/feature/AssertWithPropertiesTest.php @@ -46,9 +46,9 @@ function (): void { }, <<<'FULL_MESSAGE' - All the required rules must pass for the given data - - These rules must pass for mysql - - host must be a string - - These rules must pass for postgresql - - user must be a string + - These rules must pass for `.mysql` + - `.host` must be a string + - These rules must pass for `.postgresql` + - `.user` must be a string FULL_MESSAGE, )); diff --git a/tests/feature/GetMessagesShouldIncludeAllValidationMessagesInAChainTest.php b/tests/feature/GetMessagesShouldIncludeAllValidationMessagesInAChainTest.php index e391be986..f435bc172 100644 --- a/tests/feature/GetMessagesShouldIncludeAllValidationMessagesInAChainTest.php +++ b/tests/feature/GetMessagesShouldIncludeAllValidationMessagesInAChainTest.php @@ -21,9 +21,9 @@ function (): void { }, [ '__root__' => 'All the required rules must pass for `["username": "u", "birthdate": "Not a date", "password": ""]`', - 'username' => 'The length of username must be between 2 and 32', - 'birthdate' => 'birthdate must be a valid date/time', - 'password' => 'password must not be empty', - 'email' => 'email must be present', + 'username' => 'The length of `.username` must be between 2 and 32', + 'birthdate' => '`.birthdate` must be a valid date/time', + 'password' => '`.password` must not be empty', + 'email' => '`.email` must be present', ], )); diff --git a/tests/feature/GetMessagesTest.php b/tests/feature/GetMessagesTest.php index a18315667..c7abd66ca 100644 --- a/tests/feature/GetMessagesTest.php +++ b/tests/feature/GetMessagesTest.php @@ -22,18 +22,18 @@ [ '__root__' => 'All the required rules must pass for `["mysql": ["host": 42, "schema": 42], "postgresql": ["user": 42, "password": 42]]`', 'mysql' => [ - '__root__' => 'All the required rules must pass for mysql', - 'host' => 'host must be a string', - 'user' => 'user must be present', - 'password' => 'password must be present', - 'schema' => 'schema must be a string', + '__root__' => 'All the required rules must pass for `.mysql`', + 'host' => '`.host` must be a string', + 'user' => '`.user` must be present', + 'password' => '`.password` must be present', + 'schema' => '`.schema` must be a string', ], 'postgresql' => [ - '__root__' => 'All the required rules must pass for postgresql', - 'host' => 'host must be present', - 'user' => 'user must be a string', - 'password' => 'password must be a string', - 'schema' => 'schema must be present', + '__root__' => 'All the required rules must pass for `.postgresql`', + 'host' => '`.host` must be present', + 'user' => '`.user` must be a string', + 'password' => '`.password` must be a string', + 'schema' => '`.schema` must be present', ], ], )); diff --git a/tests/feature/GetMessagesWithReplacementsTest.php b/tests/feature/GetMessagesWithReplacementsTest.php index c44d8ce5b..6ccfbbf66 100644 --- a/tests/feature/GetMessagesWithReplacementsTest.php +++ b/tests/feature/GetMessagesWithReplacementsTest.php @@ -51,17 +51,17 @@ function (): void { [ '__root__' => 'All the required rules must pass for `["mysql": ["host": 42, "schema": 42], "postgresql": ["user": 42, "password": 42]]`', 'mysql' => [ - '__root__' => 'All the required rules must pass for mysql', - 'host' => '`host` should be a MySQL host', + '__root__' => 'All the required rules must pass for `.mysql`', + 'host' => '``.host`` should be a MySQL host', 'user' => 'Value should be a MySQL username', - 'password' => 'password must be present', - 'schema' => 'schema must be a string', + 'password' => '`.password` must be present', + 'schema' => '`.schema` must be a string', ], 'postgresql' => [ - '__root__' => 'All the required rules must pass for postgresql', - 'host' => 'host must be present', - 'user' => 'user must be a string', - 'password' => 'password must be a string', + '__root__' => 'All the required rules must pass for `.postgresql`', + 'host' => '`.host` must be present', + 'user' => '`.user` must be a string', + 'password' => '`.password` must be a string', 'schema' => 'You must provide a valid PostgreSQL schema', ], ], diff --git a/tests/feature/Issues/Issue1033Test.php b/tests/feature/Issues/Issue1033Test.php index 3eecc2732..ac9982d54 100644 --- a/tests/feature/Issues/Issue1033Test.php +++ b/tests/feature/Issues/Issue1033Test.php @@ -9,17 +9,17 @@ test('https://github.com/Respect/Validation/issues/1033', expectAll( fn() => v::each(v::equals(1))->assert(['A', 'B', 'B']), - '"A" must be equal to 1', + '`.0` must be equal to 1', <<<'FULL_MESSAGE' - Each item in `["A", "B", "B"]` must be valid - - "A" must be equal to 1 - - "B" must be equal to 1 - - "B" must be equal to 1 + - `.0` must be equal to 1 + - `.1` must be equal to 1 + - `.2` must be equal to 1 FULL_MESSAGE, [ '__root__' => 'Each item in `["A", "B", "B"]` must be valid', - 0 => '"A" must be equal to 1', - 1 => '"B" must be equal to 1', - 2 => '"B" must be equal to 1', + 0 => '`.0` must be equal to 1', + 1 => '`.1` must be equal to 1', + 2 => '`.2` must be equal to 1', ], )); diff --git a/tests/feature/Issues/Issue1289Test.php b/tests/feature/Issues/Issue1289Test.php index ad8e9aae4..ff7b56470 100644 --- a/tests/feature/Issues/Issue1289Test.php +++ b/tests/feature/Issues/Issue1289Test.php @@ -45,23 +45,23 @@ 'children' => ['nope'], ], ]), - 'default must be a string', + '`.0.default` must be a string', <<<'FULL_MESSAGE' - - These rules must pass for `["default": 2, "description": [], "children": ["nope"]]` - - Only one of these rules must pass for default - - default must be a string - - default must be a boolean - - description must be a string value + - These rules must pass for `.0` + - Only one of these rules must pass for `.default` + - `.default` must be a string + - `.default` must be a boolean + - `.description` must be a string value FULL_MESSAGE, [ 0 => [ '__root__' => 'These rules must pass for `["default": 2, "description": [], "children": ["nope"]]`', 'default' => [ '__root__' => 'Only one of these rules must pass for default', - 'stringType' => 'default must be a string', - 'boolType' => 'default must be a boolean', + 'stringType' => '`.default` must be a string', + 'boolType' => '`.default` must be a boolean', ], - 'description' => 'description must be a string value', + 'description' => '`.description` must be a string value', ], ], )); diff --git a/tests/feature/Issues/Issue1334Test.php b/tests/feature/Issues/Issue1334Test.php index a37e4e3eb..b2ee4df1a 100644 --- a/tests/feature/Issues/Issue1334Test.php +++ b/tests/feature/Issues/Issue1334Test.php @@ -22,28 +22,28 @@ function (): void { ], ); }, - 'street must be present', + '`.0.street` must be present', <<<'FULL_MESSAGE' - Each item in `[["region": "Oregon", "country": "USA", "other": 123], ["street": "", "region": "Oregon", "country": "USA"], ["s ... ]` must be valid - - These rules must pass for `["region": "Oregon", "country": "USA", "other": 123]` - - street must be present - - These rules must pass for other - - other must be a string or must be null - - These rules must pass for `["street": "", "region": "Oregon", "country": "USA"]` - - street must not be empty - - These rules must pass for `["street": 123, "region": "Oregon", "country": "USA"]` - - street must be a string + - These rules must pass for `.0` + - `.street` must be present + - These rules must pass for `.other` + - `.other` must be a string or must be null + - These rules must pass for `.1` + - `.street` must not be empty + - These rules must pass for `.2` + - `.street` must be a string FULL_MESSAGE, [ 'each' => [ '__root__' => 'Each item in `[["region": "Oregon", "country": "USA", "other": 123], ["street": "", "region": "Oregon", "country": "USA"], ["s ... ]` must be valid', 0 => [ '__root__' => 'These rules must pass for `["region": "Oregon", "country": "USA", "other": 123]`', - 'street' => 'street must be present', - 'other' => 'other must be a string or must be null', + 'street' => '`.street` must be present', + 'other' => '`.other` must be a string or must be null', ], - 1 => 'street must not be empty', - 2 => 'street must be a string', + 1 => '`.street` must not be empty', + 2 => '`.street` must be a string', ], ], )); diff --git a/tests/feature/Issues/Issue1348Test.php b/tests/feature/Issues/Issue1348Test.php index ef8219496..3ee83f5d1 100644 --- a/tests/feature/Issues/Issue1348Test.php +++ b/tests/feature/Issues/Issue1348Test.php @@ -24,57 +24,57 @@ v::key('manufacturer', v::equals('Ford'))->key('model', Validator::in(['F150', 'Bronco'])), ), )->assert($cars), - 'manufacturer must be equal to "Honda"', + '`.2.manufacturer` must be equal to "Honda"', <<<'FULL_MESSAGE' - Each item in `[["manufacturer": "Honda", "model": "Accord"], ["manufacturer": "Toyota", "model": "Rav4"], ["manufacturer": "Fo ... ]` must be valid - - Only one of these rules must pass for `["manufacturer": "Ford", "model": "not real"]` + - Only one of these rules must pass for `.2` - All the required rules must pass for `["manufacturer": "Ford", "model": "not real"]` - - manufacturer must be equal to "Honda" - - model must be in `["Accord", "Fit"]` + - `.manufacturer` must be equal to "Honda" + - `.model` must be in `["Accord", "Fit"]` - All the required rules must pass for `["manufacturer": "Ford", "model": "not real"]` - - manufacturer must be equal to "Toyota" - - model must be in `["Rav4", "Camry"]` + - `.manufacturer` must be equal to "Toyota" + - `.model` must be in `["Rav4", "Camry"]` - These rules must pass for `["manufacturer": "Ford", "model": "not real"]` - - model must be in `["F150", "Bronco"]` - - Only one of these rules must pass for `["manufacturer": "Honda", "model": "not valid"]` + - `.model` must be in `["F150", "Bronco"]` + - Only one of these rules must pass for `.3` - These rules must pass for `["manufacturer": "Honda", "model": "not valid"]` - - model must be in `["Accord", "Fit"]` + - `.model` must be in `["Accord", "Fit"]` - All the required rules must pass for `["manufacturer": "Honda", "model": "not valid"]` - - manufacturer must be equal to "Toyota" - - model must be in `["Rav4", "Camry"]` + - `.manufacturer` must be equal to "Toyota" + - `.model` must be in `["Rav4", "Camry"]` - All the required rules must pass for `["manufacturer": "Honda", "model": "not valid"]` - - manufacturer must be equal to "Ford" - - model must be in `["F150", "Bronco"]` + - `.manufacturer` must be equal to "Ford" + - `.model` must be in `["F150", "Bronco"]` FULL_MESSAGE, [ 'each' => [ '__root__' => 'Each item in `[["manufacturer": "Honda", "model": "Accord"], ["manufacturer": "Toyota", "model": "Rav4"], ["manufacturer": "Fo ... ]` must be valid', 2 => [ - '__root__' => 'Only one of these rules must pass for `["manufacturer": "Ford", "model": "not real"]`', + '__root__' => 'Only one of these rules must pass for `.2`', 'allOf.1' => [ '__root__' => 'All the required rules must pass for `["manufacturer": "Ford", "model": "not real"]`', - 'manufacturer' => 'manufacturer must be equal to "Honda"', - 'model' => 'model must be in `["Accord", "Fit"]`', + 'manufacturer' => '`.manufacturer` must be equal to "Honda"', + 'model' => '`.model` must be in `["Accord", "Fit"]`', ], 'allOf.2' => [ '__root__' => 'All the required rules must pass for `["manufacturer": "Ford", "model": "not real"]`', - 'manufacturer' => 'manufacturer must be equal to "Toyota"', - 'model' => 'model must be in `["Rav4", "Camry"]`', + 'manufacturer' => '`.manufacturer` must be equal to "Toyota"', + 'model' => '`.model` must be in `["Rav4", "Camry"]`', ], - 'allOf.3' => 'model must be in `["F150", "Bronco"]`', + 'allOf.3' => '`.model` must be in `["F150", "Bronco"]`', ], 3 => [ - '__root__' => 'Only one of these rules must pass for `["manufacturer": "Honda", "model": "not valid"]`', - 'allOf.1' => 'model must be in `["Accord", "Fit"]`', + '__root__' => 'Only one of these rules must pass for `.3`', + 'allOf.1' => '`.model` must be in `["Accord", "Fit"]`', 'allOf.2' => [ '__root__' => 'All the required rules must pass for `["manufacturer": "Honda", "model": "not valid"]`', - 'manufacturer' => 'manufacturer must be equal to "Toyota"', - 'model' => 'model must be in `["Rav4", "Camry"]`', + 'manufacturer' => '`.manufacturer` must be equal to "Toyota"', + 'model' => '`.model` must be in `["Rav4", "Camry"]`', ], 'allOf.3' => [ '__root__' => 'All the required rules must pass for `["manufacturer": "Honda", "model": "not valid"]`', - 'manufacturer' => 'manufacturer must be equal to "Ford"', - 'model' => 'model must be in `["F150", "Bronco"]`', + 'manufacturer' => '`.manufacturer` must be equal to "Ford"', + 'model' => '`.model` must be in `["F150", "Bronco"]`', ], ], ], diff --git a/tests/feature/Issues/Issue1376Test.php b/tests/feature/Issues/Issue1376Test.php index 3f1bb038f..595780fb0 100644 --- a/tests/feature/Issues/Issue1376Test.php +++ b/tests/feature/Issues/Issue1376Test.php @@ -14,24 +14,24 @@ ->property('author', v::intType()->lengthBetween(1, 2)) ->property('user', v::intVal()->lengthBetween(1, 2)) ->assert((object) ['author' => 'foo']), - 'title must be present', + '`.title` must be present', <<<'FULL_MESSAGE' - All the required rules must pass for `stdClass { +$author="foo" }` - - title must be present - - description must be present - - All the required rules must pass for author - - author must be an integer - - The length of author must be between 1 and 2 - - user must be present + - `.title` must be present + - `.description` must be present + - All the required rules must pass for `.author` + - `.author` must be an integer + - The length of `.author` must be between 1 and 2 + - `.user` must be present FULL_MESSAGE, [ '__root__' => 'All the required rules must pass for `stdClass { +$author="foo" }`', - 'title' => 'title must be present', - 'description' => 'description must be present', + 'title' => '`.title` must be present', + 'description' => '`.description` must be present', 'author' => [ - '__root__' => 'All the required rules must pass for author', - 'intType' => 'author must be an integer', - 'lengthBetween' => 'The length of author must be between 1 and 2', + '__root__' => 'All the required rules must pass for `.author`', + 'intType' => '`.author` must be an integer', + 'lengthBetween' => 'The length of `.author` must be between 1 and 2', ], 'user' => 'user must be present', ], diff --git a/tests/feature/Issues/Issue1469Test.php b/tests/feature/Issues/Issue1469Test.php index 6a07b2abd..7d4054a63 100644 --- a/tests/feature/Issues/Issue1469Test.php +++ b/tests/feature/Issues/Issue1469Test.php @@ -28,25 +28,25 @@ function (): void { ))->notEmpty()), )->assert($data); }, - 'quantity must be an integer value', + '`.0.quantity` must be an integer value', <<<'FULL_MESSAGE' - - Each item in order_items must be valid - - order_items validation failed - - quantity must be an integer value - - order_items contains both missing and extra keys - - product_title must be present - - quantity must be present - - product_title2 must not be present + - Each item in `.order_items` must be valid + - `.order_items` validation failed + - `.quantity` must be an integer value + - `.order_items` contains both missing and extra keys + - `.product_title` must be present + - `.quantity` must be present + - `.product_title2` must not be present FULL_MESSAGE, [ 'keySet' => [ - '__root__' => 'Each item in order_items must be valid', + '__root__' => 'Each item in `.order_items` must be valid', 0 => 'quantity must be an integer value', 1 => [ - '__root__' => 'order_items contains both missing and extra keys', - 'product_title' => 'product_title must be present', - 'quantity' => 'quantity must be present', - 'product_title2' => 'product_title2 must not be present', + '__root__' => '`.order_items` contains both missing and extra keys', + 'product_title' => '`.product_title` must be present', + 'quantity' => '`.quantity must` be present', + 'product_title2' => '`.product_title2` must not be present', ], ], ], diff --git a/tests/feature/Issues/Issue1477Test.php b/tests/feature/Issues/Issue1477Test.php index fb85610a1..a55443f46 100644 --- a/tests/feature/Issues/Issue1477Test.php +++ b/tests/feature/Issues/Issue1477Test.php @@ -24,7 +24,7 @@ protected function isValid(mixed $input): bool ), )->assert(['Address' => 'cvejvn']); }, - 'Address is not good!', - '- Address is not good!', - ['Address' => 'Address is not good!'], + '`.Address` is not good!', + '- `.Address` is not good!', + ['Address' => '`.Address` is not good!'], )); diff --git a/tests/feature/Issues/Issue179Test.php b/tests/feature/Issues/Issue179Test.php index ac47a6526..87d9cd6a6 100644 --- a/tests/feature/Issues/Issue179Test.php +++ b/tests/feature/Issues/Issue179Test.php @@ -23,15 +23,15 @@ function (): void { $validator->key('schema', v::stringType()); $validator->assert($config); }, - 'host must be a string', + '`.host` must be a string', <<<'FULL_MESSAGE' - These rules must pass for Settings - - host must be a string - - user must be present + - `.host` must be a string + - `.user` must be present FULL_MESSAGE, [ '__root__' => 'These rules must pass for Settings', - 'host' => 'host must be a string', - 'user' => 'user must be present', + 'host' => '`.host` must be a string', + 'user' => '`.user` must be present', ], )); diff --git a/tests/feature/Issues/Issue425Test.php b/tests/feature/Issues/Issue425Test.php index 75813b832..9f2f8d4c0 100644 --- a/tests/feature/Issues/Issue425Test.php +++ b/tests/feature/Issues/Issue425Test.php @@ -14,7 +14,7 @@ function (): void { ->key('reference', v::stringType()->notEmpty()->lengthBetween(1, 50)); $validator->assert(['age' => 1]); }, - 'reference must be present', - '- reference must be present', - ['reference' => 'reference must be present'], + '`.reference` must be present', + '- `.reference` must be present', + ['reference' => '`.reference` must be present'], )); diff --git a/tests/feature/Issues/Issue446Test.php b/tests/feature/Issues/Issue446Test.php index 151a54a68..8947da8fc 100644 --- a/tests/feature/Issues/Issue446Test.php +++ b/tests/feature/Issues/Issue446Test.php @@ -17,7 +17,7 @@ ->key('name', v::lengthBetween(2, 32)) ->key('email', v::email()) ->assert($arr), - 'The length of name must be between 2 and 32', - '- The length of name must be between 2 and 32', - ['name' => 'The length of name must be between 2 and 32'], + 'The length of `.name` must be between 2 and 32', + '- The length of `.name` must be between 2 and 32', + ['name' => 'The length of `.name` must be between 2 and 32'], )); diff --git a/tests/feature/Issues/Issue796Test.php b/tests/feature/Issues/Issue796Test.php index 66d2c7492..17e1c9cd6 100644 --- a/tests/feature/Issues/Issue796Test.php +++ b/tests/feature/Issues/Issue796Test.php @@ -40,17 +40,17 @@ 'schema' => 'schema', ], ]), - 'host must be a string', + '`.mysql.host` must be a string', <<<'FULL_MESSAGE' - All the required rules must pass for the given data - - These rules must pass for mysql - - host must be a string - - These rules must pass for postgresql - - user must be a string + - These rules must pass for `.mysql` + - `.host` must be a string + - These rules must pass for `.postgresql` + - `.user` must be a string FULL_MESSAGE, [ '__root__' => 'All the required rules must pass for the given data', - 'mysql' => 'host must be a string', - 'postgresql' => 'user must be a string', + 'mysql' => '`.host` must be a string', + 'postgresql' => '`.user` must be a string', ], )); diff --git a/tests/feature/Issues/Issue799Test.php b/tests/feature/Issues/Issue799Test.php index e428e486c..562390fba 100644 --- a/tests/feature/Issues/Issue799Test.php +++ b/tests/feature/Issues/Issue799Test.php @@ -22,12 +22,12 @@ <<<'FULL_MESSAGE' - All the required rules must pass for 1 - 1 must be an array value - - scheme must be present + - `.scheme` must be present FULL_MESSAGE, [ '__root__' => 'All the required rules must pass for 1', 'arrayVal' => '1 must be an array value', - 'scheme' => 'scheme must be present', + 'scheme' => '`.scheme` must be present', ], )); @@ -38,7 +38,7 @@ v::arrayVal()->key('scheme', v::startsWith('https')), ) ->assert($input), - 'scheme must start with "https"', - '- scheme must start with "https"', - ['scheme' => 'scheme must start with "https"'], + '`.scheme` must start with "https"', + '- `.scheme` must start with "https"', + ['scheme' => '`.scheme` must start with "https"'], )); diff --git a/tests/feature/KeysAsValidatorNamesTest.php b/tests/feature/KeysAsValidatorNamesTest.php index 2bbe86612..1713b2dfe 100644 --- a/tests/feature/KeysAsValidatorNamesTest.php +++ b/tests/feature/KeysAsValidatorNamesTest.php @@ -21,7 +21,7 @@ function (): void { }, <<<'FULL_MESSAGE' - All the required rules must pass for User Subscription Form - - The length of username must be between 2 and 32 - - birthdate must be a valid date/time + - The length of `.username` must be between 2 and 32 + - `.birthdate` must be a valid date/time FULL_MESSAGE, )); diff --git a/tests/feature/Rules/AttributesTest.php b/tests/feature/Rules/AttributesTest.php index 2da23495c..0c9697a3a 100644 --- a/tests/feature/Rules/AttributesTest.php +++ b/tests/feature/Rules/AttributesTest.php @@ -11,16 +11,16 @@ test('Default', expectAll( fn() => v::attributes()->assert(new WithAttributes('', 'john.doe@gmail.com', '2024-06-23')), - 'name must not be empty', - '- name must not be empty', - ['name' => 'name must not be empty'], + '`.name` must not be empty', + '- `.name` must not be empty', + ['name' => '`.name` must not be empty'], )); test('Inverted', expectAll( fn() => v::attributes()->assert(new WithAttributes('John Doe', 'john.doe@gmail.com', '2024-06-23', '+1234567890')), - 'phone must be a valid telephone number or must be null', - '- phone must be a valid telephone number or must be null', - ['phone' => 'phone must be a valid telephone number or must be null'], + '`.phone` must be a valid telephone number or must be null', + '- `.phone` must be a valid telephone number or must be null', + ['phone' => '`.phone` must be a valid telephone number or must be null'], )); test('Not an object', expectAll( @@ -32,39 +32,39 @@ test('Nullable', expectAll( fn() => v::attributes()->assert(new WithAttributes('John Doe', 'john.doe@gmail.com', '2024-06-23', 'not a phone number')), - 'phone must be a valid telephone number or must be null', - '- phone must be a valid telephone number or must be null', - ['phone' => 'phone must be a valid telephone number or must be null'], + '`.phone` must be a valid telephone number or must be null', + '- `.phone` must be a valid telephone number or must be null', + ['phone' => '`.phone` must be a valid telephone number or must be null'], )); test('Multiple attributes, all failed', expectAll( fn() => v::attributes()->assert(new WithAttributes('', 'not an email', 'not a date', 'not a phone number')), - 'name must not be empty', + '`.name` must not be empty', <<<'FULL_MESSAGE' - All the required rules must pass for `Respect\Validation\Test\Stubs\WithAttributes { +$name="" +$email="not an email" +$birthdate="not a date" +$phone ... }` - - name must not be empty - - email must be a valid email address - - All the required rules must pass for birthdate - - birthdate must be a valid date in the format "2005-12-30" - - For comparison with now, birthdate must be a valid datetime - - phone must be a valid telephone number or must be null + - `.name` must not be empty + - `.email` must be a valid email address + - All the required rules must pass for `.birthdate` + - `.birthdate` must be a valid date in the format "2005-12-30" + - For comparison with now, `.birthdate` must be a valid datetime + - `.phone` must be a valid telephone number or must be null FULL_MESSAGE, [ '__root__' => 'All the required rules must pass for `Respect\\Validation\\Test\\Stubs\\WithAttributes { +$name="" +$email="not an email" +$birthdate="not a date" +$phone ... }`', - 'name' => 'name must not be empty', - 'email' => 'email must be a valid email address', + 'name' => '`.name` must not be empty', + 'email' => '`.email` must be a valid email address', 'birthdate' => [ '__root__' => 'All the required rules must pass for birthdate', - 'date' => 'birthdate must be a valid date in the format "2005-12-30"', - 'dateTimeDiffLessThanOrEqual' => 'For comparison with now, birthdate must be a valid datetime', + 'date' => '`.birthdate` must be a valid date in the format "2005-12-30"', + 'dateTimeDiffLessThanOrEqual' => 'For comparison with now, `.birthdate` must be a valid datetime', ], - 'phone' => 'phone must be a valid telephone number or must be null', + 'phone' => '`.phone` must be a valid telephone number or must be null', ], )); test('Multiple attributes, one failed', expectAll( fn() => v::attributes()->assert(new WithAttributes('John Doe', 'john.doe@gmail.com', '22 years ago')), - 'birthdate must be a valid date in the format "2005-12-30"', - '- birthdate must be a valid date in the format "2005-12-30"', - ['birthdate' => 'birthdate must be a valid date in the format "2005-12-30"'], + '`.birthdate` must be a valid date in the format "2005-12-30"', + '- `.birthdate` must be a valid date in the format "2005-12-30"', + ['birthdate' => '`.birthdate` must be a valid date in the format "2005-12-30"'], )); diff --git a/tests/feature/Rules/CircuitTest.php b/tests/feature/Rules/CircuitTest.php index 31a0779e4..f9ba6a7dc 100644 --- a/tests/feature/Rules/CircuitTest.php +++ b/tests/feature/Rules/CircuitTest.php @@ -86,7 +86,7 @@ v::key('countyCode', v::countryCode()), v::lazy(fn ($input) => v::key('subdivisionCode', v::subdivisionCode($input['countyCode']))), )->assert(['countyCode' => 'BR', 'subdivisionCode' => 'CA']), - 'subdivisionCode must be a subdivision code of Brazil', - '- subdivisionCode must be a subdivision code of Brazil', - ['subdivisionCode' => 'subdivisionCode must be a subdivision code of Brazil'], + '`.subdivisionCode` must be a subdivision code of Brazil', + '- `.subdivisionCode` must be a subdivision code of Brazil', + ['subdivisionCode' => '`.subdivisionCode` must be a subdivision code of Brazil'], )); diff --git a/tests/feature/Rules/EachTest.php b/tests/feature/Rules/EachTest.php index 4939ad749..f1940b558 100644 --- a/tests/feature/Rules/EachTest.php +++ b/tests/feature/Rules/EachTest.php @@ -23,35 +23,35 @@ test('Default', expectAll( fn() => v::each(v::intType())->assert(['a', 'b', 'c']), - '"a" must be an integer', + '`.0` must be an integer', <<<'FULL_MESSAGE' - Each item in `["a", "b", "c"]` must be valid - - "a" must be an integer - - "b" must be an integer - - "c" must be an integer + - `.0` must be an integer + - `.1` must be an integer + - `.2` must be an integer FULL_MESSAGE, [ '__root__' => 'Each item in `["a", "b", "c"]` must be valid', - 0 => '"a" must be an integer', - 1 => '"b" must be an integer', - 2 => '"c" must be an integer', + 0 => '`.0` must be an integer', + 1 => '`.1` must be an integer', + 2 => '`.2` must be an integer', ], )); test('Inverted', expectAll( fn() => v::not(v::each(v::intType()))->assert([1, 2, 3]), - '1 must not be an integer', + '`.0` must not be an integer', <<<'FULL_MESSAGE' - Each item in `[1, 2, 3]` must be invalid - - 1 must not be an integer - - 2 must not be an integer - - 3 must not be an integer + - `.0` must not be an integer + - `.1` must not be an integer + - `.2` must not be an integer FULL_MESSAGE, [ '__root__' => 'Each item in `[1, 2, 3]` must be invalid', - 0 => '1 must not be an integer', - 1 => '2 must not be an integer', - 2 => '3 must not be an integer', + 0 => '`.0` must not be an integer', + 1 => '`.1` must not be an integer', + 2 => '`.2` must not be an integer', ], )); @@ -225,42 +225,42 @@ ], ]) ->assert(['a', 'b', 'c']), - 'Wrapped must be an integer', + 'First item should have been an integer', <<<'FULL_MESSAGE' - - Each item in Wrapped must be valid - - Wrapped must be an integer - - Wrapped must be an integer - - Wrapped must be an integer + - Here a sequence of items that did not pass the validation + - First item should have been an integer + - Second item should have been an integer + - Third item should have been an integer FULL_MESSAGE, [ - '__root__' => 'Each item in Wrapped must be valid', - 0 => 'Wrapped must be an integer', - 1 => 'Wrapped must be an integer', - 2 => 'Wrapped must be an integer', + '__root__' => 'Here a sequence of items that did not pass the validation', + 0 => 'First item should have been an integer', + 1 => 'Second item should have been an integer', + 2 => 'Third item should have been an integer', ], )); test('Chained wrapped rule', expectAll( fn() => v::each(v::between(5, 7)->odd())->assert([2, 4]), - '2 must be between 5 and 7', + '`.0` must be between 5 and 7', <<<'FULL_MESSAGE' - Each item in `[2, 4]` must be valid - - All the required rules must pass for 2 + - All the required rules must pass for `.0` - 2 must be between 5 and 7 - 2 must be an odd number - - All the required rules must pass for 4 + - All the required rules must pass for `.1` - 4 must be between 5 and 7 - 4 must be an odd number FULL_MESSAGE, [ '__root__' => 'Each item in `[2, 4]` must be valid', 0 => [ - '__root__' => 'All the required rules must pass for 2', + '__root__' => 'All the required rules must pass for `.0`', 'between' => '2 must be between 5 and 7', 'odd' => '2 must be an odd number', ], 1 => [ - '__root__' => 'All the required rules must pass for 4', + '__root__' => 'All the required rules must pass for `.1`', 'between' => '4 must be between 5 and 7', 'odd' => '4 must be an odd number', ], @@ -269,16 +269,16 @@ test('Multiple nested rules', expectAll( fn() => v::each(v::arrayType()->key('my_int', v::intType()->odd()))->assert([['not_int' => 'wrong'], ['my_int' => 2], 'not an array']), - 'my_int must be present', + '`.0.my_int` must be present', <<<'FULL_MESSAGE' - Each item in `[["not_int": "wrong"], ["my_int": 2], "not an array"]` must be valid - - These rules must pass for `["not_int": "wrong"]` - - my_int must be present - - These rules must pass for `["my_int": 2]` - - my_int must be an odd number - - All the required rules must pass for "not an array" + - These rules must pass for `.0` + - `.my_int` must be present + - These rules must pass for `.1` + - `.my_int` must be an odd number + - All the required rules must pass for `.2` - "not an array" must be an array - - my_int must be present + - `.my_int` must be present FULL_MESSAGE, [ '__root__' => 'Each item in `[["not_int": "wrong"], ["my_int": 2], "not an array"]` must be valid', diff --git a/tests/feature/Rules/KeyExistsTest.php b/tests/feature/Rules/KeyExistsTest.php index 54d4ecf5e..9f4fe3260 100644 --- a/tests/feature/Rules/KeyExistsTest.php +++ b/tests/feature/Rules/KeyExistsTest.php @@ -9,16 +9,16 @@ test('Default mode', expectAll( fn() => v::keyExists('foo')->assert(['bar' => 'baz']), - 'foo must be present', - '- foo must be present', - ['foo' => 'foo must be present'], + '`.foo` must be present', + '- `.foo` must be present', + ['foo' => '`.foo` must be present'], )); test('Inverted mode', expectAll( fn() => v::not(v::keyExists('foo'))->assert(['foo' => 'baz']), - 'foo must not be present', - '- foo must not be present', - ['foo' => 'foo must not be present'], + '`.foo` must not be present', + '- `.foo` must not be present', + ['foo' => '`.foo` must not be present'], )); test('Custom name', expectAll( @@ -29,8 +29,8 @@ )); test('Custom template', expectAll( - fn() => v::keyExists('foo')->assert(['bar' => 'baz'], 'Custom template for `{{name}}`'), - 'Custom template for `foo`', - '- Custom template for `foo`', - ['foo' => 'Custom template for `foo`'], + fn() => v::keyExists('foo')->assert(['bar' => 'baz'], 'Custom template for {{name}}'), + 'Custom template for `.foo`', + '- Custom template for `.foo`', + ['foo' => 'Custom template for `.foo`'], )); diff --git a/tests/feature/Rules/KeyOptionalTest.php b/tests/feature/Rules/KeyOptionalTest.php index 543d3cf16..1f38131c2 100644 --- a/tests/feature/Rules/KeyOptionalTest.php +++ b/tests/feature/Rules/KeyOptionalTest.php @@ -9,23 +9,23 @@ test('Default', expectAll( fn() => v::keyOptional('foo', v::intType())->assert(['foo' => 'string']), - 'foo must be an integer', - '- foo must be an integer', - ['foo' => 'foo must be an integer'], + '`.foo` must be an integer', + '- `.foo` must be an integer', + ['foo' => '`.foo` must be an integer'], )); test('Inverted', expectAll( fn() => v::not(v::keyOptional('foo', v::intType()))->assert(['foo' => 12]), - 'foo must not be an integer', - '- foo must not be an integer', - ['foo' => 'foo must not be an integer'], + '`.foo` must not be an integer', + '- `.foo` must not be an integer', + ['foo' => '`.foo` must not be an integer'], )); test('Inverted with missing key', expectAll( fn() => v::not(v::keyOptional('foo', v::intType()))->assert([]), - 'foo must be present', - '- foo must be present', - ['foo' => 'foo must be present'], + '`.foo` must be present', + '- `.foo` must be present', + ['foo' => '`.foo` must be present'], )); test('With wrapped name, default', expectAll( @@ -44,23 +44,23 @@ test('With wrapper name, default', expectAll( fn() => v::keyOptional('foo', v::intType())->setName('Wrapper')->assert(['foo' => 'string']), - 'foo must be an integer', - '- foo must be an integer', - ['foo' => 'foo must be an integer'], + 'Wrapper must be an integer', + '- Wrapper must be an integer', + ['foo' => 'Wrapper must be an integer'], )); test('With wrapper name, inverted', expectAll( fn() => v::not(v::keyOptional('foo', v::intType())->setName('Wrapper'))->setName('Not')->assert(['foo' => 12]), - 'foo must not be an integer', - '- foo must not be an integer', - ['foo' => 'foo must not be an integer'], + 'Wrapper must not be an integer', + '- Wrapper must not be an integer', + ['foo' => 'Wrapper must not be an integer'], )); test('With "Not" name, inverted', expectAll( fn() => v::not(v::keyOptional('foo', v::intType()))->setName('Not')->assert(['foo' => 12]), - 'foo must not be an integer', - '- foo must not be an integer', - ['foo' => 'foo must not be an integer'], + 'Not must not be an integer', + '- Not must not be an integer', + ['foo' => 'Not must not be an integer'], )); test('With template, default', expectAll( diff --git a/tests/feature/Rules/KeySetTest.php b/tests/feature/Rules/KeySetTest.php index c5155b28a..c5d7d43f1 100644 --- a/tests/feature/Rules/KeySetTest.php +++ b/tests/feature/Rules/KeySetTest.php @@ -9,52 +9,52 @@ test('one rule / one failed', expectAll( fn() => v::keySet(v::key('foo', v::intType()))->assert(['foo' => 'string']), - 'foo must be an integer', - '- foo must be an integer', - ['foo' => 'foo must be an integer'], + '`.foo` must be an integer', + '- `.foo` must be an integer', + ['foo' => '`.foo` must be an integer'], )); test('one rule / one missing key', expectAll( fn() => v::keySet(v::keyExists('foo'))->assert([]), - 'foo must be present', - '- foo must be present', - ['foo' => 'foo must be present'], + '`.foo` must be present', + '- `.foo` must be present', + ['foo' => '`.foo` must be present'], )); test('one rule / one extra key', expectAll( fn() => v::keySet(v::keyExists('foo'))->assert(['foo' => 42, 'bar' => 'string']), - 'bar must not be present', - '- bar must not be present', - ['bar' => 'bar must not be present'], + '`.bar` must not be present', + '- `.bar` must not be present', + ['bar' => '`.bar` must not be present'], )); test('one rule / one extra key / one missing key', expectAll( fn() => v::keySet(v::keyExists('foo'))->assert(['bar' => true]), - 'foo must be present', + '`.foo` must be present', <<<'FULL_MESSAGE' - `["bar": true]` contains both missing and extra keys - - foo must be present - - bar must not be present + - `.foo` must be present + - `.bar` must not be present FULL_MESSAGE, [ '__root__' => '`["bar": true]` contains both missing and extra keys', - 'foo' => 'foo must be present', - 'bar' => 'bar must not be present', + 'foo' => '`.foo` must be present', + 'bar' => '`.bar` must not be present', ], )); test('one rule / two extra keys', expectAll( fn() => v::keySet(v::keyExists('foo'))->assert(['foo' => 42, 'bar' => 'string', 'baz' => true]), - 'bar must not be present', + '`.bar` must not be present', <<<'FULL_MESSAGE' - `["foo": 42, "bar": "string", "baz": true]` contains extra keys - - bar must not be present - - baz must not be present + - `.bar` must not be present + - `.baz` must not be present FULL_MESSAGE, [ '__root__' => '`["foo": 42, "bar": "string", "baz": true]` contains extra keys', - 'bar' => 'bar must not be present', - 'baz' => 'baz must not be present', + 'bar' => '`.bar` must not be present', + 'baz' => '`.baz` must not be present', ], )); @@ -75,54 +75,54 @@ 'xyzzy' => false, 'thud' => 42, ]), - 'bar must not be present', + '`.bar` must not be present', <<<'FULL_MESSAGE' - `["foo": 42, "bar": "string", "baz": true, "qux": false, "quux": 42, ...]` contains extra keys - - bar must not be present - - baz must not be present - - qux must not be present - - quux must not be present - - corge must not be present - - grault must not be present - - garply must not be present - - waldo must not be present - - fred must not be present - - plugh must not be present + - `.bar` must not be present + - `.baz` must not be present + - `.qux` must not be present + - `.quux` must not be present + - `.corge` must not be present + - `.grault` must not be present + - `.garply` must not be present + - `.waldo` must not be present + - `.fred` must not be present + - `.plugh` must not be present FULL_MESSAGE, [ '__root__' => '`["foo": 42, "bar": "string", "baz": true, "qux": false, "quux": 42, ...]` contains extra keys', - 'bar' => 'bar must not be present', - 'baz' => 'baz must not be present', - 'qux' => 'qux must not be present', - 'quux' => 'quux must not be present', - 'corge' => 'corge must not be present', - 'grault' => 'grault must not be present', - 'garply' => 'garply must not be present', - 'waldo' => 'waldo must not be present', - 'fred' => 'fred must not be present', - 'plugh' => 'plugh must not be present', + 'bar' => '`.bar` must not be present', + 'baz' => '`.baz` must not be present', + 'qux' => '`.qux` must not be present', + 'quux' => '`.quux` must not be present', + 'corge' => '`.corge` must not be present', + 'grault' => '`.grault` must not be present', + 'garply' => '`.garply` must not be present', + 'waldo' => '`.waldo` must not be present', + 'fred' => '`.fred` must not be present', + 'plugh' => '`.plugh` must not be present', ], )); test('multiple rules / one failed', expectAll( fn() => v::keySet(v::keyExists('foo'), v::keyExists('bar'))->assert(['foo' => 42]), - 'bar must be present', - '- bar must be present', - ['bar' => 'bar must be present'], + '`.bar` must be present', + '- `.bar` must be present', + ['bar' => '`.bar` must be present'], )); test('multiple rules / all failed', expectAll( fn() => v::keySet(v::keyExists('foo'), v::keyExists('bar'))->assert([]), - 'foo must be present', + '`.foo` must be present', <<<'FULL_MESSAGE' - `[]` contains missing keys - - foo must be present - - bar must be present + - `.foo` must be present + - `.bar` must be present FULL_MESSAGE, [ '__root__' => '`[]` contains missing keys', - 'foo' => 'foo must be present', - 'bar' => 'bar must be present', + 'foo' => '`.foo` must be present', + 'bar' => '`.bar` must be present', ], )); @@ -131,9 +131,9 @@ v::keyExists('foo'), v::keyExists('bar'), )->assert(['foo' => 42, 'bar' => 'string', 'baz' => true]), - 'baz must not be present', - '- baz must not be present', - ['baz' => 'baz must not be present'], + '`.baz` must not be present', + '- `.baz` must not be present', + ['baz' => '`.baz` must not be present'], )); test('multiple rules / one extra key / one missing', expectAll( @@ -141,16 +141,16 @@ v::keyExists('foo'), v::keyExists('bar'), )->assert(['bar' => 'string', 'baz' => true]), - 'foo must be present', + '`.foo` must be present', <<<'FULL_MESSAGE' - `["bar": "string", "baz": true]` contains both missing and extra keys - - foo must be present - - baz must not be present + - `.foo` must be present + - `.baz` must not be present FULL_MESSAGE, [ '__root__' => '`["bar": "string", "baz": true]` contains both missing and extra keys', - 'foo' => 'foo must be present', - 'baz' => 'baz must not be present', + 'foo' => '`.foo` must be present', + 'baz' => '`.baz` must not be present', ], )); @@ -160,16 +160,16 @@ v::keyExists('bar'), v::keyOptional('qux', v::intType()), )->assert(['foo' => 42, 'bar' => 'string', 'baz' => true, 'qux' => false]), - 'qux must be an integer', + '`.qux` must be an integer', <<<'FULL_MESSAGE' - `["foo": 42, "bar": "string", "baz": true, "qux": false]` contains extra keys - - qux must be an integer - - baz must not be present + - `.qux` must be an integer + - `.baz` must not be present FULL_MESSAGE, [ '__root__' => '`["foo": 42, "bar": "string", "baz": true, "qux": false]` contains extra keys', - 'qux' => 'qux must be an integer', - 'baz' => 'baz must not be present', + 'qux' => '`.qux` must be an integer', + 'baz' => '`.baz` must not be present', ], )); @@ -180,16 +180,16 @@ v::key('baz', v::intType()), ) ->assert(['foo' => 42, 'bar' => 'string', 'baz' => true]), - 'bar must be an integer', + '`.bar` must be an integer', <<<'FULL_MESSAGE' - `["foo": 42, "bar": "string", "baz": true]` validation failed - - bar must be an integer - - baz must be an integer + - `.bar` must be an integer + - `.baz` must be an integer FULL_MESSAGE, [ '__root__' => '`["foo": 42, "bar": "string", "baz": true]` validation failed', - 'bar' => 'bar must be an integer', - 'baz' => 'baz must be an integer', + 'bar' => '`.bar` must be an integer', + 'baz' => '`.baz` must be an integer', ], )); @@ -201,15 +201,15 @@ ->key('baz', v::intType()), ) ->assert(['foo' => 42, 'bar' => 'string']), - 'bar must be an integer', + '`.bar` must be an integer', <<<'FULL_MESSAGE' - `["foo": 42, "bar": "string"]` contains missing keys - - bar must be an integer - - baz must be present + - `.bar` must be an integer + - `.baz` must be present FULL_MESSAGE, [ '__root__' => '`["foo": 42, "bar": "string"]` contains missing keys', - 'bar' => 'bar must be an integer', - 'baz' => 'baz must be present', + 'bar' => '`.bar` must be an integer', + 'baz' => '`.baz` must be present', ], )); diff --git a/tests/feature/Rules/KeyTest.php b/tests/feature/Rules/KeyTest.php index 9d3205063..ca964ebd5 100644 --- a/tests/feature/Rules/KeyTest.php +++ b/tests/feature/Rules/KeyTest.php @@ -9,30 +9,30 @@ test('Missing key', expectAll( fn() => v::key('foo', v::intType())->assert([]), - 'foo must be present', - '- foo must be present', - ['foo' => 'foo must be present'], + '`.foo` must be present', + '- `.foo` must be present', + ['foo' => '`.foo` must be present'], )); test('Default', expectAll( fn() => v::key('foo', v::intType())->assert(['foo' => 'string']), - 'foo must be an integer', - '- foo must be an integer', - ['foo' => 'foo must be an integer'], + '`.foo` must be an integer', + '- `.foo` must be an integer', + ['foo' => '`.foo` must be an integer'], )); test('Inverted', expectAll( fn() => v::not(v::key('foo', v::intType()))->assert(['foo' => 12]), - 'foo must not be an integer', - '- foo must not be an integer', - ['foo' => 'foo must not be an integer'], + '`.foo` must not be an integer', + '- `.foo` must not be an integer', + ['foo' => '`.foo` must not be an integer'], )); test('Double-inverted with missing key', expectAll( fn() => v::not(v::not(v::key('foo', v::intType())))->assert([]), - 'foo must be present', - '- foo must be present', - ['foo' => 'foo must be present'], + '`.foo` must be present', + '- `.foo` must be present', + ['foo' => '`.foo` must be present'], )); test('With wrapped name, missing key', expectAll( @@ -58,9 +58,9 @@ test('With wrapper name, default', expectAll( fn() => v::key('foo', v::intType())->setName('Wrapper')->assert(['foo' => 'string']), - 'foo must be an integer', - '- foo must be an integer', - ['foo' => 'foo must be an integer'], + 'Wrapper must be an integer', + '- Wrapper must be an integer', + ['foo' => 'Wrapper must be an integer'], )); test('With wrapper name, missing key', expectAll( @@ -72,16 +72,16 @@ test('With wrapper name, inverted', expectAll( fn() => v::not(v::key('foo', v::intType())->setName('Wrapper'))->setName('Not')->assert(['foo' => 12]), - 'foo must not be an integer', - '- foo must not be an integer', - ['foo' => 'foo must not be an integer'], + 'Wrapper must not be an integer', + '- Wrapper must not be an integer', + ['foo' => 'Wrapper must not be an integer'], )); test('With "Not" name, inverted', expectAll( fn() => v::not(v::key('foo', v::intType()))->setName('Not')->assert(['foo' => 12]), - 'foo must not be an integer', - '- foo must not be an integer', - ['foo' => 'foo must not be an integer'], + 'Not must not be an integer', + '- Not must not be an integer', + ['foo' => 'Not must not be an integer'], )); test('With template, default', expectAll( diff --git a/tests/feature/Rules/NamedTest.php b/tests/feature/Rules/NamedTest.php index 4f31fb85e..55fa3836d 100644 --- a/tests/feature/Rules/NamedTest.php +++ b/tests/feature/Rules/NamedTest.php @@ -69,17 +69,17 @@ 'Vegetables' ), )->assert(['vegetables' => ['root' => 12, 'stems' => 12]]), - 'root must be a string', + '`.vegetables.root` must be a string', <<<'FULL_MESSAGE' - All the required rules must pass for Vegetables - - root must be a string - - stems must be a string - - fruits must be present + - `.root` must be a string + - `.stems` must be a string + - `.fruits` must be present FULL_MESSAGE, [ '__root__' => 'All the required rules must pass for Vegetables', - 'root' => 'root must be a string', - 'stems' => 'stems must be a string', - 'fruits' => 'fruits must be present', + 'root' => '`.root` must be a string', + 'stems' => '`.stems` must be a string', + 'fruits' => '`.fruits` must be present', ], )); diff --git a/tests/feature/Rules/PropertyExistsTest.php b/tests/feature/Rules/PropertyExistsTest.php index 6327a8286..f92bf4d2b 100644 --- a/tests/feature/Rules/PropertyExistsTest.php +++ b/tests/feature/Rules/PropertyExistsTest.php @@ -9,16 +9,16 @@ test('Default mode', expectAll( fn() => v::propertyExists('foo')->assert((object) ['bar' => 'baz']), - 'foo must be present', - '- foo must be present', - ['foo' => 'foo must be present'], + '`.foo` must be present', + '- `.foo` must be present', + ['foo' => '`.foo` must be present'], )); test('Inverted mode', expectAll( fn() => v::not(v::propertyExists('foo'))->assert((object) ['foo' => 'baz']), - 'foo must not be present', - '- foo must not be present', - ['foo' => 'foo must not be present'], + '`.foo` must not be present', + '- `.foo` must not be present', + ['foo' => '`.foo` must not be present'], )); test('Custom name', expectAll( @@ -29,8 +29,8 @@ )); test('Custom template', expectAll( - fn() => v::propertyExists('foo')->assert((object) ['bar' => 'baz'], 'Custom template for `{{name}}`'), - 'Custom template for `foo`', - '- Custom template for `foo`', - ['foo' => 'Custom template for `foo`'], + fn() => v::propertyExists('foo')->assert((object) ['bar' => 'baz'], 'Custom template for {{name}}'), + 'Custom template for `.foo`', + '- Custom template for `.foo`', + ['foo' => 'Custom template for `.foo`'], )); diff --git a/tests/feature/Rules/PropertyOptionalTest.php b/tests/feature/Rules/PropertyOptionalTest.php index 777e176b3..29582c0e8 100644 --- a/tests/feature/Rules/PropertyOptionalTest.php +++ b/tests/feature/Rules/PropertyOptionalTest.php @@ -9,23 +9,23 @@ test('Default', expectAll( fn() => v::propertyOptional('foo', v::intType())->assert((object) ['foo' => 'string']), - 'foo must be an integer', - '- foo must be an integer', - ['foo' => 'foo must be an integer'], + '`.foo` must be an integer', + '- `.foo` must be an integer', + ['foo' => '`.foo` must be an integer'], )); test('Inverted', expectAll( fn() => v::not(v::propertyOptional('foo', v::intType()))->assert((object) ['foo' => 12]), - 'foo must not be an integer', - '- foo must not be an integer', - ['foo' => 'foo must not be an integer'], + '`.foo` must not be an integer', + '- `.foo` must not be an integer', + ['foo' => '`.foo` must not be an integer'], )); test('Inverted with missing property', expectAll( fn() => v::not(v::propertyOptional('foo', v::intType()))->assert(new stdClass()), - 'foo must be present', - '- foo must be present', - ['foo' => 'foo must be present'], + '`.foo` must be present', + '- `.foo` must be present', + ['foo' => '`.foo` must be present'], )); test('With wrapped name, default', expectAll( @@ -43,27 +43,24 @@ )); test('With wrapper name, default', expectAll( - fn() => v::propertyOptional('foo', v::intType()) - ->setName('Wrapper') - ->assert((object) ['foo' => 'string']), - 'foo must be an integer', - '- foo must be an integer', - ['foo' => 'foo must be an integer'], + fn() => v::propertyOptional('foo', v::intType())->setName('Wrapper')->assert((object) ['foo' => 'string']), + 'Wrapper must be an integer', + '- Wrapper must be an integer', + ['foo' => 'Wrapper must be an integer'], )); test('With wrapper name, inverted', expectAll( - fn() => v::not(v::propertyOptional('foo', v::intType())->setName('Wrapper')) - ->setName('Not')->assert((object) ['foo' => 12]), - 'foo must not be an integer', - '- foo must not be an integer', - ['foo' => 'foo must not be an integer'], + fn() => v::not(v::propertyOptional('foo', v::intType())->setName('Wrapper'))->setName('Not')->assert((object) ['foo' => 12]), + 'Wrapper must not be an integer', + '- Wrapper must not be an integer', + ['foo' => 'Wrapper must not be an integer'], )); test('With "Not" name, inverted', expectAll( fn() => v::not(v::propertyOptional('foo', v::intType()))->setName('Not')->assert((object) ['foo' => 12]), - 'foo must not be an integer', - '- foo must not be an integer', - ['foo' => 'foo must not be an integer'], + 'Not must not be an integer', + '- Not must not be an integer', + ['foo' => 'Not must not be an integer'], )); test('With template, default', expectAll( diff --git a/tests/feature/Rules/PropertyTest.php b/tests/feature/Rules/PropertyTest.php index 52ecb7634..0438ce049 100644 --- a/tests/feature/Rules/PropertyTest.php +++ b/tests/feature/Rules/PropertyTest.php @@ -9,30 +9,30 @@ test('Missing property', expectAll( fn() => v::property('foo', v::intType())->assert(new stdClass()), - 'foo must be present', - '- foo must be present', - ['foo' => 'foo must be present'], + '`.foo` must be present', + '- `.foo` must be present', + ['foo' => '`.foo` must be present'], )); test('Default', expectAll( fn() => v::property('foo', v::intType())->assert((object) ['foo' => 'string']), - 'foo must be an integer', - '- foo must be an integer', - ['foo' => 'foo must be an integer'], + '`.foo` must be an integer', + '- `.foo` must be an integer', + ['foo' => '`.foo` must be an integer'], )); test('Inverted', expectAll( fn() => v::not(v::property('foo', v::intType()))->assert((object) ['foo' => 12]), - 'foo must not be an integer', - '- foo must not be an integer', - ['foo' => 'foo must not be an integer'], + '`.foo` must not be an integer', + '- `.foo` must not be an integer', + ['foo' => '`.foo` must not be an integer'], )); test('Double-inverted with missing property', expectAll( fn() => v::not(v::not(v::property('foo', v::intType())))->assert(new stdClass()), - 'foo must be present', - '- foo must be present', - ['foo' => 'foo must be present'], + '`.foo` must be present', + '- `.foo` must be present', + ['foo' => '`.foo` must be present'], )); test('With wrapped name, missing property', expectAll( @@ -62,9 +62,9 @@ test('With wrapper name, default', expectAll( fn() => v::property('foo', v::intType())->setName('Wrapper')->assert((object) ['foo' => 'string']), - 'foo must be an integer', - '- foo must be an integer', - ['foo' => 'foo must be an integer'], + 'Wrapper must be an integer', + '- Wrapper must be an integer', + ['foo' => 'Wrapper must be an integer'], )); test('With wrapper name, missing property', expectAll( @@ -77,16 +77,16 @@ test('With wrapper name, inverted', expectAll( fn() => v::not(v::property('foo', v::intType())->setName('Wrapper'))->setName('Not') ->assert((object) ['foo' => 12]), - 'foo must not be an integer', - '- foo must not be an integer', - ['foo' => 'foo must not be an integer'], + 'Wrapper must not be an integer', + '- Wrapper must not be an integer', + ['foo' => 'Wrapper must not be an integer'], )); test('With "Not" name, inverted', expectAll( fn() => v::not(v::property('foo', v::intType()))->setName('Not')->assert((object) ['foo' => 12]), - 'foo must not be an integer', - '- foo must not be an integer', - ['foo' => 'foo must not be an integer'], + 'Not must not be an integer', + '- Not must not be an integer', + ['foo' => 'Not must not be an integer'], )); test('With template, default', expectAll( diff --git a/tests/feature/ShouldNotOverwriteDefinedNamesTest.php b/tests/feature/ShouldNotOverwriteDefinedNamesTest.php index fa34d358f..183300a54 100644 --- a/tests/feature/ShouldNotOverwriteDefinedNamesTest.php +++ b/tests/feature/ShouldNotOverwriteDefinedNamesTest.php @@ -16,10 +16,10 @@ test('Scenario #2', expectMessage( fn() => v::key('email', v::email())->setName('Email')->assert($input), - 'email must be a valid email address', + 'Email must be a valid email address', )); test('Scenario #3', expectMessage( fn() => v::key('email', v::email())->assert($input), - 'email must be a valid email address', + '`.email` must be a valid email address', )); diff --git a/tests/feature/Transformers/DeprecatedAttributeTest.php b/tests/feature/Transformers/DeprecatedAttributeTest.php index f8c43a2be..30dfc09fe 100644 --- a/tests/feature/Transformers/DeprecatedAttributeTest.php +++ b/tests/feature/Transformers/DeprecatedAttributeTest.php @@ -13,48 +13,48 @@ test('Scenario #1', expectMessageAndError( fn() => v::attribute('baz')->assert($object), - 'baz must be present', + '`.baz` must be present', 'The attribute() rule has been deprecated and will be removed in the next major version. Use propertyExists() instead.', )); test('Scenario #2', expectMessageAndError( fn() => v::not(v::attribute('foo'))->assert($object), - 'foo must not be present', + '`.foo` must not be present', 'The attribute() rule has been deprecated and will be removed in the next major version. Use propertyExists() instead.', )); test('Scenario #3', expectMessageAndError( fn() => v::attribute('foo', v::falseVal())->assert($object), - 'foo must evaluate to `false`', + '`.foo` must evaluate to `false`', 'The attribute() rule has been deprecated and will be removed in the next major version. Use property() instead.', )); test('Scenario #4', expectMessageAndError( fn() => v::not(v::attribute('foo', v::trueVal()))->assert($object), - 'foo must not evaluate to `true`', + '`.foo` must not evaluate to `true`', 'The attribute() rule has been deprecated and will be removed in the next major version. Use property() instead.', )); test('Scenario #5', expectMessageAndError( fn() => v::attribute('foo', v::falseVal(), true)->assert($object), - 'foo must evaluate to `false`', + '`.foo` must evaluate to `false`', 'The attribute() rule has been deprecated and will be removed in the next major version. Use property() instead.', )); test('Scenario #6', expectMessageAndError( fn() => v::not(v::attribute('foo', v::trueVal(), true))->assert($object), - 'foo must not evaluate to `true`', + '`.foo` must not evaluate to `true`', 'The attribute() rule has been deprecated and will be removed in the next major version. Use property() instead.', )); test('Scenario #7', expectMessageAndError( fn() => v::attribute('foo', v::falseVal(), false)->assert($object), - 'foo must evaluate to `false`', + '`.foo` must evaluate to `false`', 'The attribute() rule has been deprecated and will be removed in the next major version. Use propertyOptional() instead.', )); test('Scenario #8', expectMessageAndError( fn() => v::not(v::attribute('foo', v::trueVal(), false))->assert($object), - 'foo must not evaluate to `true`', + '`.foo` must not evaluate to `true`', 'The attribute() rule has been deprecated and will be removed in the next major version. Use propertyOptional() instead.', )); diff --git a/tests/feature/Transformers/DeprecatedKeyNestedTest.php b/tests/feature/Transformers/DeprecatedKeyNestedTest.php index 33264833d..e585b0e1a 100644 --- a/tests/feature/Transformers/DeprecatedKeyNestedTest.php +++ b/tests/feature/Transformers/DeprecatedKeyNestedTest.php @@ -15,24 +15,42 @@ test('Scenario #1', expectMessageAndError( fn() => v::keyNested('foo.bar.baz')->assert(['foo.bar.baz' => false]), - 'foo must be present', + '`.foo` must be present', + 'The keyNested() rule is deprecated and will be removed in the next major version. Use nested key() or property() instead.', +)); + +test('Scenario #A', expectMessageAndError( + fn() => v::keyNested('foo.bar.baz')->assert(['foo' => []]), + '`.foo.bar` must be present', + 'The keyNested() rule is deprecated and will be removed in the next major version. Use nested key() or property() instead.', +)); + +test('Scenario #B', expectMessageAndError( + fn() => v::keyNested('foo.bar.baz')->assert(['foo' => []]), + '`.foo.bar` must be present', + 'The keyNested() rule is deprecated and will be removed in the next major version. Use nested key() or property() instead.', +)); + +test('Scenario #C', expectMessageAndError( + fn() => v::keyNested('foo.bar.baz')->assert(['foo' => ['bar' => []]]), + '`.foo.bar.baz` must be present', 'The keyNested() rule is deprecated and will be removed in the next major version. Use nested key() or property() instead.', )); test('Scenario #2', expectMessageAndError( fn() => v::keyNested('foo.bar', v::negative())->assert($input), - 'bar must be a negative number', + '`.foo.bar` must be a negative number', 'The keyNested() rule is deprecated and will be removed in the next major version. Use nested key() or property() instead.', )); test('Scenario #3', expectMessageAndError( fn() => v::keyNested('foo.bar', v::stringType())->assert(new ArrayObject($input)), - 'bar must be a string', + '`.foo.bar` must be a string', 'The keyNested() rule is deprecated and will be removed in the next major version. Use nested key() or property() instead.', )); test('Scenario #4', expectMessageAndError( fn() => v::keyNested('foo.bar', v::floatType(), false)->assert($input), - 'bar must be float', + '`.foo.bar` must be float', 'The keyNested() rule is deprecated and will be removed in the next major version. Use nested key() or property() instead.', )); diff --git a/tests/feature/Transformers/DeprecatedKeyTest.php b/tests/feature/Transformers/DeprecatedKeyTest.php index c9ae85154..dc6665c3d 100644 --- a/tests/feature/Transformers/DeprecatedKeyTest.php +++ b/tests/feature/Transformers/DeprecatedKeyTest.php @@ -11,36 +11,36 @@ test('Scenario #1', expectMessageAndError( fn() => v::key('baz')->assert($array), - 'baz must be present', + '`.baz` must be present', 'Calling key() without a second parameter has been deprecated, and will be not be allowed in the next major version. Use keyExists() instead.', )); test('Scenario #2', expectMessageAndError( fn() => v::not(v::key('foo'))->assert($array), - 'foo must not be present', + '`.foo` must not be present', 'Calling key() without a second parameter has been deprecated, and will be not be allowed in the next major version. Use keyExists() instead.', )); test('Scenario #3', expectMessageAndError( fn() => v::key('foo', v::falseVal(), true)->assert($array), - 'foo must evaluate to `false`', + '`.foo` must evaluate to `false`', 'Calling key() with a third parameter has been deprecated, and will be not be allowed in the next major version. Use key() without the third parameter.', )); test('Scenario #4', expectMessageAndError( fn() => v::not(v::key('foo', v::trueVal(), true))->assert($array), - 'foo must not evaluate to `true`', + '`.foo` must not evaluate to `true`', 'Calling key() with a third parameter has been deprecated, and will be not be allowed in the next major version. Use key() without the third parameter.', )); test('Scenario #5', expectMessageAndError( fn() => v::key('foo', v::falseVal(), false)->assert($array), - 'foo must evaluate to `false`', + '`.foo` must evaluate to `false`', 'Calling key() with a third parameter has been deprecated, and will be not be allowed in the next major version. Use keyOptional() instead.', )); test('Scenario #6', expectMessageAndError( fn() => v::not(v::key('foo', v::trueVal(), false))->assert($array), - 'foo must not evaluate to `true`', + '`.foo` must not evaluate to `true`', 'Calling key() with a third parameter has been deprecated, and will be not be allowed in the next major version. Use keyOptional() instead.', )); diff --git a/tests/feature/Transformers/DeprecatedKeyValueTest.php b/tests/feature/Transformers/DeprecatedKeyValueTest.php index b0465f64b..5eba7307a 100644 --- a/tests/feature/Transformers/DeprecatedKeyValueTest.php +++ b/tests/feature/Transformers/DeprecatedKeyValueTest.php @@ -9,60 +9,60 @@ test('Scenario #1', expectMessageAndError( fn() => v::keyValue('foo', 'equals', 'bar')->assert(['bar' => 42]), - 'foo must be present', + '`.foo` must be present', 'The keyValue() rule has been deprecated and will be removed in the next major version. Use nested lazy() instead.', )); test('Scenario #2', expectMessageAndError( fn() => v::keyValue('foo', 'equals', 'bar')->assert(['foo' => 42]), - 'bar must be present', + '`.bar` must be present', 'The keyValue() rule has been deprecated and will be removed in the next major version. Use nested lazy() instead.', )); test('Scenario #3', expectMessageAndError( fn() => v::keyValue('foo', 'json', 'bar')->assert(['foo' => 42, 'bar' => 43]), - 'bar must be valid to validate foo', + '`.bar` must be valid to validate `.foo`', 'The keyValue() rule has been deprecated and will be removed in the next major version. Use nested lazy() instead.', )); test('Scenario #4', expectMessageAndError( fn() => v::keyValue('foo', 'equals', 'bar')->assert(['foo' => 1, 'bar' => 2]), - 'foo must be equal to 2', + '`.foo` must be equal to 2', 'The keyValue() rule has been deprecated and will be removed in the next major version. Use nested lazy() instead.', )); test('Scenario #5', expectMessageAndError( fn() => v::not(v::keyValue('foo', 'equals', 'bar'))->assert(['foo' => 1, 'bar' => 1]), - 'foo must not be equal to 1', + '`.foo` must not be equal to 1', 'The keyValue() rule has been deprecated and will be removed in the next major version. Use nested lazy() instead.', )); test('Scenario #6', expectMessageAndError( fn() => v::keyValue('foo', 'equals', 'bar')->assert(['bar' => 42]), - 'foo must be present', + '`.foo` must be present', 'The keyValue() rule has been deprecated and will be removed in the next major version. Use nested lazy() instead.', )); test('Scenario #7', expectMessageAndError( fn() => v::keyValue('foo', 'equals', 'bar')->assert(['foo' => 42]), - 'bar must be present', + '`.bar` must be present', 'The keyValue() rule has been deprecated and will be removed in the next major version. Use nested lazy() instead.', )); test('Scenario #8', expectMessageAndError( fn() => v::keyValue('foo', 'json', 'bar')->assert(['foo' => 42, 'bar' => 43]), - 'bar must be valid to validate foo', + '`.bar` must be valid to validate `.foo`', 'The keyValue() rule has been deprecated and will be removed in the next major version. Use nested lazy() instead.', )); test('Scenario #9', expectMessageAndError( fn() => v::keyValue('foo', 'equals', 'bar')->assert(['foo' => 1, 'bar' => 2]), - 'foo must be equal to 2', + '`.foo` must be equal to 2', 'The keyValue() rule has been deprecated and will be removed in the next major version. Use nested lazy() instead.', )); test('Scenario #10', expectMessageAndError( fn() => v::not(v::keyValue('foo', 'equals', 'bar'))->assert(['foo' => 1, 'bar' => 1]), - 'foo must not be equal to 1', + '`.foo` must not be equal to 1', 'The keyValue() rule has been deprecated and will be removed in the next major version. Use nested lazy() instead.', )); diff --git a/tests/feature/Transformers/PrefixTest.php b/tests/feature/Transformers/PrefixTest.php index 83689aaa8..9d2bded2a 100644 --- a/tests/feature/Transformers/PrefixTest.php +++ b/tests/feature/Transformers/PrefixTest.php @@ -11,9 +11,9 @@ test('Key', expectAll( fn() => v::keyEquals('foo', 12)->assert(['foo' => 10]), - 'foo must be equal to 12', - '- foo must be equal to 12', - ['foo' => 'foo must be equal to 12'], + '`.foo` must be equal to 12', + '- `.foo` must be equal to 12', + ['foo' => '`.foo` must be equal to 12'], )); test('Length', expectAll( @@ -53,9 +53,9 @@ test('Property', expectAll( fn() => v::propertyBetween('foo', 1, 3)->assert((object) ['foo' => 5]), - 'foo must be between 1 and 3', - '- foo must be between 1 and 3', - ['foo' => 'foo must be between 1 and 3'], + '`.foo` must be between 1 and 3', + '- `.foo` must be between 1 and 3', + ['foo' => '`.foo` must be between 1 and 3'], )); test('UndefOr', expectAll(