2011-04-28 01:41:12 +02:00
|
|
|
<?php
|
2015-06-08 16:47:14 +02:00
|
|
|
|
2015-06-08 17:09:25 +02:00
|
|
|
/*
|
2023-02-17 05:13:51 +01:00
|
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
|
|
* SPDX-License-Identifier: MIT
|
2015-06-08 17:09:25 +02:00
|
|
|
*/
|
|
|
|
|
2017-11-19 19:01:31 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2011-04-28 01:41:12 +02:00
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
2024-01-28 01:46:21 +01:00
|
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
|
|
use PHPUnit\Framework\Attributes\Group;
|
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
2024-02-13 11:58:57 +01:00
|
|
|
use Respect\Validation\Test\Rules\Stub;
|
|
|
|
use Respect\Validation\Test\RuleTestCase;
|
2012-05-17 21:16:45 +02:00
|
|
|
|
2024-01-28 01:46:21 +01:00
|
|
|
#[Group('rule')]
|
|
|
|
#[CoversClass(Not::class)]
|
2024-02-13 11:58:57 +01:00
|
|
|
final class NotTest extends RuleTestCase
|
2011-04-28 01:41:12 +02:00
|
|
|
{
|
2024-01-28 01:46:21 +01:00
|
|
|
#[Test]
|
2024-02-13 11:58:57 +01:00
|
|
|
public function shouldInvertTheResultOfWrappedRule(): void
|
2011-04-28 01:41:12 +02:00
|
|
|
{
|
2024-02-13 11:58:57 +01:00
|
|
|
$wrapped = Stub::fail(2);
|
2024-02-12 19:51:30 +01:00
|
|
|
|
2024-02-13 11:58:57 +01:00
|
|
|
$rule = new Not($wrapped);
|
2011-04-28 01:41:12 +02:00
|
|
|
|
2024-02-13 11:58:57 +01:00
|
|
|
self::assertEquals(
|
|
|
|
$rule->evaluate('input'),
|
2024-03-26 00:16:09 +01:00
|
|
|
$wrapped->evaluate('input')->withPrefixedId('not')->withInvertedMode()
|
2024-02-13 11:58:57 +01:00
|
|
|
);
|
2011-04-28 01:41:12 +02:00
|
|
|
}
|
|
|
|
|
2024-02-13 11:58:57 +01:00
|
|
|
/** @return iterable<string, array{Not, mixed}> */
|
|
|
|
public static function providerForValidInput(): iterable
|
2011-04-28 01:41:12 +02:00
|
|
|
{
|
2024-02-13 11:58:57 +01:00
|
|
|
yield 'invert fail' => [new Not(Stub::fail(1)), []];
|
|
|
|
yield 'invert success x2' => [new Not(new Not(Stub::pass(1))), []];
|
2011-04-28 01:41:12 +02:00
|
|
|
}
|
2016-01-29 22:50:27 +01:00
|
|
|
|
2024-02-13 11:58:57 +01:00
|
|
|
/** @return iterable<string, array{Not, mixed}> */
|
|
|
|
public static function providerForInvalidInput(): iterable
|
2016-01-29 22:50:27 +01:00
|
|
|
{
|
2024-02-13 11:58:57 +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
|
|
|
}
|