-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathDateTimeTest.php
More file actions
73 lines (65 loc) · 2.45 KB
/
DateTimeTest.php
File metadata and controls
73 lines (65 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
declare(strict_types=1);
namespace SimpleSAML\Test\XML\Assert;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use SimpleSAML\Assert\AssertionFailedException;
use SimpleSAML\XML\Assert\Assert;
/**
* Class \SimpleSAML\Test\XML\Assert\DateTimeTest
*
* @package simplesamlphp/xml-common
*/
#[CoversClass(Assert::class)]
final class DateTimeTest extends TestCase
{
/**
* @param boolean $shouldPass
* @param string $dateTime
*/
#[DataProvider('provideInvalidDateTime')]
#[DataProvider('provideValidDateTime')]
public function testValidDateTime(bool $shouldPass, string $dateTime): void
{
try {
Assert::validDateTime($dateTime);
$this->assertTrue($shouldPass);
} catch (AssertionFailedException $e) {
$this->assertFalse($shouldPass);
}
}
/**
* @return array<string, array{0: true, 1: string}>
*/
public static function provideValidDateTime(): array
{
return [
'valid' => [true, '2001-10-26T21:32:52'],
'valid with numeric difference' => [true, '2001-10-26T21:32:52+02:00'],
'valid with Zulu' => [true, '2001-10-26T19:32:52Z'],
'valid with 00:00 difference' => [true, '2001-10-26T19:32:52+00:00'],
'valid with negative value' => [true, '-2001-10-26T21:32:52'],
'valid with subseconds' => [true, '2001-10-26T21:32:52.12679'],
'valid with more than four digit year' => [true, '-22001-10-26T21:32:52+02:00'],
'valid with up to twelve sub-seconds' => [true, '2001-10-26T21:32:52.126798764382'],
'sub-seconds ending with zero' => [true, '2001-10-26T21:32:52.12670'],
];
}
/**
* @return array<string, array{0: false, 1: string}>
*/
public static function provideInvalidDateTime(): array
{
return [
'missing time' => [false, '2001-10-26'],
'missing second' => [false, '2001-10-26T21:32'],
'hour out of range' => [false, '2001-10-26T25:32:52+02:00'],
'hour twenty-four' => [false, '2001-10-26T24:32:52+02:00'],
'year 0000' => [false, '0000-10-26T25:32:52+02:00'],
'prefixed zero' => [false, '02001-10-26T25:32:52+02:00'],
'wrong format' => [false, '01-10-26T21:32'],
'too many sub-seconds' => [false, '2001-10-26T21:32:52.1267987643821'],
];
}
}