7
7
use DateInterval ;
8
8
use DateTimeImmutable ;
9
9
use DateTimeZone ;
10
+ use mysql_xdevapi \CollectionModify ;
10
11
use PHPUnit \Framework \TestCase ;
11
12
use Stringable ;
12
13
@@ -26,7 +27,9 @@ public function testItDoesNotReturnTheAbsoluteInterval(): void
26
27
*/
27
28
public function testItCanBeInstantiatedFromDurationInput (string $ input , DateInterval $ expected ): void
28
29
{
29
- self ::assertEquals ($ expected , TimeToLive::fromDurationString ($ input ));
30
+ $ now = new DateTimeImmutable ();
31
+
32
+ self ::assertEquals ($ now ->add ($ expected ), $ now ->add (TimeToLive::fromDurationString ($ input )));
30
33
}
31
34
32
35
/**
@@ -47,16 +50,25 @@ public function validDurationString(): iterable
47
50
];
48
51
}
49
52
53
+ public function testItCastToNullWithNull (): void
54
+ {
55
+ self ::assertNull (TimeToLive::convert (null ));
56
+ }
57
+
50
58
/**
51
59
* @dataProvider validDurationInt
52
60
*/
53
- public function testItCanBeInstantiatedFromSeconds (int |string |Stringable |null | DateInterval $ input , ? DateInterval $ expected ): void
61
+ public function testItCanBeInstantiatedFromSeconds (int |string |Stringable |DateInterval $ input , DateInterval $ expected ): void
54
62
{
55
- self ::assertEquals ($ expected , TimeToLive::convert ($ input ));
63
+ /** @var DateInterval $ttl */
64
+ $ ttl = TimeToLive::convert ($ input );
65
+ $ now = new DateTimeImmutable ();
66
+
67
+ self ::assertEquals ($ now ->add ($ expected ), $ now ->add ($ ttl ));
56
68
}
57
69
58
70
/**
59
- * @return iterable<string, array{input:int|string|object|null| DateInterval, expected:DateInterval|null}>
71
+ * @return iterable<string, array{input:int|string|object|DateInterval, expected:DateInterval|null}>
60
72
*/
61
73
public function validDurationInt (): iterable
62
74
{
@@ -67,11 +79,6 @@ public function validDurationInt(): iterable
67
79
'expected ' => $ seconds ,
68
80
];
69
81
70
- yield 'null ' => [
71
- 'input ' => null ,
72
- 'expected ' => null ,
73
- ];
74
-
75
82
yield 'stringable object ' => [
76
83
'input ' => new class () {
77
84
public function __toString (): string
0 commit comments