respect-validation/tests/integration/get_messages_should_include_all_validation_messages_in_a_chain.phpt
Olumide Samson 029fa7fe73
Remove "Key" prefix from KeyException message
Most Validation errors are sent to Users/Visitors or Clients and as such
might not need to know it was a Key their inputs are being validated
upon.

Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2020-10-04 11:42:51 +02:00

42 lines
993 B
PHP

--CREDITS--
Henrique Moody <henriquemoody@gmail.com>
--TEST--
getMessages() should include all validation messages in a chain
--FILE--
<?php
declare(strict_types=1);
date_default_timezone_set('UTC');
require 'vendor/autoload.php';
use Respect\Validation\Exceptions\NestedValidationException;
use Respect\Validation\Validator;
try {
$input = [
'username' => 'u',
'birthdate' => 'Not a date',
'password' => '',
];
Validator::create()
->key('username', Validator::length(2, 32))
->key('birthdate', Validator::dateTime())
->key('password', Validator::notEmpty())
->key('email', Validator::email())
->assert($input);
} catch (NestedValidationException $e) {
print_r($e->getMessages());
}
?>
--EXPECT--
Array
(
[username] => username must have a length between 2 and 32
[birthdate] => birthdate must be a valid date/time
[password] => password must not be empty
[email] => email must be present
)