mirror of
https://github.com/Respect/Validation.git
synced 2026-03-14 22:35:45 +01:00
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>
41 lines
936 B
PHP
41 lines
936 B
PHP
<?php
|
|
|
|
/*
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Respect\Validation\Exceptions\NestedValidationException;
|
|
use Respect\Validation\Exceptions\ValidationException;
|
|
|
|
function exceptionMessage(callable $callable): void
|
|
{
|
|
try {
|
|
$callable();
|
|
} catch (ValidationException $exception) {
|
|
echo $exception->getMessage() . PHP_EOL;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param array<string, array<string, string>> $templates
|
|
*/
|
|
function exceptionMessages(callable $callable, array $templates = []): void
|
|
{
|
|
try {
|
|
$callable();
|
|
} catch (NestedValidationException $exception) {
|
|
print_r($exception->getMessages($templates));
|
|
}
|
|
}
|
|
|
|
function exceptionFullMessage(callable $callable): void
|
|
{
|
|
try {
|
|
$callable();
|
|
} catch (NestedValidationException $exception) {
|
|
echo $exception->getFullMessage() . PHP_EOL;
|
|
}
|
|
}
|