respect-validation/tests/unit/Rules/FiniteTest.php
Henrique Moody 2d7e2ea48f
Add "respect/stringifier" as dependency
Due to this change it was possible to identify that NotEmptyException,
and NotOptionalException where not working as they should. A fix was
made along with this commit.
2018-01-06 14:07:03 +01:00

79 lines
1.6 KiB
PHP

<?php
/*
* This file is part of Respect/Validation.
*
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
*
* For the full copyright and license information, please view the "LICENSE.md"
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Respect\Validation\Rules;
use PHPUnit\Framework\TestCase;
/**
* @group rule
* @covers \Respect\Validation\Rules\Finite
* @covers \Respect\Validation\Exceptions\FiniteException
*/
class FiniteTest extends TestCase
{
protected $rule;
protected function setUp(): void
{
$this->rule = new Finite();
}
/**
* @dataProvider providerForFinite
*/
public function testShouldValidateFiniteNumbers($input): void
{
self::assertTrue($this->rule->validate($input));
}
/**
* @dataProvider providerForNonFinite
*/
public function testShouldNotValidateNonFiniteNumbers($input): void
{
self::assertFalse($this->rule->validate($input));
}
/**
* @expectedException \Respect\Validation\Exceptions\FiniteException
* @expectedExceptionMessage `INF` must be a finite number
*/
public function testShouldThrowFiniteExceptionWhenChecking(): void
{
$this->rule->check(INF);
}
public function providerForFinite()
{
return [
['123456'],
[-9],
[0],
[16],
[2],
[PHP_INT_MAX],
];
}
public function providerForNonFinite()
{
return [
[' '],
[INF],
[[]],
[new \stdClass()],
[null],
];
}
}