2018-05-31 16:23:42 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Respect/Validation.
|
|
|
|
*
|
|
|
|
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
|
|
|
*
|
2019-05-23 16:21:34 +02:00
|
|
|
* For the full copyright and license information, please view the LICENSE file
|
|
|
|
* that was distributed with this source code.
|
2018-05-31 16:23:42 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2019-06-04 20:50:01 +02:00
|
|
|
namespace Respect\Validation\Rules;
|
2018-05-31 16:23:42 +02:00
|
|
|
|
|
|
|
use DateTime;
|
|
|
|
use DateTimeImmutable;
|
|
|
|
use Respect\Validation\Test\RuleTestCase;
|
|
|
|
use stdClass;
|
2020-07-21 22:54:41 +02:00
|
|
|
|
2018-05-31 16:23:42 +02:00
|
|
|
use function date;
|
|
|
|
use function strtotime;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group rule
|
|
|
|
*
|
|
|
|
* @covers \Respect\Validation\Rules\AbstractAge
|
2018-07-23 20:35:14 +02:00
|
|
|
* @covers \Respect\Validation\Rules\MaxAge
|
2018-05-31 16:23:42 +02:00
|
|
|
*
|
|
|
|
* @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
|
|
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
|
|
|
*/
|
|
|
|
final class MaxAgeTest extends RuleTestCase
|
|
|
|
{
|
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2018-05-31 16:23:42 +02:00
|
|
|
*/
|
|
|
|
public function providerForValidInput(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[new MaxAge(30, 'Y-m-d'), date('Y-m-d', strtotime('30 years ago'))],
|
|
|
|
[new MaxAge(30, 'Y-m-d'), date('Y-m-d', strtotime('29 years ago'))],
|
|
|
|
[new MaxAge(30), '30 years ago'],
|
|
|
|
[new MaxAge(30), '29 years ago'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2018-05-31 16:23:42 +02:00
|
|
|
*/
|
|
|
|
public function providerForInvalidInput(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[new MaxAge(30), new DateTime('30 years ago')],
|
|
|
|
[new MaxAge(30), new DateTime('29 years ago')],
|
|
|
|
[new MaxAge(30), new DateTimeImmutable('30 years ago')],
|
|
|
|
[new MaxAge(30), new DateTimeImmutable('29 years ago')],
|
|
|
|
[new MaxAge(30, 'Y-m-d'), new DateTime('30 years ago')],
|
|
|
|
[new MaxAge(30, 'Y-m-d'), new DateTimeImmutable('30 years ago')],
|
|
|
|
[new MaxAge(30, 'Y-m-d'), '30 years ago'],
|
|
|
|
[new MaxAge(30, 'Y-m-d'), date('Y/m/d', strtotime('30 years ago'))],
|
|
|
|
[new MaxAge(30), new DateTime('31 years ago')],
|
|
|
|
[new MaxAge(30), new DateTimeImmutable('31 years ago')],
|
|
|
|
[new MaxAge(30), '31 years ago'],
|
|
|
|
[new MaxAge(30, 'Y-m-d'), date('Y-m-d', strtotime('31 years ago'))],
|
|
|
|
[new MaxAge(30), 'invalid-input'],
|
|
|
|
[new MaxAge(30), new stdClass()],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|