@@ -48,7 +48,7 @@ public function testWithStateInitStateOnFirstAcquiring()
48
48
$ this ->assertTrue ($ checkpoint ->acquire ($ now ));
49
49
$ this ->assertEquals ($ now , $ checkpoint ->time ());
50
50
$ this ->assertEquals (-1 , $ checkpoint ->index ());
51
- $ this ->assertEquals ([$ now , -1 ], $ cache ->get ('cache ' , fn () => []));
51
+ $ this ->assertEquals ([$ now , -1 , $ now ], $ cache ->get ('cache ' , fn () => []));
52
52
}
53
53
54
54
public function testWithStateLoadStateOnAcquiring ()
@@ -58,10 +58,10 @@ public function testWithStateLoadStateOnAcquiring()
58
58
59
59
$ cache ->get ('cache ' , fn () => [$ now , 0 ], \INF );
60
60
61
- $ this ->assertTrue ($ checkpoint ->acquire ($ now ->modify ('1 min ' )));
61
+ $ this ->assertTrue ($ checkpoint ->acquire ($ startedAt = $ now ->modify ('1 min ' )));
62
62
$ this ->assertEquals ($ now , $ checkpoint ->time ());
63
63
$ this ->assertEquals (0 , $ checkpoint ->index ());
64
- $ this ->assertEquals ([$ now , 0 ], $ cache ->get ('cache ' , fn () => []));
64
+ $ this ->assertEquals ([$ now , 0 , $ startedAt ], $ cache ->get ('cache ' , fn () => []));
65
65
}
66
66
67
67
public function testWithLockInitStateOnFirstAcquiring ()
@@ -72,11 +72,12 @@ public function testWithLockInitStateOnFirstAcquiring()
72
72
73
73
$ this ->assertTrue ($ checkpoint ->acquire ($ now ));
74
74
$ this ->assertEquals ($ now , $ checkpoint ->time ());
75
+ $ this ->assertEquals ($ now , $ checkpoint ->from ());
75
76
$ this ->assertEquals (-1 , $ checkpoint ->index ());
76
77
$ this ->assertTrue ($ lock ->isAcquired ());
77
78
}
78
79
79
- public function testwithLockLoadStateOnAcquiring ()
80
+ public function testWithLockLoadStateOnAcquiring ()
80
81
{
81
82
$ lock = new Lock (new Key ('lock ' ), new InMemoryStore ());
82
83
$ checkpoint = new Checkpoint ('dummy ' , $ lock );
@@ -86,6 +87,7 @@ public function testwithLockLoadStateOnAcquiring()
86
87
87
88
$ this ->assertTrue ($ checkpoint ->acquire ($ now ->modify ('1 min ' )));
88
89
$ this ->assertEquals ($ now , $ checkpoint ->time ());
90
+ $ this ->assertEquals ($ now , $ checkpoint ->from ());
89
91
$ this ->assertEquals (0 , $ checkpoint ->index ());
90
92
$ this ->assertTrue ($ lock ->isAcquired ());
91
93
}
@@ -105,12 +107,13 @@ public function testWithCacheSave()
105
107
{
106
108
$ checkpoint = new Checkpoint ('cache ' , new NoLock (), $ cache = new ArrayAdapter ());
107
109
$ now = new \DateTimeImmutable ('2020-02-20 20:20:20Z ' );
108
- $ checkpoint ->acquire ($ now ->modify ('-1 hour ' ));
110
+ $ checkpoint ->acquire ($ startedAt = $ now ->modify ('-1 hour ' ));
109
111
$ checkpoint ->save ($ now , 3 );
110
112
111
113
$ this ->assertSame ($ now , $ checkpoint ->time ());
112
114
$ this ->assertSame (3 , $ checkpoint ->index ());
113
- $ this ->assertEquals ([$ now , 3 ], $ cache ->get ('cache ' , fn () => []));
115
+ $ this ->assertSame ($ startedAt , $ checkpoint ->from ());
116
+ $ this ->assertEquals ([$ now , 3 , $ startedAt ], $ cache ->get ('cache ' , fn () => []));
114
117
}
115
118
116
119
public function testWithLockSave ()
@@ -119,11 +122,12 @@ public function testWithLockSave()
119
122
$ checkpoint = new Checkpoint ('dummy ' , $ lock );
120
123
$ now = new \DateTimeImmutable ('2020-02-20 20:20:20Z ' );
121
124
122
- $ checkpoint ->acquire ($ now ->modify ('-1 hour ' ));
125
+ $ checkpoint ->acquire ($ startTime = $ now ->modify ('-1 hour ' ));
123
126
$ checkpoint ->save ($ now , 3 );
124
127
125
128
$ this ->assertSame ($ now , $ checkpoint ->time ());
126
129
$ this ->assertSame (3 , $ checkpoint ->index ());
130
+ $ this ->assertSame ($ startTime , $ checkpoint ->from ());
127
131
}
128
132
129
133
public function testWithLockAndCacheSave ()
@@ -132,12 +136,12 @@ public function testWithLockAndCacheSave()
132
136
$ checkpoint = new Checkpoint ('dummy ' , $ lock , $ cache = new ArrayAdapter ());
133
137
$ now = new \DateTimeImmutable ('2020-02-20 20:20:20Z ' );
134
138
135
- $ checkpoint ->acquire ($ now ->modify ('-1 hour ' ));
139
+ $ checkpoint ->acquire ($ startTime = $ now ->modify ('-1 hour ' ));
136
140
$ checkpoint ->save ($ now , 3 );
137
141
138
142
$ this ->assertSame ($ now , $ checkpoint ->time ());
139
143
$ this ->assertSame (3 , $ checkpoint ->index ());
140
- $ this ->assertEquals ([$ now , 3 ], $ cache ->get ('dummy ' , fn () => []));
144
+ $ this ->assertEquals ([$ now , 3 , $ startTime ], $ cache ->get ('dummy ' , fn () => []));
141
145
}
142
146
143
147
public function testWithCacheFullCycle ()
@@ -161,7 +165,7 @@ public function testWithCacheFullCycle()
161
165
$ this ->assertSame (3 , $ lastIndex );
162
166
$ this ->assertEquals ($ now , $ checkpoint ->time ());
163
167
$ this ->assertSame (0 , $ checkpoint ->index ());
164
- $ this ->assertEquals ([$ now , 0 ], $ cache ->get ('cache ' , fn () => []));
168
+ $ this ->assertEquals ([$ now , 0 , $ now ], $ cache ->get ('cache ' , fn () => []));
165
169
}
166
170
167
171
public function testWithLockResetStateAfterLockedAcquiring ()
0 commit comments