mirror of
https://github.com/Respect/Validation.git
synced 2026-03-16 07:15:45 +01:00
There are a few "problems" with the current engine: - Allowing each rule to execute assert() and check() means duplication in some cases. - Because we use exceptions to assert/check, we can only invert a validation (with Not) if there are errors. That means that we have limited granularity control. - There is a lot of logic in the exceptions. That means that even after it throws an exception, something could still happen. We're stable on that front, but I want to simplify them. Besides, debugging exception code is painful because the stack trace does not go beyond the exception. Apart from that, there are many limitations with templating, and working that out in the current implementation makes it much harder. These changes will improve the library in many aspects, but they will also change the behavior and break backward compatibility. However, that's a price I'm willing to pay for the improvements we'll have. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
42 lines
1.3 KiB
PHP
42 lines
1.3 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 function rand;
|
|
|
|
#[Group('rule')]
|
|
#[CoversClass(When::class)]
|
|
final class WhenTest extends RuleTestCase
|
|
{
|
|
/** @return array<array{When, mixed}> */
|
|
public static function providerForValidInput(): array
|
|
{
|
|
return [
|
|
'when fail, then pass' => [new When(Stub::pass(1), Stub::pass(1)), rand()],
|
|
'when pass, then pass, else daze' => [new When(Stub::pass(1), Stub::pass(1), Stub::daze()), rand()],
|
|
'when fail, then daze, else pass' => [new When(Stub::fail(1), Stub::daze(), Stub::pass(1)), rand()],
|
|
];
|
|
}
|
|
|
|
/** @return array<array{When, mixed}> */
|
|
public static function providerForInvalidInput(): array
|
|
{
|
|
return [
|
|
'when pass, then fail' => [new When(Stub::pass(1), Stub::fail(1)), rand()],
|
|
'when pass, then fail, else daze' => [new When(Stub::pass(1), Stub::fail(1), Stub::daze()), rand()],
|
|
'when fail, then daze, else fail' => [new When(Stub::fail(1), Stub::daze(), Stub::fail(1)), rand()],
|
|
];
|
|
}
|
|
}
|