8000 harden test to not depend on the actual time · symfony/symfony@28a956b · GitHub
[go: up one dir, main page]

Skip to content

Commit 28a956b

Browse files
committed
harden test to not depend on the actual time
1 parent 04671ee commit 28a956b

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/Symfony/Component/HttpKernel/Tests/Profiler/FileProfilerStorageTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,26 +190,25 @@ public function testRetrieveByUrl()
190190

191191
public function testStoreTime()
192192
{
193-
$dt = new \DateTime('now');
194-
$start = $dt->getTimestamp();
193+
$start = $now = time();
195194

196195
for ($i = 0; $i < 3; ++$i) {
197-
$dt->modify('+1 minute');
196+
$now += 60;
198197
$profile = new Profile('time_'.$i);
199198
$profile->setIp('127.0.0.1');
200199
$profile->setUrl('http://foo.bar');
201-
$profile->setTime($dt->getTimestamp());
200+
$profile->setTime($now);
202201
$profile->setMethod('GET');
203202
$this->storage->write($profile);
204203
}
205204

206-
$records = $this->storage->find('', '', 3, 'GET', $start, time() + 3 * 60);
205+
$records = $this->storage->find('', '', 3, 'GET', $start, $start + 3 * 60);
207206
$this->assertCount(3, $records, '->find() returns all previously added records');
208207
$this->assertEquals('time_2', $records[0]['token'], '->find() returns records ordered by time in descendant order');
209208
$this->assertEquals('time_1', $records[1]['token'], '->find() returns records ordered by time in descendant order');
210209
$this->assertEquals('time_0', $records[2]['token'], '->find() returns records ordered by time in descendant order');
211210

212-
$records = $this->storage->find('', '', 3, 'GET', $start, time() + 2 * 60);
211+
$records = $this->storage->find('', '', 3, 'GET', $start, $start + 2 * 60);
213212
$this->assertCount(2, $records, '->find() should return only first two of the previously added records');
214213
}
215214

0 commit comments

Comments
 (0)
0