forked from erikfercak/Timecop-PHP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadmeTest.php
38 lines (28 loc) · 994 Bytes
/
ReadmeTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
date_default_timezone_set('Europe/Prague');
require_once dirname(__FILE__) . '/../lib/Timecop.php';
class ReadmeTest extends PHPUnit_Framework_TestCase
{
public function testReadmeExamples()
{
// override internal PHP functions
Timecop::warpTime();
// time travel
$presentTime = time();
Timecop::travel(time() - 3600); // one hour back
$this->assertTrue($presentTime > time());
Timecop::travel(time() + 7200); // one hour forward
$this->assertTrue($presentTime < time());
// freeze time
Timecop::freeze();
$frozenTime = time();
usleep(1000001);
$this->assertEquals(time(), $frozenTime);
// restore time - unfreezes time and returns to present
Timecop::restore();
$this->assertNotEquals(time(), $frozenTime);
$this->assertTrue($frozenTime > time());
// restore original PHP functionality
Timecop::unwarpTime();
}
}