2010-12-05 21:26:04 +01:00
|
|
|
<?php
|
2015-06-08 16:47:14 +02:00
|
|
|
|
2015-06-08 17:09:25 +02:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2010-12-05 21:26:04 +01:00
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
2015-08-16 20:00:05 +02:00
|
|
|
/**
|
|
|
|
* @group rule
|
2017-02-04 14:01:14 +01:00
|
|
|
* @covers \Respect\Validation\Rules\Max
|
|
|
|
* @covers \Respect\Validation\Exceptions\MaxException
|
2015-08-16 20:00:05 +02:00
|
|
|
*/
|
2010-12-05 21:26:04 +01:00
|
|
|
class MaxTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider providerForValidMax
|
|
|
|
*/
|
2013-01-14 23:44:49 +01:00
|
|
|
public function testValidMaxInputShouldReturnTrue($maxValue, $inclusive, $input)
|
2010-12-05 21:26:04 +01:00
|
|
|
{
|
2010-12-07 20:17:43 +01:00
|
|
|
$max = new Max($maxValue, $inclusive);
|
2011-10-06 02:07:15 +02:00
|
|
|
$this->assertTrue($max->validate($input));
|
|
|
|
$this->assertTrue($max->check($input));
|
2010-12-05 21:26:04 +01:00
|
|
|
$this->assertTrue($max->assert($input));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerForInvalidMax
|
2017-02-04 14:01:14 +01:00
|
|
|
* @expectedException \Respect\Validation\Exceptions\MaxException
|
2010-12-05 21:26:04 +01:00
|
|
|
*/
|
2013-01-14 23:44:49 +01:00
|
|
|
public function testInvalidMaxValueShouldThrowMaxException($maxValue, $inclusive, $input)
|
2010-12-05 21:26:04 +01:00
|
|
|
{
|
2010-12-07 20:17:43 +01:00
|
|
|
$max = new Max($maxValue, $inclusive);
|
2011-10-06 02:07:15 +02:00
|
|
|
$this->assertFalse($max->validate($input));
|
|
|
|
$this->assertFalse($max->assert($input));
|
2010-12-05 21:26:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function providerForValidMax()
|
|
|
|
{
|
2015-10-18 03:44:47 +02:00
|
|
|
return [
|
|
|
|
[200, false, ''],
|
|
|
|
[200, false, 165.0],
|
|
|
|
[200, false, -200],
|
|
|
|
[200, true, 200],
|
|
|
|
[200, false, 0],
|
|
|
|
['-18 years', true, '1988-09-09'],
|
|
|
|
['z', true, 'z'],
|
|
|
|
['z', false, 'y'],
|
|
|
|
['tomorrow', true, 'now'],
|
|
|
|
];
|
2010-12-05 21:26:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function providerForInvalidMax()
|
|
|
|
{
|
2015-10-18 03:44:47 +02:00
|
|
|
return [
|
|
|
|
[200, false, 300],
|
|
|
|
[200, false, 250],
|
|
|
|
[200, false, 1500],
|
|
|
|
[200, false, 200],
|
|
|
|
];
|
2010-12-05 21:26:04 +01:00
|
|
|
}
|
2013-01-14 23:44:49 +01:00
|
|
|
}
|