respect-validation/tests/unit/Rules/NotTest.php
Henrique Moody eeaea466ac
Prefix IDs of wrapper rule results
Because some rules work more as a prefix, it makes sense to prefix their
result ID. That will allow for a more intuitive templating, especially
when using those rules as prefixes.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-03-26 01:23:29 +01:00

49 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 PHPUnit\Framework\Attributes\Test;
use Respect\Validation\Test\Rules\Stub;
use Respect\Validation\Test\RuleTestCase;
#[Group('rule')]
#[CoversClass(Not::class)]
final class NotTest extends RuleTestCase
{
#[Test]
public function shouldInvertTheResultOfWrappedRule(): void
{
$wrapped = Stub::fail(2);
$rule = new Not($wrapped);
self::assertEquals(
$rule->evaluate('input'),
$wrapped->evaluate('input')->withPrefixedId('not')->withInvertedMode()
);
}
/** @return iterable<string, array{Not, mixed}> */
public static function providerForValidInput(): iterable
{
yield 'invert fail' => [new Not(Stub::fail(1)), []];
yield 'invert success x2' => [new Not(new Not(Stub::pass(1))), []];
}
/** @return iterable<string, array{Not, mixed}> */
public static function providerForInvalidInput(): iterable
{
yield 'invert pass' => [new Not(Stub::pass(1)), []];
yield 'invert fail x2' => [new Not(new Not(Stub::fail(1))), []];
}
}