2010-12-06 19:30:56 +01: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);
|
|
|
|
|
2010-12-06 19:30:56 +01:00
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
2024-03-03 14:26:43 +01:00
|
|
|
use ArrayObject;
|
2024-01-28 01:46:21 +01:00
|
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
|
|
use PHPUnit\Framework\Attributes\Group;
|
2024-02-04 19:04:48 +01:00
|
|
|
use Respect\Validation\Test\Rules\Stub;
|
2018-01-07 14:12:55 +01:00
|
|
|
use Respect\Validation\Test\RuleTestCase;
|
2018-06-17 01:20:47 +02:00
|
|
|
use stdClass;
|
2018-01-07 14:12:55 +01:00
|
|
|
|
2024-01-28 01:46:21 +01:00
|
|
|
#[Group('rule')]
|
|
|
|
#[CoversClass(Each::class)]
|
2018-06-17 01:20:47 +02:00
|
|
|
final class EachTest extends RuleTestCase
|
2010-12-06 19:30:56 +01:00
|
|
|
{
|
2024-02-04 19:23:04 +01:00
|
|
|
/** @return iterable<array{Each, mixed}> */
|
|
|
|
public static function providerForValidInput(): iterable
|
2023-04-02 16:00:37 +02:00
|
|
|
{
|
|
|
|
return [
|
2024-02-04 19:04:48 +01:00
|
|
|
[new Each(Stub::pass(5)), [1, 2, 3, 4, 5]],
|
2024-03-03 14:26:43 +01:00
|
|
|
[new Each(Stub::pass(5)), new ArrayObject([1, 2, 3, 4, 5])],
|
2023-04-02 16:00:37 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2024-02-04 19:23:04 +01:00
|
|
|
/** @return iterable<array{Each, mixed}> */
|
|
|
|
public static function providerForInvalidInput(): iterable
|
2023-04-02 16:00:37 +02:00
|
|
|
{
|
|
|
|
return [
|
2024-03-03 14:26:43 +01:00
|
|
|
[new Each(Stub::daze()), []],
|
|
|
|
[new Each(Stub::daze()), new stdClass()],
|
2024-02-22 16:15:29 +01:00
|
|
|
[new Each(Stub::daze()), 123],
|
|
|
|
[new Each(Stub::daze()), ''],
|
|
|
|
[new Each(Stub::daze()), null],
|
|
|
|
[new Each(Stub::daze()), false],
|
2024-02-04 19:04:48 +01:00
|
|
|
[new Each(Stub::fail(5)), ['', 2, 3, 4, 5]],
|
|
|
|
[new Each(Stub::fail(5)), ['a', 2, 3, 4, 5]],
|
2024-03-03 14:26:43 +01:00
|
|
|
[new Each(Stub::fail(5)), new ArrayObject([1, 2, 3, 4, 5])],
|
|
|
|
[new Each(Stub::fail(5)), (object) ['foo' => true]],
|
2023-04-02 16:00:37 +02:00
|
|
|
];
|
|
|
|
}
|
2013-01-14 23:44:49 +01:00
|
|
|
}
|