|
4 | 4 |
|
5 | 5 | namespace SimpleSAML\Test\XMLSchema\Type\Builtin; |
6 | 6 |
|
| 7 | +use DateTimeImmutable; |
7 | 8 | use PHPUnit\Framework\Attributes\CoversClass; |
8 | 9 | use PHPUnit\Framework\Attributes\DataProvider; |
9 | 10 | use PHPUnit\Framework\Attributes\DataProviderExternal; |
@@ -40,13 +41,62 @@ public function testTime(bool $shouldPass, string $time): void |
40 | 41 | } |
41 | 42 |
|
42 | 43 |
|
| 44 | + /** |
| 45 | + * Test the fromDateTime function |
| 46 | + */ |
| 47 | + #[DependsOnClass(TimeTest::class)] |
| 48 | + public function testFromDateTime(): void |
| 49 | + { |
| 50 | + $t = new DateTimeImmutable('00:00:00+00:00'); |
| 51 | + |
| 52 | + $timeValue = TimeValue::fromDateTime($t); |
| 53 | + $this->assertEquals('00:00:00+00:00', $timeValue->getValue()); |
| 54 | + } |
| 55 | + |
| 56 | + |
| 57 | + /** |
| 58 | + */ |
| 59 | + public function testSubSeconds(): void |
| 60 | + { |
| 61 | + // Strip sub-second trailing zero's and make sure the decimal sign is removed |
| 62 | + $timeValue = TimeValue::fromString('21:32:52.00'); |
| 63 | + $this->assertEquals('21:32:52', $timeValue->getValue()); |
| 64 | + |
| 65 | + // Strip sub-second trailing zero's |
| 66 | + $timeValue = TimeValue::fromString('21:32:52.12300'); |
| 67 | + $this->assertEquals('21:32:52.123', $timeValue->getValue()); |
| 68 | + |
| 69 | + // Strip sub-seconds over microsecond precision |
| 70 | + $timeValue = TimeValue::fromString('21:32:52.1234567'); |
| 71 | + $this->assertEquals('21:32:52.123456', $timeValue->getValue()); |
| 72 | + |
| 73 | + // Strip sub-second trailing zero's and make sure the decimal sign is removed |
| 74 | + $timeValue = TimeValue::fromString('21:32:52.00Z'); |
| 75 | + $this->assertEquals('21:32:52Z', $timeValue->getValue()); |
| 76 | + |
| 77 | + // Strip sub-seconds over microsecond precision with timezone |
| 78 | + $timeValue = TimeValue::fromString('21:32:52.1234567+01:00'); |
| 79 | + $this->assertEquals('21:32:52.123456+01:00', $timeValue->getValue()); |
| 80 | + |
| 81 | + // Strip sub-seconds over microsecond precision with timezone Zulu |
| 82 | + $timeValue = TimeValue::fromString('21:32:52.1234567Z'); |
| 83 | + $this->assertEquals('21:32:52.123456Z', $timeValue->getValue()); |
| 84 | + } |
| 85 | + |
| 86 | + |
43 | 87 | /** |
44 | 88 | * @return array<string, array{0: true, 1: string}> |
45 | 89 | */ |
46 | 90 | public static function provideValidTime(): array |
47 | 91 | { |
48 | 92 | return [ |
49 | 93 | 'whitespace collapse' => [true, "\n 21:32:52.12679\t "], |
| 94 | + 'trailing sub-second zero' => [true, '21:32:52.1230'], |
| 95 | + 'trailing sub-second zero with timezone' => [true, '21:32:52.1230+00:00'], |
| 96 | + 'trailing sub-second zero with timezone Zulu' => [true, '21:32:52.1230Z'], |
| 97 | + 'all trailing sub-second all zero' => [true, '21:32:52.00'], |
| 98 | + 'all trailing sub-second all zero with timezone' => [true, '21:32:52.00+00:00'], |
| 99 | + 'all trailing sub-second all zero with timezone Zulu' => [true, '21:32:52.00Z'], |
50 | 100 | ]; |
51 | 101 | } |
52 | 102 |
|
|
0 commit comments