mirror of
https://github.com/Respect/Validation.git
synced 2026-03-16 07:15:45 +01:00
When we created this rule in version 1.0 in 2015, PHP was in version 5.6, and the `is_iterable()` function didn't exist. Only in version 7.1, released at the end of 2016, was the pseudo-type "iterable" introduced to PHP. This old "IterableType" rule is almost obsolete. Still, I decided to keep it because it is possible to use foreach in any object, as it will iterate over its public properties. I did rename the rule because that makes more sense. An "IterableType" rule should guarantee that the input type is the real-(pseudo)-iterable. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
47 lines
1 KiB
PHP
47 lines
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 ArrayIterator;
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
use PHPUnit\Framework\Attributes\Group;
|
|
use Respect\Validation\Test\RuleTestCase;
|
|
use stdClass;
|
|
|
|
#[Group('rule')]
|
|
#[CoversClass(IterableVal::class)]
|
|
final class IterableValTest extends RuleTestCase
|
|
{
|
|
/** @return iterable<array{IterableVal, mixed}> */
|
|
public static function providerForValidInput(): iterable
|
|
{
|
|
$rule = new IterableVal();
|
|
|
|
return [
|
|
[$rule, [1, 2, 3]],
|
|
[$rule, new stdClass()],
|
|
[$rule, new ArrayIterator()],
|
|
];
|
|
}
|
|
|
|
/** @return iterable<array{IterableVal, mixed}> */
|
|
public static function providerForInvalidInput(): iterable
|
|
{
|
|
$rule = new IterableVal();
|
|
|
|
return [
|
|
[$rule, 3],
|
|
[$rule, 'asdf'],
|
|
[$rule, 9.85],
|
|
[$rule, null],
|
|
[$rule, true],
|
|
];
|
|
}
|
|
}
|