respect-validation/tests/integration/translator-assert.phpt
Henrique Moody 8a7bc1ab7a
Improve readability of integration tests
The integration tests use the same pattern to test exception messages.
With my changes, we won't validate which exception we throw in those
tests, but matching the message is enough. I created three functions to
replace most of those tests.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2023-04-01 07:40:42 +02:00

32 lines
1 KiB
PHP

--CREDITS--
Henrique Moody <henriquemoody@gmail.com>
--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}}',
'{{name}} must be of type string'
=> '{{name}} deve ser do tipo string',
'{{name}} must have a length between {{minValue}} and {{maxValue}}'
=> '{{name}} deve possuir de {{minValue}} a {{maxValue}} caracteres',
][$message];
})
);
exceptionFullMessage(static fn() => Validator::stringType()->length(2, 15)->assert(0));
?>
--EXPECT--
- Todas as regras requeridas devem passar para 0
- 0 deve ser do tipo string
- 0 deve possuir de 2 a 15 caracteres