-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement TimecopDateTimeImmutable::__construct(),
timecop_date_create_immutable(), timecop_date_create_immutable_from_format() / Now timecop_date_create_from_format() returns DateTime instance
- Loading branch information
Showing
83 changed files
with
1,510 additions
and
607 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
extension_loaded('timecop') or die('skip timecop module not available'); | ||
if (isset($required_version)) { | ||
if (version_compare(PHP_VERSION, $required_version, "<")) { | ||
die("skip PHP ${required_version}+ required for this test"); | ||
} | ||
} | ||
if (isset($required_func)) { | ||
foreach ($required_func as $func_name) { | ||
if (!function_exists($func_name)) { | ||
die("skip $func_name() function is not available."); | ||
} | ||
} | ||
} | ||
if (isset($required_class)) { | ||
foreach ($required_class as $class_name) { | ||
if (!class_exists($class_name)) { | ||
die("skip $class_name class is not available."); | ||
} | ||
} | ||
} | ||
if (isset($required_method)) { | ||
foreach ($required_method as $v) { | ||
list($class_name, $method_name) = $v; | ||
if (!method_exists($class_name, $method_name)) { | ||
die("skip $class_name::$method_name() method is not available."); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--TEST-- | ||
Check for timecop_freeze() | ||
--SKIPIF-- | ||
<?php | ||
$required_func = array("timecop_freeze"); | ||
$required_class = array("TimecopDateTime"); | ||
include(__DIR__."/../tests-skipcheck.inc.php"); | ||
--INI-- | ||
date.timezone=America/Los_Angeles | ||
timecop.func_override=0 | ||
--FILE-- | ||
<?php | ||
$dt1 = new DateTime("1970-01-01 00:00:00.000 GMT"); | ||
timecop_freeze($dt1); | ||
$dt2 =new TimecopDateTime(); | ||
|
||
if (class_exists("DateTimeImmutable")) { | ||
$dt3 = new DateTimeImmutable("1970-01-01 09:00:00.000 GMT"); | ||
timecop_freeze($dt3); | ||
$dt4 =new TimecopDateTime(); | ||
} else { | ||
$dt3 = new DateTime("1970-01-01 01:00:00.000"); | ||
$dt4 = new DateTime("1970-01-01 01:00:00.000"); | ||
} | ||
|
||
$dt5 = new TimecopDateTime("2040-01-01 00:00:00.000 GMT"); | ||
timecop_freeze($dt5); | ||
|
||
if (PHP_INT_SIZE === 8) { | ||
$dt6 = new TimecopDateTime(); | ||
} else { | ||
// force pass the test on 32bit environment | ||
$dt6 = $dt5; | ||
$dt6->setTimeZone(new DateTimezone("America/Los_Angeles")); | ||
} | ||
|
||
timecop_freeze(1); | ||
$dt7 =new TimecopDateTime(); | ||
|
||
var_dump($dt2->format("Y-m-d H:i:s.u")); | ||
var_dump($dt4->format("Y-m-d H:i:s.u")); | ||
var_dump($dt6->format("Y-m-d H:i:s.u")); | ||
var_dump($dt1 == $dt2); | ||
var_dump($dt3 == $dt4); | ||
var_dump($dt5 == $dt6); | ||
var_dump($dt7->format("Y-m-d H:i:s.u")); | ||
--EXPECT-- | ||
string(26) "1969-12-31 16:00:00.000000" | ||
string(26) "1970-01-01 01:00:00.000000" | ||
string(26) "2039-12-31 16:00:00.000000" | ||
bool(true) | ||
bool(true) | ||
bool(true) | ||
string(26) "1969-12-31 16:00:01.000000" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--TEST-- | ||
Check for timecop_travel() | ||
--SKIPIF-- | ||
<?php | ||
$required_func = array("timecop_travel"); | ||
$required_class = array("DateTime", "TimecopDateTime"); | ||
$required_method = array(); | ||
include(__DIR__."/../tests-skipcheck.inc.php"); | ||
--INI-- | ||
date.timezone=America/Los_Angeles | ||
timecop.func_override=0 | ||
--FILE-- | ||
<?php | ||
$dt1 = new DateTime("1970-01-01 00:00:00.900 GMT"); | ||
timecop_travel($dt1); | ||
usleep(100000); | ||
$dt2 =new TimecopDateTime(); | ||
|
||
if (class_exists("DateTimeImmutable")) { | ||
$dt3 = new DateTimeImmutable("1970-01-01 09:00:00.900 GMT"); | ||
timecop_travel($dt3); | ||
usleep(100000); | ||
$dt4 =new TimecopDateTime(); | ||
} else { | ||
$dt3 = new DateTime("1970-01-01 01:00:00.900"); | ||
$dt4 = new DateTime("1970-01-01 01:00:01.050"); | ||
} | ||
|
||
$dt5 = new TimecopDateTime("2040-01-01 00:00:00.900 GMT"); | ||
timecop_travel($dt5); | ||
usleep(100000); | ||
if (PHP_INT_SIZE === 8) { | ||
$dt6 =new TimecopDateTime(); | ||
} else { | ||
// always pass the test on 32bit environment | ||
$dt6 = clone $dt5; | ||
$dt6->modify("+1second"); | ||
$dt6->setTimeZone(new DateTimezone("America/Los_Angeles")); | ||
} | ||
|
||
timecop_travel(1); | ||
sleep(1); | ||
$dt7 =new TimecopDateTime(); | ||
|
||
var_dump($dt2->format("Y-m-d H:i:s")); | ||
var_dump($dt4->format("Y-m-d H:i:s")); | ||
var_dump($dt6->format("Y-m-d H:i:s")); | ||
var_dump($dt1 < $dt2); | ||
var_dump($dt3 < $dt4); | ||
var_dump($dt5 < $dt6); | ||
var_dump($dt7->format("Y-m-d H:i:s")); | ||
--EXPECT-- | ||
string(19) "1969-12-31 16:00:01" | ||
string(19) "1970-01-01 01:00:01" | ||
string(19) "2039-12-31 16:00:01" | ||
bool(true) | ||
bool(true) | ||
bool(true) | ||
string(19) "1969-12-31 16:00:02" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--TEST-- | ||
Check for timecop_scale() | ||
--SKIPIF-- | ||
<?php | ||
$required_func = array("timecop_travel", "timecop_scale"); | ||
$required_class = array("TimecopDateTime"); | ||
$required_method = array(); | ||
include(__DIR__."/../tests-skipcheck.inc.php"); | ||
--INI-- | ||
date.timezone=America/Los_Angeles | ||
timecop.func_override=0 | ||
--FILE-- | ||
<?php | ||
$dt1 = new TimecopDateTime("1970-01-01 00:00:00.900 GMT"); | ||
timecop_travel($dt1); | ||
timecop_scale(10); | ||
usleep(110000); | ||
$dt2 =new TimecopDateTime(); | ||
timecop_scale(20); | ||
usleep(100000); | ||
$dt3 =new TimecopDateTime(); | ||
var_dump($dt2->format("Y-m-d H:i:s")); | ||
var_dump($dt3->format("Y-m-d H:i:s")); | ||
--EXPECT-- | ||
string(19) "1969-12-31 16:00:02" | ||
string(19) "1969-12-31 16:00:04" |
Oops, something went wrong.