respect-validation/tests/unit/Rules/MinAgeTest.php
Henrique Moody ef8a8f4b27
Turn LICENSE file into plain/text
There is no need for that file to be a Markdown, and it can be a plain
text file.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2019-05-23 16:21:34 +02:00

72 lines
2.2 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 file
* that was distributed with this source code.
*/
declare(strict_types=1);
namespace Respect\Validation\Rules;
use DateTime;
use DateTimeImmutable;
use Respect\Validation\Test\RuleTestCase;
use stdClass;
use function date;
use function strtotime;
/**
* @group rule
*
* @covers \Respect\Validation\Rules\AbstractAge
* @covers \Respect\Validation\Rules\MinAge
*
* @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Jean Pimentel <jeanfap@gmail.com>
* @author Kennedy Tedesco <kennedyt.tw@gmail.com>
*/
final class MinAgeTest extends RuleTestCase
{
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
{
return [
[new MinAge(18, 'Y-m-d'), date('Y-m-d', strtotime('18 years ago'))],
[new MinAge(18, 'Y-m-d'), date('Y-m-d', strtotime('19 years ago'))],
[new MinAge(18), '18 years ago'],
[new MinAge(18), '19 years ago'],
];
}
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
{
return [
[new MinAge(18), new DateTime('18 years ago')],
[new MinAge(18), new DateTimeImmutable('19 years ago')],
[new MinAge(18, 'Y-m-d'), new DateTime('100 years ago')],
[new MinAge(18, 'Y-m-d'), new DateTimeImmutable('18 years ago')],
[new MinAge(18, 'Y-m-d'), '100 years ago'],
[new MinAge(18, 'Y-m-d'), '18 years ago'],
[new MinAge(18, 'Y-m-d'), date('Y-m-d', strtotime('17 years ago'))],
[new MinAge(18), 'invalid-input'],
[new MinAge(18), new stdClass()],
[new MinAge(18, 'Y-m-d'), date('Y/m/d', strtotime('18 years ago'))],
[new MinAge(18, 'Y-m-d'), date('Y-m-d', strtotime('17 years ago'))],
[new MinAge(18), new DateTime('17 years ago')],
[new MinAge(18), new DateTimeImmutable('17 years ago')],
[new MinAge(18), '17 years ago'],
];
}
}