respect-validation/tests/unit/Exceptions/NestedValidationExceptionTest.php
Henrique Moody 9a13c9fb03
Update coding standards
This change will bring many breaking changes. The good thing is that we
can finally use more modern resources available in PHP.

I can imagine that's not a popular change since it will bring many
breaking changes to users, but we shouldn't be stuck in time because of
that. Using some of those features will make it easier to contribute to
the project. At least, I hope so.

There are still some useless doc-blocks, and we're not using "readonly"
properties when we could. I aim to send those changes soon.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-01-28 00:22:41 +01:00

46 lines
1.6 KiB
PHP

<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
use Respect\Validation\Message\Formatter;
use Respect\Validation\Message\Stringifier\KeepOriginalStringName;
use Respect\Validation\Test\TestCase;
/**
* @covers \Respect\Validation\Exceptions\NestedValidationException
*/
final class NestedValidationExceptionTest extends TestCase
{
/**
* @test
*/
public function getChildrenShouldReturnExceptionAddedByAddRelated(): void
{
$composite = new AttributeException('input', 'id', [], new Formatter('strval', new KeepOriginalStringName()));
$node = new IntValException('input', 'id', [], new Formatter('strval', new KeepOriginalStringName()));
$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', new KeepOriginalStringName()));
$node = new IntValException('input', 'id', [], new Formatter('strval', new KeepOriginalStringName()));
$composite->addChild($node);
$composite->addChild($node);
$composite->addChild($node);
self::assertCount(1, $composite->getChildren());
self::assertContainsOnly(IntValException::class, $composite->getChildren());
}
}