respect-validation/tests/unit/Rules/NotTest.php

49 lines
1.3 KiB
PHP
Raw Normal View History

<?php
2015-06-08 16:47:14 +02:00
/*
* 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;
2012-05-17 21:16:45 +02:00
#[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))), []];
}
2016-01-29 22:50:27 +01:00
/** @return iterable<string, array{Not, mixed}> */
public static function providerForInvalidInput(): iterable
2016-01-29 22:50:27 +01:00
{
yield 'invert pass' => [new Not(Stub::pass(1)), []];
yield 'invert fail x2' => [new Not(new Not(Stub::fail(1))), []];
2016-01-29 22:50:27 +01:00
}
2012-05-17 20:51:49 +02:00
}