mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 15:50:03 +01:00
93 lines
2.5 KiB
PHP
93 lines
2.5 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.
|
|
*/
|
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
use DateTime;
|
|
|
|
/**
|
|
* @group rule
|
|
* @covers Respect\Validation\Rules\Between
|
|
* @covers Respect\Validation\Exceptions\BetweenException
|
|
*/
|
|
class BetweenTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
public function providerValid()
|
|
{
|
|
return array(
|
|
array(10, 20, false, ''),
|
|
array(10, 20, true, ''),
|
|
array(0, 1, true, 0),
|
|
array(0, 1, true, 1),
|
|
array(10, 20, false, 15),
|
|
array(10, 20, true, 20),
|
|
array(-10, 20, false, -5),
|
|
array(-10, 20, false, 0),
|
|
array('a', 'z', false, 'j'),
|
|
array(
|
|
new DateTime('yesterday'),
|
|
new DateTime('tomorrow'),
|
|
false,
|
|
new DateTime('now'),
|
|
),
|
|
);
|
|
}
|
|
|
|
public function providerInvalid()
|
|
{
|
|
return array(
|
|
array(0, 1, false, 0),
|
|
array(0, 1, false, 1),
|
|
array(0, 1, false, 2),
|
|
array(0, 1, false, -1),
|
|
array(10, 20, false, 999),
|
|
array(10, 20, false, 20),
|
|
array(-10, 20, false, -11),
|
|
array('a', 'j', false, 'z'),
|
|
array(
|
|
new DateTime('yesterday'),
|
|
new DateTime('now'),
|
|
false,
|
|
new DateTime('tomorrow'),
|
|
),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerValid
|
|
*/
|
|
public function testValuesBetweenBoundsShouldPass($min, $max, $inclusive, $input)
|
|
{
|
|
$o = new Between($min, $max, $inclusive);
|
|
$this->assertTrue($o->__invoke($input));
|
|
$this->assertTrue($o->assert($input));
|
|
$this->assertTrue($o->check($input));
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerInvalid
|
|
* @expectedException Respect\Validation\Exceptions\BetweenException
|
|
*/
|
|
public function testValuesOutBoundsShouldRaiseException($min, $max, $inclusive, $input)
|
|
{
|
|
$o = new Between($min, $max, $inclusive);
|
|
$this->assertFalse($o->__invoke($input));
|
|
$this->assertFalse($o->assert($input));
|
|
}
|
|
|
|
/**
|
|
* @expectedException Respect\Validation\Exceptions\ComponentException
|
|
*/
|
|
public function testInvalidConstructionParamsShouldRaiseException()
|
|
{
|
|
$o = new Between(10, 5);
|
|
}
|
|
}
|