respect-validation/tests/unit/Validators/NotTest.php
Henrique Moody 81310cc4d9
Rename namespace Rules to Validators
Since that namespace contains our “validators”, naming it as such makes
much more sense.
2026-01-05 17:36:35 +01:00

49 lines
1.4 KiB
PHP

<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Validators;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use Respect\Validation\Id;
use Respect\Validation\Test\RuleTestCase;
use Respect\Validation\Test\Validators\Stub;
#[Group('validator')]
#[CoversClass(Not::class)]
final class NotTest extends RuleTestCase
{
#[Test]
public function shouldInvertTheResultOfWrappedRule(): void
{
$wrapped = Stub::fail(2);
$validator = new Not($wrapped);
self::assertEquals(
$validator->evaluate('input'),
$wrapped->evaluate('input')->withId(new Id('notStub'))->withToggledModeAndValidation(),
);
}
/** @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))), []];
}
}