respect-validation/tests/unit/Exceptions/NestedValidationExceptionTest.php
Henrique Moody 00f61b9bdc
Move message formatting out of ValidationException
There should not be too much code in the ValidationException. It is hard
to test and debug code in exceptions because PHP does not trace further
than their constructor.

This commit will move the message formatting from ValidationException
into a Formatter class (inside a Message namespace).

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-12 13:45:38 +02:00

53 lines
1.7 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 Respect\Validation\Message\Formatter;
use Respect\Validation\Test\TestCase;
/**
* @covers \Respect\Validation\Exceptions\NestedValidationException
*
* @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
* @author Gabriel Caruso <carusogabriel34@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
*/
final class NestedValidationExceptionTest extends TestCase
{
/**
* @test
*/
public function getChildrenShouldReturnExceptionAddedByAddRelated(): void
{
$composite = new AttributeException('input', 'id', [], new Formatter('strval'));
$node = new IntValException('input', 'id', [], new Formatter('strval'));
$composite->addChild($node);
self::assertCount(1, $composite->getChildren());
self::assertContainsOnly(IntValException::class, $composite->getChildren());
}
/**
* @test
*/
public function addingTheSameInstanceShouldAddJustOneSingleReference(): void
{
$composite = new AttributeException('input', 'id', [], new Formatter('strval'));
$node = new IntValException('input', 'id', [], new Formatter('strval'));
$composite->addChild($node);
$composite->addChild($node);
$composite->addChild($node);
self::assertCount(1, $composite->getChildren());
self::assertContainsOnly(IntValException::class, $composite->getChildren());
}
}