|
115 | 115 | }); |
116 | 116 |
|
117 | 117 | it('DateTimeRFC3339Extended::tryFromString returns value for valid RFC3339_EXTENDED string', function (): void { |
118 | | - $s = '2025-01-02T03:04:05.123456+00:00'; |
| 118 | + // DATE_RFC3339_EXTENDED uses milliseconds precision (3 digits) |
| 119 | + $s = '2025-01-02T03:04:05.123+00:00'; |
119 | 120 | $v = DateTimeRFC3339Extended::tryFromString($s); |
120 | 121 |
|
121 | 122 | expect($v) |
122 | | - ->toBeInstanceOf(Undefined::class); |
| 123 | + ->toBeInstanceOf(DateTimeRFC3339Extended::class) |
| 124 | + ->and($v->toString()) |
| 125 | + ->toBe($s); |
123 | 126 | }); |
124 | 127 |
|
125 | 128 | it('DateTimeRFC3339Extended::tryFromString returns Undefined for invalid string', function (): void { |
|
138 | 141 | expect((string) $vo)->toBe('2025-01-02T03:04:05.123+00:00') |
139 | 142 | ->and($vo->__toString())->toBe('2025-01-02T03:04:05.123+00:00'); |
140 | 143 | }); |
| 144 | + |
| 145 | +it('tryFromMixed handles valid RFC3339_EXTENDED strings and invalid mixed inputs', function (): void { |
| 146 | + // valid string |
| 147 | + $ok = DateTimeRFC3339Extended::tryFromMixed('2025-01-02T03:04:05.000+00:00'); |
| 148 | + |
| 149 | + // invalid types |
| 150 | + $badArr = DateTimeRFC3339Extended::tryFromMixed(['x']); |
| 151 | + $badNull = DateTimeRFC3339Extended::tryFromMixed(null); |
| 152 | + |
| 153 | + // stringable object |
| 154 | + $stringable = new class { |
| 155 | + public function __toString(): string |
| 156 | + { |
| 157 | + return '2025-01-02T03:04:05.000+00:00'; |
| 158 | + } |
| 159 | + }; |
| 160 | + $okStr = DateTimeRFC3339Extended::tryFromMixed($stringable); |
| 161 | + |
| 162 | + expect($ok)->toBeInstanceOf(DateTimeRFC3339Extended::class) |
| 163 | + ->and($ok->toString())->toBe('2025-01-02T03:04:05.000+00:00') |
| 164 | + ->and($okStr)->toBeInstanceOf(DateTimeRFC3339Extended::class) |
| 165 | + ->and($badArr)->toBeInstanceOf(Undefined::class) |
| 166 | + ->and($badNull)->toBeInstanceOf(Undefined::class); |
| 167 | +}); |
0 commit comments