mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 07:45:45 +01:00
Because now we have the concept of attributes in PHP, the rule with the name "Attribute" makes no sense because it doesn't validate attributes but properties. In the future, it might be possible that Validation will have a rule called "Attribute" to validate PHP attributes. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
44 lines
1.6 KiB
PHP
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 PropertyException('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 PropertyException('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());
|
|
}
|
|
}
|