mirror of
https://github.com/Respect/Validation.git
synced 2026-03-16 07:15:45 +01:00
Due to this change it was possible to identify that NotEmptyException, and NotOptionalException where not working as they should. A fix was made along with this commit.
76 lines
2.1 KiB
PHP
76 lines
2.1 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Respect/Validation.
|
|
*
|
|
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
|
*
|
|
* For the full copyright and license information, please view the "LICENSE.md"
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Validation\Exceptions;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class ValidationExceptionTest extends TestCase
|
|
{
|
|
public function testItImplementsExceptionInterface(): void
|
|
{
|
|
$validationException = new ValidationException();
|
|
self::assertInstanceOf(ExceptionInterface::class, $validationException);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerForFormat
|
|
*/
|
|
public function testFormatShouldReplacePlaceholdersProperly($template, $result, $vars): void
|
|
{
|
|
self::assertEquals(
|
|
$result,
|
|
ValidationException::format($template, $vars)
|
|
);
|
|
}
|
|
|
|
public function testGetMainMessageShouldApplyTemplatePlaceholders(): void
|
|
{
|
|
$sampleValidationException = new ValidationException();
|
|
$sampleValidationException->configure('foo', ['bar' => 1, 'baz' => 2]);
|
|
$sampleValidationException->setTemplate('{{name}} {{bar}} {{baz}}');
|
|
self::assertEquals(
|
|
'foo 1 2',
|
|
$sampleValidationException->getMainMessage()
|
|
);
|
|
}
|
|
|
|
public function testSettingTemplates(): void
|
|
{
|
|
$x = new ValidationException();
|
|
$x->configure('bar');
|
|
$x->setTemplate('foo');
|
|
self::assertEquals('foo', $x->getTemplate());
|
|
}
|
|
|
|
public function providerForFormat()
|
|
{
|
|
return [
|
|
[
|
|
'{{foo}} {{bar}} {{baz}}',
|
|
'"hello" "world" "respect"',
|
|
['foo' => 'hello', 'bar' => 'world', 'baz' => 'respect'],
|
|
],
|
|
[
|
|
'{{foo}} {{bar}} {{baz}}',
|
|
'"hello" {{bar}} "respect"',
|
|
['foo' => 'hello', 'baz' => 'respect'],
|
|
],
|
|
[
|
|
'{{foo}} {{bar}} {{baz}}',
|
|
'"hello" {{bar}} "respect"',
|
|
['foo' => 'hello', 'bot' => 111, 'baz' => 'respect'],
|
|
],
|
|
];
|
|
}
|
|
}
|