mirror of
https://github.com/Respect/Validation.git
synced 2026-03-15 06:45:44 +01:00
We want to release version 3.0 as fresh as possible, without having to maintain backward compatibility with the previous versions. Because that version will be on for some time, we decided it will be best to support only PHP version 8.5 or higher. Acked-by: Alexandre Gomes Gaigalas <alganet@gmail.com>
71 lines
2 KiB
PHP
71 lines
2 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Validation\Helpers;
|
|
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
use PHPUnit\Framework\Attributes\Group;
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
use Respect\Validation\Test\TestCase;
|
|
|
|
#[Group('helper')]
|
|
final class CanValidateDateTimeTest extends TestCase
|
|
{
|
|
use CanValidateDateTime;
|
|
|
|
#[Test]
|
|
#[DataProvider('providerForValidDateTime')]
|
|
public function shouldFindWhenValueIsDateTime(string $format, string $value): void
|
|
{
|
|
self::assertTrue($this->isDateTime($format, $value));
|
|
}
|
|
|
|
#[Test]
|
|
#[DataProvider('providerForInvalidDateTime')]
|
|
public function shouldFindWhenValueIsNotDateTime(string $format, string $value): void
|
|
{
|
|
self::assertFalse($this->isDateTime($format, $value));
|
|
}
|
|
|
|
/**
|
|
* @return mixed[][]
|
|
*/
|
|
public static function providerForValidDateTime(): array
|
|
{
|
|
return [
|
|
['Y-m-d', '2009-09-09'],
|
|
['Y-m-d', '2020-02-29'],
|
|
['Ymd', '20090909'],
|
|
['d/m/Y', '23/05/1987'],
|
|
['c', '2018-01-30T19:04:35+00:00'],
|
|
['Y-m-d\TH:i:sP', '2018-01-30T19:04:35+00:00'],
|
|
['r', 'Tue, 30 Jan 2018 19:06:01 +0000'],
|
|
['D, d M Y H:i:s O', 'Tue, 30 Jan 2018 19:06:01 +0000'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return mixed[][]
|
|
*/
|
|
public static function providerForInvalidDateTime(): array
|
|
{
|
|
return [
|
|
['Y-m-d', '0000-01-01'],
|
|
['Y-m-d', '2021-02-29'],
|
|
['y-m-d', '2009-09-12'],
|
|
['Y-m-d', '0000-00-31'],
|
|
['Y-m-d', '0000-12-00'],
|
|
['Y-m-d H:i:s', '1987-12-31'],
|
|
['c', '2018-01-30T19:04:35-00:00'],
|
|
['Y-m-d\TH:i:sP', '2018-01-30T19:04:35-00:00'],
|
|
['r', 'Tue, 30 Jan 2018 19:06:01 -0000'],
|
|
['D, d M Y H:i:s O', 'Tue, 30 Jan 2018 19:06:01 -0000'],
|
|
];
|
|
}
|
|
}
|