respect-validation/tests/unit/Exceptions/NestedValidationExceptionTest.php
Henrique Moody 12c145756c
Upgrade "phpunit/phpunit"
This commit also replaces PHPUnit annotations with attributes.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-01-28 14:16:52 +01:00

44 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 PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use Respect\Validation\Message\Formatter;
use Respect\Validation\Message\Stringifier\KeepOriginalStringName;
use Respect\Validation\Test\TestCase;
#[Group('core')]
#[CoversClass(NestedValidationException::class)]
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());
}
}