respect-validation/tests/integration/lib/helpers.php
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

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;
}
}