@@ -161,11 +161,14 @@ public function testCleanUp()
161161 {
162162 $ this ->provider ->create ();
163163 $ provider = $ this ->getFileProvider ([
164- 'message_expiration ' => 1 ,
164+ 'message_expiration ' => 10 ,
165165 ]);
166- $ provider ->publish (['testing ' ]);
167- $ provider ->publish (['testing 123 ' ]);
168- sleep (1 );
166+
167+ $ id = $ provider ->publish (['testing ' ]);
168+ $ this ->mockMessageAge ($ id , 3600 );
169+ $ id = $ provider ->publish (['testing 123 ' ]);
170+ $ this ->mockMessageAge ($ id , 3600 );
171+
169172 $ provider ->cleanUp ();
170173 $ messages = $ provider ->receive ();
171174 $ this ->assertEmpty ($ messages );
@@ -177,16 +180,32 @@ public function testCleanUp()
177180 public function testCleanUpDoesNotRemoveCurrentMessages () {
178181 $ this ->provider ->create ();
179182 $ provider = $ this ->getFileProvider ([
180- 'message_expiration ' => 2 ,
183+ 'message_expiration ' => 10 ,
181184 ]);
182- $ provider ->publish (['testing ' ]);
183- $ provider ->publish (['testing 123 ' ]);
184- sleep (2 );
185185 $ currentMessage = ['dont remove me ' ];
186+
187+ $ id = $ provider ->publish (['testing ' ]);
188+ $ this ->mockMessageAge ($ id , 3600 );
189+ $ id = $ provider ->publish (['testing 123 ' ]);
190+ $ this ->mockMessageAge ($ id , 3600 );
186191 $ provider ->publish ($ currentMessage );
192+
187193 $ provider ->cleanUp ();
188194 $ messages = $ provider ->receive ();
189195 $ this ->assertCount (1 , $ messages );
190196 $ this ->assertSame ($ currentMessage , $ messages [0 ]->getBody ());
191197 }
198+
199+ /**
200+ * @param string $id
201+ * @param int $ageInSeconds
202+ * @return string
203+ */
204+ protected function mockMessageAge ($ id , $ ageInSeconds ) {
205+ $ path = substr (hash ('md5 ' , $ id ), 0 , 3 );
206+ touch (
207+ $ this ->basePath .DIRECTORY_SEPARATOR .$ this ->queueHash .DIRECTORY_SEPARATOR .$ path .DIRECTORY_SEPARATOR .$ id .'.json ' ,
208+ time () - $ ageInSeconds
209+ );
210+ }
192211}
0 commit comments