2018-05-31 16:23:42 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2023-02-17 05:13:51 +01:00
|
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
|
|
* SPDX-License-Identifier: MIT
|
2018-05-31 16:23:42 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
|
|
|
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\MinAge
|
2018-05-31 16:23:42 +02:00
|
|
|
*
|
|
|
|
* @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
|
|
|
|
{
|
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2018-05-31 16:23:42 +02:00
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public static function providerForValidInput(): array
|
2018-05-31 16:23:42 +02:00
|
|
|
{
|
|
|
|
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'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2018-05-31 16:23:42 +02:00
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public static function providerForInvalidInput(): array
|
2018-05-31 16:23:42 +02:00
|
|
|
{
|
|
|
|
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'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|