parent
27aa8ea930
commit
684c47458b
4 changed files with 86 additions and 3 deletions
@ -0,0 +1,10 @@ |
||||
<?php |
||||
|
||||
function datetimeDirectCalls(int $timestamp): string |
||||
{ |
||||
$now = time(); |
||||
return date('Y-m-d', $timestamp) |
||||
. gmdate('Y-m-d H:i:s', $timestamp) |
||||
. date('U', $timestamp) |
||||
. $now; |
||||
} |
||||
@ -0,0 +1,26 @@ |
||||
<?php |
||||
|
||||
use TypePhp\CompilerTest; |
||||
|
||||
final class DatetimeOptimizerTest extends BaseTest |
||||
{ |
||||
public function testCoreDatetimeCallsUseDirectPhpxWrappers(): void |
||||
{ |
||||
global $translator; |
||||
|
||||
$compiler = CompilerTest::create(TYPEPHP_ROOT_PATH); |
||||
$translator = $compiler; |
||||
$source = TYPEPHP_ROOT_PATH . '/phpunit/code/datetime-direct-calls.php'; |
||||
$compiler->addFiles([$source]); |
||||
$compiler->prepareFile($source); |
||||
$generated = $compiler->convertFile($source); |
||||
$code = file_get_contents($generated); |
||||
|
||||
self::assertIsString($code); |
||||
self::assertSame(1, substr_count($code, 'php::fn::time(')); |
||||
self::assertSame(2, substr_count($code, 'php::fn::date(')); |
||||
self::assertSame(1, substr_count($code, 'php::fn::gmdate(')); |
||||
self::assertStringNotContainsString('get_persistent_func', $code); |
||||
self::assertStringNotContainsString('php::call(', $code); |
||||
} |
||||
} |
||||
@ -0,0 +1,18 @@ |
||||
--TEST-- |
||||
date, gmdate and time use direct PHPX wrappers |
||||
--FILE-- |
||||
<?php |
||||
|
||||
function main(): void |
||||
{ |
||||
date_default_timezone_set('Asia/Shanghai'); |
||||
|
||||
var_dump(date('Y-m-d H:i:s', 0)); |
||||
var_dump(gmdate('Y-m-d H:i:s', 0)); |
||||
var_dump(time() > 0); |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
string(19) "1970-01-01 08:00:00" |
||||
string(19) "1970-01-01 00:00:00" |
||||
bool(true) |
||||
Loading…
Reference in new issue