8000 minor #39706 [HttpKernel] harden test to not depend on the actual tim… · symfony/symfony@b9bdb8e · GitHub
[go: up one dir, main page]

Skip to content

Commit b9bdb8e

Browse files
committed
minor #39706 [HttpKernel] harden test to not depend on the actual time (xabbuh)
This PR was merged into the 4.4 branch. Discussion ---------- [HttpKernel] harden test to not depend on the actual time | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | From time to time this test fails (e.g. https://travis-ci.com/github/symfony/symfony/jobs/468014427#L7092). We can fix that by not depending on the system clock which is actually not needed in this test. Commits ------- 28a956b harden test to not depend on the actual time
2 parents 04671ee + 28a956b commit b9bdb8e

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