mirror of
https://github.com/Respect/Validation.git
synced 2026-03-16 07:15:45 +01:00
Since I updated the validation engine[1], it became possible to create
results with siblings. This commit changes the "UndefOr", allowing it to
create a result with a sibling when possible. That will improve the
clarity of the error message.
[1]: 238f2d506a
51 lines
1.8 KiB
PHP
51 lines
1.8 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
use PHPUnit\Framework\Attributes\Group;
|
|
use Respect\Validation\Test\Rules\Stub;
|
|
use Respect\Validation\Test\RuleTestCase;
|
|
use stdClass;
|
|
|
|
#[Group('rule')]
|
|
#[CoversClass(UndefOr::class)]
|
|
final class UndefOrTest extends RuleTestCase
|
|
{
|
|
/** @return iterable<string, array{UndefOr, mixed}> */
|
|
public static function providerForValidInput(): iterable
|
|
{
|
|
yield 'null' => [new UndefOr(Stub::pass(1)), null];
|
|
yield 'empty string' => [new UndefOr(Stub::pass(1)), ''];
|
|
yield 'null with failing rule' => [new UndefOr(Stub::fail(1)), null];
|
|
yield 'empty string with failing rule' => [new UndefOr(Stub::fail(1)), ''];
|
|
yield 'not optional' => [new UndefOr(Stub::pass(1)), 42];
|
|
}
|
|
|
|
/** @return iterable<array{UndefOr, mixed}> */
|
|
public static function providerForInvalidInput(): iterable
|
|
{
|
|
yield [new UndefOr(Stub::fail(1)), 1];
|
|
yield [new UndefOr(Stub::fail(1)), []];
|
|
yield [new UndefOr(Stub::fail(1)), ' '];
|
|
yield [new UndefOr(Stub::fail(1)), 0];
|
|
yield [new UndefOr(Stub::fail(1)), '0'];
|
|
yield [new UndefOr(Stub::fail(1)), 0];
|
|
yield [new UndefOr(Stub::fail(1)), '0.0'];
|
|
yield [new UndefOr(Stub::fail(1)), false];
|
|
yield [new UndefOr(Stub::fail(1)), ['']];
|
|
yield [new UndefOr(Stub::fail(1)), [' ']];
|
|
yield [new UndefOr(Stub::fail(1)), [0]];
|
|
yield [new UndefOr(Stub::fail(1)), ['0']];
|
|
yield [new UndefOr(Stub::fail(1)), [false]];
|
|
yield [new UndefOr(Stub::fail(1)), [[''], [0]]];
|
|
yield [new UndefOr(Stub::fail(1)), new stdClass()];
|
|
}
|
|
}
|