2015-08-20 05:35:43 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2023-02-17 05:13:51 +01:00
|
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
|
|
* SPDX-License-Identifier: MIT
|
2015-08-20 05:35:43 +02:00
|
|
|
*/
|
|
|
|
|
2017-11-19 19:01:31 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2015-08-20 05:35:43 +02:00
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
2018-09-30 17:53:23 +02:00
|
|
|
use Respect\Validation\Test\RuleTestCase;
|
|
|
|
use stdClass;
|
2020-07-21 22:54:41 +02:00
|
|
|
|
2019-02-09 13:31:32 +01:00
|
|
|
use function acos;
|
2020-07-21 22:54:41 +02:00
|
|
|
|
2018-09-30 17:53:23 +02:00
|
|
|
use const INF;
|
|
|
|
use const PHP_INT_MAX;
|
2017-11-04 11:21:40 +01:00
|
|
|
|
2015-08-20 05:35:43 +02:00
|
|
|
/**
|
2018-09-30 17:53:23 +02:00
|
|
|
* @group rule
|
|
|
|
*
|
2018-07-23 20:35:14 +02:00
|
|
|
* @covers \Respect\Validation\Rules\Finite
|
2018-09-30 17:53:23 +02:00
|
|
|
*
|
|
|
|
* @author Danilo Correa <danilosilva87@gmail.com>
|
|
|
|
* @author Gabriel Caruso <carusogabriel34@gmail.com>
|
|
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
2015-08-20 05:35:43 +02:00
|
|
|
*/
|
2018-09-30 17:53:23 +02:00
|
|
|
final class FiniteTest extends RuleTestCase
|
2015-08-20 05:35:43 +02:00
|
|
|
{
|
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2015-08-20 05:35:43 +02:00
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public static function providerForValidInput(): array
|
2015-08-20 05:35:43 +02:00
|
|
|
{
|
2018-09-30 17:53:23 +02:00
|
|
|
$sut = new Finite();
|
2015-08-20 05:35:43 +02:00
|
|
|
|
2018-09-30 17:53:23 +02:00
|
|
|
return [
|
|
|
|
'integer-string' => [$sut, '123456'],
|
|
|
|
'float-string' => [$sut, '123.456'],
|
|
|
|
'zero' => [$sut, 0],
|
|
|
|
'negative integer' => [$sut, PHP_INT_MAX * -1],
|
|
|
|
'positive integer' => [$sut, PHP_INT_MAX],
|
|
|
|
'positive float' => [$sut, 1.3e100],
|
|
|
|
'negative float' => [$sut, 1.3e100 * -1],
|
|
|
|
];
|
2015-08-20 05:35:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2015-08-20 05:35:43 +02:00
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public static function providerForInvalidInput(): array
|
2015-08-20 05:35:43 +02:00
|
|
|
{
|
2018-09-30 17:53:23 +02:00
|
|
|
$sut = new Finite();
|
2015-08-20 05:35:43 +02:00
|
|
|
|
2015-10-18 03:44:47 +02:00
|
|
|
return [
|
2018-09-30 17:53:23 +02:00
|
|
|
'empty' => [$sut, ''],
|
|
|
|
'not a number' => [$sut, acos(1.01)],
|
|
|
|
'infinite' => [$sut, INF],
|
|
|
|
'negative infinite' => [$sut, INF * -1],
|
|
|
|
'array' => [$sut, []],
|
|
|
|
'object' => [$sut, new stdClass()],
|
|
|
|
'null' => [$sut, null],
|
|
|
|
'boolean false' => [$sut, false],
|
|
|
|
'boolean true' => [$sut, true],
|
2015-10-18 03:44:47 +02:00
|
|
|
];
|
2015-08-20 05:35:43 +02:00
|
|
|
}
|
|
|
|
}
|