respect-validation/tests/unit/Rules/NotTest.php
Henrique Moody 2ee7509c2e
Make data providers static
From PHPUnit 10, all data providers need to be static. This commit will
make migrating from version 9 to 10 a bit easier.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2023-04-03 17:20:31 +02:00

118 lines
3.1 KiB
PHP

<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Exceptions\ValidationException;
use Respect\Validation\Test\TestCase;
use Respect\Validation\Validatable;
use Respect\Validation\Validator;
/**
* @group rule
* @covers \Respect\Validation\Exceptions\NotException
* @covers \Respect\Validation\Rules\Not
*
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Caio César Tavares <caiotava@gmail.com>
* @author Gabriel Caruso <carusogabriel34@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
*/
final class NotTest extends TestCase
{
/**
* @doesNotPerformAssertions
*
* @dataProvider providerForValidNot
*
* @test
*
* @param mixed $input
*/
public function not(Validatable $rule, $input): void
{
$not = new Not($rule);
$not->assert($input);
}
/**
* @dataProvider providerForInvalidNot
*
* @test
*
* @param mixed $input
*/
public function notNotHaha(Validatable $rule, $input): void
{
$not = new Not($rule);
$this->expectException(ValidationException::class);
$not->assert($input);
}
/**
* @dataProvider providerForSetName
*
* @test
*/
public function notSetName(Validatable $rule): void
{
$not = new Not($rule);
$not->setName('Foo');
self::assertEquals('Foo', $not->getName());
self::assertEquals('Foo', $not->getNegatedRule()->getName());
}
/**
* @return mixed[][]
*/
public static function providerForValidNot(): array
{
return [
[new IntVal(), ''],
[new IntVal(), 'aaa'],
[new AllOf(new NoWhitespace(), new Digit()), 'as df'],
[new AllOf(new NoWhitespace(), new Digit()), '12 34'],
[new AllOf(new AllOf(new NoWhitespace(), new Digit())), '12 34'],
[new AllOf(new NoneOf(new NumericVal(), new IntVal())), 13.37],
[new NoneOf(new NumericVal(), new IntVal()), 13.37],
[Validator::noneOf(Validator::numericVal(), Validator::intVal()), 13.37],
];
}
/**
* @return mixed[][]
*/
public static function providerForInvalidNot(): array
{
return [
[new IntVal(), 123],
[new AllOf(new AnyOf(new NumericVal(), new IntVal())), 13.37],
[new AnyOf(new NumericVal(), new IntVal()), 13.37],
[Validator::anyOf(Validator::numericVal(), Validator::intVal()), 13.37],
];
}
/**
* @return Validatable[][]
*/
public static function providerForSetName(): array
{
return [
'non-allOf' => [new IntVal()],
'allOf' => [new AllOf(new NumericVal(), new IntVal())],
'not' => [new Not(new Not(new IntVal()))],
'allOf with name' => [Validator::intVal()->setName('Bar')],
'noneOf' => [Validator::noneOf(Validator::numericVal(), Validator::intVal())],
];
}
}