2018-11-30 09:25:42 +01:00
|
|
|
--CREDITS--
|
|
|
|
Henrique Moody <henriquemoody@gmail.com>
|
2015-07-29 05:31:21 +02:00
|
|
|
--TEST--
|
|
|
|
setTemplate() with single validator should use template as main message
|
|
|
|
--FILE--
|
|
|
|
<?php
|
2019-02-09 11:44:33 +01:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2015-07-29 05:31:21 +02:00
|
|
|
require 'vendor/autoload.php';
|
|
|
|
|
2015-10-23 12:33:37 +02:00
|
|
|
use Respect\Validation\Exceptions\NestedValidationException;
|
2015-10-18 03:44:47 +02:00
|
|
|
use Respect\Validation\Validator;
|
2015-07-29 05:31:21 +02:00
|
|
|
|
2016-04-07 19:11:40 +02:00
|
|
|
$rule = Validator::callback('is_int')->setTemplate('{{name}} is not tasty');
|
2015-07-29 05:31:21 +02:00
|
|
|
try {
|
2016-04-07 19:11:40 +02:00
|
|
|
$rule->assert('something');
|
|
|
|
} catch (NestedValidationException $e) {
|
2018-05-22 13:42:10 +02:00
|
|
|
echo $e->getMessage();
|
2016-04-07 19:11:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
echo PHP_EOL;
|
|
|
|
|
|
|
|
try {
|
|
|
|
$rule->check('something');
|
2015-10-23 12:33:37 +02:00
|
|
|
} catch (NestedValidationException $e) {
|
2018-05-22 13:42:10 +02:00
|
|
|
echo $e->getMessage();
|
2015-07-29 05:31:21 +02:00
|
|
|
}
|
|
|
|
?>
|
2018-12-19 18:05:58 +01:00
|
|
|
--EXPECT--
|
2015-07-29 05:31:21 +02:00
|
|
|
"something" is not tasty
|
2016-04-07 19:11:40 +02:00
|
|
|
"something" is not tasty
|