2010-12-07 20:17:43 +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-07 20:17:43 +01:00
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
2024-01-28 01:46:21 +01:00
|
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
|
|
use PHPUnit\Framework\Attributes\Group;
|
2018-06-22 04:19:01 +02:00
|
|
|
use Respect\Validation\Test\RuleTestCase;
|
2020-05-19 18:14:07 +02:00
|
|
|
use stdClass;
|
2020-07-21 22:54:41 +02:00
|
|
|
|
2019-02-17 19:41:55 +01:00
|
|
|
use const PHP_INT_MAX;
|
2017-11-04 11:21:40 +01:00
|
|
|
|
2024-01-28 01:46:21 +01:00
|
|
|
#[Group('rule')]
|
|
|
|
#[CoversClass(IntVal::class)]
|
2018-06-22 04:19:01 +02:00
|
|
|
final class IntValTest extends RuleTestCase
|
2010-12-07 20:17:43 +01:00
|
|
|
{
|
2024-02-04 19:23:04 +01:00
|
|
|
/** @return iterable<array{IntVal, mixed}> */
|
|
|
|
public static function providerForValidInput(): iterable
|
2010-12-07 20:17:43 +01:00
|
|
|
{
|
2018-06-22 04:19:01 +02:00
|
|
|
$rule = new IntVal();
|
2010-12-07 20:17:43 +01:00
|
|
|
|
2015-10-18 03:44:47 +02:00
|
|
|
return [
|
2018-06-22 04:19:01 +02:00
|
|
|
[$rule, 16],
|
|
|
|
[$rule, '165'],
|
|
|
|
[$rule, 123456],
|
|
|
|
[$rule, PHP_INT_MAX],
|
2018-08-01 22:08:30 +02:00
|
|
|
[$rule, '06'],
|
2020-05-19 18:14:07 +02:00
|
|
|
[$rule, '09'],
|
2018-08-01 22:08:30 +02:00
|
|
|
[$rule, '0'],
|
2020-05-19 18:14:07 +02:00
|
|
|
[$rule, '00'],
|
|
|
|
[$rule, 0b101010],
|
|
|
|
[$rule, 0x2a],
|
|
|
|
[$rule, '089'],
|
2021-05-05 13:24:38 +02:00
|
|
|
[$rule, -42],
|
|
|
|
[$rule, '-42'],
|
|
|
|
[$rule, '-042'],
|
2015-10-18 03:44:47 +02:00
|
|
|
];
|
2010-12-07 20:17:43 +01:00
|
|
|
}
|
|
|
|
|
2024-02-04 19:23:04 +01:00
|
|
|
/** @return iterable<array{IntVal, mixed}> */
|
|
|
|
public static function providerForInvalidInput(): iterable
|
2010-12-07 20:17:43 +01:00
|
|
|
{
|
2018-06-22 04:19:01 +02:00
|
|
|
$rule = new IntVal();
|
|
|
|
|
2015-10-18 03:44:47 +02:00
|
|
|
return [
|
2018-06-22 04:19:01 +02:00
|
|
|
[$rule, ''],
|
2020-05-19 18:14:07 +02:00
|
|
|
[$rule, new stdClass()],
|
|
|
|
[$rule, []],
|
2018-06-22 04:19:01 +02:00
|
|
|
[$rule, null],
|
|
|
|
[$rule, 'a'],
|
|
|
|
[$rule, '1.0'],
|
|
|
|
[$rule, 1.0],
|
|
|
|
[$rule, ' '],
|
2018-08-01 20:20:11 +02:00
|
|
|
[$rule, true],
|
|
|
|
[$rule, false],
|
2018-06-22 04:19:01 +02:00
|
|
|
[$rule, 'Foo'],
|
|
|
|
[$rule, '1.44'],
|
|
|
|
[$rule, 1e-5],
|
2020-05-19 18:14:07 +02:00
|
|
|
[$rule, '089ab'],
|
2015-10-18 03:44:47 +02:00
|
|
|
];
|
2010-12-07 20:17:43 +01:00
|
|
|
}
|
2013-01-14 23:44:49 +01:00
|
|
|
}
|