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.
|
|
|
|
*/
|
|
|
|
|
2017-11-19 19:01:31 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2010-12-05 21:26:04 +01:00
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
2017-11-04 11:21:40 +01:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
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
|
|
|
*/
|
2017-11-04 11:21:40 +01:00
|
|
|
class MaxTest extends TestCase
|
2010-12-05 21:26:04 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider providerForValidMax
|
|
|
|
*/
|
2017-11-19 19:01:31 +01:00
|
|
|
public function testValidMaxInputShouldReturnTrue($maxValue, $inclusive, $input): void
|
2010-12-05 21:26:04 +01:00
|
|
|
{
|
2010-12-07 20:17:43 +01:00
|
|
|
$max = new Max($maxValue, $inclusive);
|
2017-11-12 14:33:39 +01:00
|
|
|
self::assertTrue($max->validate($input));
|
2018-01-28 16:14:00 +01:00
|
|
|
$max->check($input);
|
2018-01-28 17:16:53 +01:00
|
|
|
$max->assert($input);
|
2010-12-05 21:26:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerForInvalidMax
|
2017-02-04 14:01:14 +01:00
|
|
|
* @expectedException \Respect\Validation\Exceptions\MaxException
|
2010-12-05 21:26:04 +01:00
|
|
|
*/
|
2017-11-19 19:01:31 +01:00
|
|
|
public function testInvalidMaxValueShouldThrowMaxException($maxValue, $inclusive, $input): void
|
2010-12-05 21:26:04 +01:00
|
|
|
{
|
2010-12-07 20:17:43 +01:00
|
|
|
$max = new Max($maxValue, $inclusive);
|
2017-11-12 14:33:39 +01:00
|
|
|
self::assertFalse($max->validate($input));
|
2018-01-28 17:16:53 +01:00
|
|
|
$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
|
|
|
}
|