diff --git a/src/Php/Constants.php b/src/Php/Constants.php new file mode 100644 index 00000000..1a556308 --- /dev/null +++ b/src/Php/Constants.php @@ -0,0 +1,47 @@ +name->getType() != 'Name') { + if ($expr->name->getType() != 'Name' and !($expr->name instanceof Node\Name\FullyQualified)) { abort($expr); } $name = $this->parseIdentifier($expr->name); @@ -1991,6 +1953,8 @@ class Translator extends \PhpAot\Core\Translator return 'true'; } elseif ($name === 'false') { return 'false'; + } elseif ($name === 'PHP_EOL') { + return '"' . $this->escapeString(PHP_EOL) . '"'; } return 'php::constant("' . $name . '")'; } @@ -2035,7 +1999,7 @@ class Translator extends \PhpAot\Core\Translator private function escapeVarName(string $name): string { - if (in_array($name, $this->reservedNames)) { + if (in_array($name, Constants::CPP_RESERVED_NAMES)) { return '_php__var__' . $name; } else { return $name; diff --git a/tests/std/dir/scandir_basic.phpt b/tests/std/dir/scandir_basic.phpt new file mode 100644 index 00000000..d86aa291 --- /dev/null +++ b/tests/std/dir/scandir_basic.phpt @@ -0,0 +1,63 @@ +--TEST-- +Test scandir() function : basic functionality +--FILE-- + +--CLEAN-- + +--EXPECT-- +*** Testing scandir() : basic functionality *** + +-- scandir() with mandatory arguments -- +array(5) { + [0]=> + string(1) "." + [1]=> + string(2) ".." + [2]=> + string(9) "file1.tmp" + [3]=> + string(9) "file2.tmp" + [4]=> + string(9) "file3.tmp" +} + +-- scandir() with all arguments -- +array(5) { + [0]=> + string(9) "file3.tmp" + [1]=> + string(9) "file2.tmp" + [2]=> + string(9) "file1.tmp" + [3]=> + string(2) ".." + [4]=> + string(1) "." +} diff --git a/tests/std/misc/exec_basic1.phpt b/tests/std/misc/exec_basic1.phpt new file mode 100644 index 00000000..db26e73b --- /dev/null +++ b/tests/std/misc/exec_basic1.phpt @@ -0,0 +1,33 @@ +--TEST-- +exec, system, passthru — Basic command execution functions +--SKIPIF-- + +--FILE-- +getMessage() . \PHP_EOL; +} +try { + var_dump(system($cmd, $output)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(passthru($cmd, $output)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +?> +--EXPECT-- +string(3) "abc" +abc +string(3) "abc" +abc +NULL + diff --git a/tests/std/misc/syslog_basic.phpt b/tests/std/misc/syslog_basic.phpt new file mode 100644 index 00000000..f73d950c --- /dev/null +++ b/tests/std/misc/syslog_basic.phpt @@ -0,0 +1,11 @@ +--TEST-- +Basic syslog test +--FILE-- + +--EXPECT-- diff --git a/tests/std/misc/time_nanosleep_basic.phpt b/tests/std/misc/time_nanosleep_basic.phpt new file mode 100644 index 00000000..3f20b00f --- /dev/null +++ b/tests/std/misc/time_nanosleep_basic.phpt @@ -0,0 +1,25 @@ +--TEST-- +time_nanosleep — Delay for a number of seconds and nanoseconds +--SKIPIF-- + +--CREDITS-- +Àlex Corretgé - alex@corretge.cat +--FILE-- + +--EXPECT-- +Slept for 2 seconds, 100 milliseconds. diff --git a/tests/std/network/bindto.phpt b/tests/std/network/bindto.phpt new file mode 100644 index 00000000..749103db --- /dev/null +++ b/tests/std/network/bindto.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test invalid bindto +--FILE-- + [ + 'bindto' => 'invalid', + ], +]); +$fp = stream_socket_client( + 'tcp://www.' . str_repeat('x', 100) . '.com:80', + $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $ctx +); +?> +--EXPECTF-- +Warning: %s: php_network_getaddresses: getaddrinfo for www.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.com failed: %s in %s + +Warning: %s: Unable to connect to tcp://www.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.com:80 (php_network_getaddresses: getaddrinfo for %s failed: %s) in %s diff --git a/tests/std/network/closelog_basic.phpt b/tests/std/network/closelog_basic.phpt new file mode 100644 index 00000000..d52e55ae --- /dev/null +++ b/tests/std/network/closelog_basic.phpt @@ -0,0 +1,15 @@ +--TEST-- +Test closelog() function : basic functionality +--FILE-- + +--EXPECT-- +*** Testing closelog() : basic functionality *** + +-- Testing closelog() function with Zero arguments -- +bool(true) diff --git a/tests/std/network/fsockopen_basic.phpt b/tests/std/network/fsockopen_basic.phpt new file mode 100644 index 00000000..1ee1f621 --- /dev/null +++ b/tests/std/network/fsockopen_basic.phpt @@ -0,0 +1,54 @@ +--TEST-- +Test fsockopen() function : basic functionality +--FILE-- + +--EXPECTF-- +*** Testing fsockopen() : basic functionality *** +Open a server socket + +Calling fsockopen() with all possible arguments: +resource(%d) of type (stream) + +Calling fsockopen() with mandatory arguments: +resource(%d) of type (stream) + +Calling fsockopen() with address and port in same string: +resource(%d) of type (stream) +Done diff --git a/tests/std/network/fsockopen_error.phpt b/tests/std/network/fsockopen_error.phpt new file mode 100644 index 00000000..1f908e0b --- /dev/null +++ b/tests/std/network/fsockopen_error.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test fsockopen() function : error conditions +--FILE-- + +--EXPECTF-- +*** Testing fsockopen() : basic error conditions *** + +-- Attempting to connect to a non-existent socket -- + +Warning: %s: Unable to connect to tcp://127.0.0.1:31337 (%a) in %s +bool(false) +string(%d) "%a" + +-- Attempting to connect using an invalid protocol -- + +Warning: %s: Unable to connect to invalid://127.0.0.1:31337 (Unable to find the socket transport "invalid" - did you forget to enable it when you configured PHP?) in %s +bool(false) +string(100) "Unable to find the socket transport "invalid" - did you forget to enable it when you configured PHP?" +Done diff --git a/tests/std/network/fsockopen_variation1.phpt b/tests/std/network/fsockopen_variation1.phpt new file mode 100644 index 00000000..bb1b0f15 --- /dev/null +++ b/tests/std/network/fsockopen_variation1.phpt @@ -0,0 +1,38 @@ +--TEST-- +testing fsockopen without a protocol string +--FILE-- + +--EXPECTF-- +Open a server socket + +Calling fsockopen() without a protocol in the hostname string: +resource(%d) of type (stream) + +Calling fsockopen() with address and port in same string, without a protocol: +resource(%d) of type (stream) +Done diff --git a/tests/std/network/fsockopen_variation2.phpt b/tests/std/network/fsockopen_variation2.phpt new file mode 100644 index 00000000..262ae0ba --- /dev/null +++ b/tests/std/network/fsockopen_variation2.phpt @@ -0,0 +1,48 @@ +--TEST-- +testing fsockopen() with udp sockets +--FILE-- + +--EXPECTF-- +Open a server socket + +Calling fsockopen(): +resource(%d) of type (stream) + +Pass some data between the sockets: +string(10) "0123456789" + +Calling fsockopen() with address and port in same string: +resource(%d) of type (stream) + +Pass some data between the sockets: +string(10) "0123456789" +Done