respect-validation/tests/integration/readme/getting_messages_as_an_array.phpt
Henrique Moody fefe905e0b
Include "__root__" when getting message as an array
When converting an object into an array, we exclude the message root
message from it. Since we're using a convention to template those
messages as an array, we could also use the same convention to return
those messages.

While working on it, I noticed that the name "__self__" wasn't
reflecting what that really meant, so I renamed it "__root__" because it
better reflects the meaning of those messages/templates.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-03-25 22:38:19 +01:00

21 lines
625 B
PHP

--FILE--
<?php
declare(strict_types=1);
require 'vendor/autoload.php';
use Respect\Validation\Validator as v;
exceptionMessages(
static fn() => v::alnum()->noWhitespace()->lengthBetween(1, 15)->assert('really messed up screen#name')
);
?>
--EXPECT--
[
'__root__' => 'All of the required rules must pass for "really messed up screen#name"',
'alnum' => '"really messed up screen#name" must contain only letters (a-z) and digits (0-9)',
'noWhitespace' => '"really messed up screen#name" must not contain whitespace',
'length' => 'The length of "really messed up screen#name" must be between 1 and 15',
]