mirror of
https://github.com/Respect/Validation.git
synced 2024-06-26 17:20:16 +02:00
This change will also make the composite-based rules require at least two rules in their constructor because those rules do not make sense with only one rule. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
66 lines
2.3 KiB
PHP
66 lines
2.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\Exceptions\InvalidRuleConstructorException;
|
|
use Respect\Validation\Test\RuleTestCase;
|
|
|
|
#[Group('rule')]
|
|
#[CoversClass(ContainsAny::class)]
|
|
final class ContainsAnyTest extends RuleTestCase
|
|
{
|
|
#[Test]
|
|
public function itShouldThrowAnExceptionWhenThereAreNoNeedles(): void
|
|
{
|
|
$this->expectException(InvalidRuleConstructorException::class);
|
|
$this->expectExceptionMessage('At least one value must be provided');
|
|
|
|
// @phpstan-ignore-next-line
|
|
new ContainsAny([]);
|
|
}
|
|
|
|
/** @return iterable<array{ContainsAny, mixed}> */
|
|
public static function providerForValidInput(): iterable
|
|
{
|
|
return [
|
|
[new ContainsAny(['Something', 'Else']), 'something else'],
|
|
[new ContainsAny([true]), [1, 2, 3]],
|
|
[new ContainsAny([true], true), [true]],
|
|
[new ContainsAny(['1']), [1, 2, 3]],
|
|
[new ContainsAny([1], true), [1, 2, 3]],
|
|
[new ContainsAny(['word', '@', '/']), 'lorem ipsum @ word'],
|
|
[new ContainsAny(['foo', 'qux']), 'foobarbaz'],
|
|
[new ContainsAny(['1']), ['foo', 1]],
|
|
[new ContainsAny(['foo', true]), ['foo', 'bar']],
|
|
];
|
|
}
|
|
|
|
/** @return iterable<array{ContainsAny, mixed}> */
|
|
public static function providerForInvalidInput(): iterable
|
|
{
|
|
return [
|
|
[new ContainsAny(['foo']), ['bar', 'baz']],
|
|
[new ContainsAny(['foo', 'bar']), ['baz', 'qux']],
|
|
[new ContainsAny(['foo', 'bar']), ['FOO', 'BAR']],
|
|
[new ContainsAny(['foo'], true), ['bar', 'baz']],
|
|
[new ContainsAny(['foo', 'bar'], true), ['FOO', 'BAR']],
|
|
[new ContainsAny(['whatever']), ''],
|
|
[new ContainsAny(['']), 'whatever'],
|
|
[new ContainsAny([false]), ''],
|
|
[new ContainsAny(['foo', 'qux']), 'barbaz'],
|
|
[new ContainsAny([1, 2, 3], true), ['1', '2', '3']],
|
|
[new ContainsAny(['word', '@', '/']), 'lorem ipsum'],
|
|
];
|
|
}
|
|
}
|