respect-validation/tests/integration/translator-assert.phpt
Henrique Moody 97b243daa1
Allow building rules using prefixes
Although helpful, the changes in the Min, Max, and Length rules made
using those rules more verbose. This commit will simplify their use by
allowing users to use them as prefixes.

Because I was creating prefixes for those rules, I made other cool
prefixes. Doing that is scary because it will generate more code to
support, and I would have liked to avoid that. However, that's a
valuable addition, and it's worth the risk.

I might reconsider that in the future, but for now, that looks like a
good idea.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-03-24 16:58:24 +01:00

39 lines
1.5 KiB
PHP

--FILE--
<?php
declare(strict_types=1);
require 'vendor/autoload.php';
use Respect\Validation\Factory;
use Respect\Validation\Validator;
Factory::setDefaultInstance(
(new Factory())
->withTranslator(static function (string $message): string {
return [
'All of the required rules must pass for {{name}}'
=> 'Todas as regras requeridas devem passar para {{name}}',
'The length of'
=> 'O comprimento de',
'{{name}} must be of type string'
=> '{{name}} deve ser do tipo string',
'{{name}} must be between {{minValue}} and {{maxValue}}'
=> '{{name}} deve possuir de {{minValue}} a {{maxValue}} caracteres',
'{{name}} must be between {{minValue}} and {{maxValue}}'
=> '{{name}} deve possuir de {{minValue}} a {{maxValue}} caracteres',
'{{name}} must be a valid telephone number for country {{countryName|trans}}'
=> '{{name}} deve ser um número de telefone válido para o país {{countryName|trans}}',
'United States' => 'Estados Unidos',
][$message] ?? $message;
})
);
exceptionFullMessage(static fn() => Validator::stringType()->lengthBetween(2, 15)->phone('US')->assert(0));
?>
--EXPECT--
- Todas as regras requeridas devem passar para 0
- 0 deve ser do tipo string
- O comprimento de 0 deve possuir de 2 a 15 caracteres
- 0 deve ser um número de telefone válido para o país Estados Unidos