Skip to content

Commit 2a5ae6f

Browse files
author
Ion Bazan
committed
fixed #30
1 parent d722041 commit 2a5ae6f

File tree

3 files changed

+73
-7
lines changed

3 files changed

+73
-7
lines changed

tests/issue_005.phpt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
Check for issue #5 (DateTime reflection)
3+
--SKIPIF--
4+
<?php
5+
$required_version = "5.3";
6+
$required_func = array("timecop_freeze");
7+
$required_class = array("TimecopDateTime");
8+
include(__DIR__."/tests-skipcheck.inc.php");
9+
--INI--
10+
date.timezone=GMT
11+
timecop.func_override=1
12+
--FILE--
13+
<?php
14+
class Test
15+
{
16+
public function setCreatedAt(DateTime $createdAt)
17+
{
18+
$this->createdAt = $createdAt;
19+
}
20+
}
21+
22+
$test = new Test();
23+
24+
$reflection = new ReflectionClass($test);
25+
$params = $reflection->getMethod('setCreatedAt')->getParameters();
26+
27+
foreach ($params as $param) {
28+
var_dump($param->getClass());
29+
}
30+
--EXPECT--
31+
object(ReflectionClass)#3 (1) {
32+
["name"]=>
33+
string(8) "DateTime"
34+
}

tests/issue_030.phpt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
Check for issue #30 (DateTimeImmutable::createFromFormat with ! returns DateTime)
3+
--SKIPIF--
4+
<?php
5+
$required_version = "5.5";
6+
$required_func = array("timecop_freeze");
7+
$required_class = array("TimecopDateTimeImmutable");
8+
include(__DIR__."/tests-skipcheck.inc.php");
9+
--INI--
10+
date.timezone=GMT
11+
timecop.func_override=1
12+
--FILE--
13+
<?php
14+
var_dump(\DateTimeImmutable::createFromFormat('!Y-m-d', '2017-10-03'));
15+
var_dump(\DateTimeImmutable::createFromFormat('Y-m-d!', '2017-10-03'));
16+
--EXPECT--
17+
object(DateTimeImmutable)#1 (3) {
18+
["date"]=>
19+
string(26) "2017-10-03 00:00:00.000000"
20+
["timezone_type"]=>
21+
int(3)
22+
["timezone"]=>
23+
string(3) "GMT"
24+
}
25+
object(DateTimeImmutable)#1 (3) {
26+
["date"]=>
27+
string(26) "1970-01-01 00:00:00.000000"
28+
["timezone_type"]=>
29+
int(3)
30+
["timezone"]=>
31+
string(3) "GMT"
32+
}
33+

timecop.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,8 +1925,13 @@ static void _timecop_date_create_from_format(INTERNAL_FUNCTION_PARAMETERS, int i
19251925
INIT_ZVAL(orig_time);
19261926
ZVAL_STRINGL(&orig_time, orig_time_str, orig_time_len, 0);
19271927
#endif
1928+
if (immutable) {
1929+
real_func = ORIG_FUNC_NAME("date_create_immutable_from_format");
1930+
} else {
1931+
real_func = ORIG_FUNC_NAME("date_create_from_format");
1932+
}
19281933

1929-
call_php_function_with_3_params(ORIG_FUNC_NAME("date_create_from_format"), &dt, &orig_format, &orig_time, orig_timezone);
1934+
call_php_function_with_3_params(real_func, &dt, &orig_format, &orig_time, orig_timezone);
19301935

19311936
#if PHP_MAJOR_VERSION >= 7
19321937
if (Z_TYPE(dt) == IS_FALSE) {
@@ -2021,12 +2026,6 @@ static void _timecop_date_create_from_format(INTERNAL_FUNCTION_PARAMETERS, int i
20212026
#else
20222027
call_php_function_with_3_params("sprintf", &new_time, &tmp, fixed_time, &orig_time);
20232028
#endif
2024-
2025-
if (immutable) {
2026-
real_func = ORIG_FUNC_NAME("date_create_immutable_from_format");
2027-
} else {
2028-
real_func = ORIG_FUNC_NAME("date_create_from_format");
2029-
}
20302029
#if PHP_MAJOR_VERSION >= 7
20312030
call_php_function_with_3_params(real_func, return_value, &new_format, &new_time, orig_timezone);
20322031
#else

0 commit comments

Comments
 (0)