respect-validation/tests/unit/Rules/FiniteTest.php

69 lines
1.6 KiB
PHP
Raw Normal View History

2015-08-20 05:35:43 +02:00
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
2015-08-20 05:35:43 +02:00
*/
declare(strict_types=1);
2015-08-20 05:35:43 +02:00
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
use stdClass;
use function acos;
use const INF;
use const PHP_INT_MAX;
2017-11-04 11:21:40 +01:00
2015-08-20 05:35:43 +02:00
/**
* @group rule
*
* @covers \Respect\Validation\Rules\Finite
*
* @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
*/
final class FiniteTest extends RuleTestCase
2015-08-20 05:35:43 +02:00
{
/**
* {@inheritDoc}
2015-08-20 05:35:43 +02:00
*/
public static function providerForValidInput(): array
2015-08-20 05:35:43 +02:00
{
$sut = new Finite();
2015-08-20 05:35:43 +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
}
/**
* {@inheritDoc}
2015-08-20 05:35:43 +02:00
*/
public static function providerForInvalidInput(): array
2015-08-20 05:35:43 +02:00
{
$sut = new Finite();
2015-08-20 05:35:43 +02:00
2015-10-18 03:44:47 +02:00
return [
'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
}
}