parent
0033a243d0
commit
16787142d6
12 changed files with 398 additions and 41 deletions
@ -0,0 +1,47 @@ |
||||
<?php |
||||
|
||||
namespace PhpAot\Php; |
||||
|
||||
class Constants |
||||
{ |
||||
const array CPP_RESERVED_NAMES = [ |
||||
'auto', |
||||
'break', |
||||
'case', |
||||
'catch', |
||||
'class', |
||||
'struct', |
||||
'const', |
||||
'continue', |
||||
'default', |
||||
'do', |
||||
'else', |
||||
'elseif', |
||||
'enum', |
||||
'extends', |
||||
'final', |
||||
'finally', |
||||
'for', |
||||
'function', |
||||
'global', |
||||
'if', |
||||
'int', |
||||
'double', |
||||
'float', |
||||
'false', |
||||
'for', |
||||
'if', |
||||
'int', |
||||
'new', |
||||
'null', |
||||
'or', |
||||
'and', |
||||
'private', |
||||
'protected', |
||||
'public', |
||||
'return', |
||||
'static', |
||||
'pipe', |
||||
'errno', // Linux error code |
||||
]; |
||||
} |
||||
@ -0,0 +1,63 @@ |
||||
--TEST-- |
||||
Test scandir() function : basic functionality |
||||
--FILE-- |
||||
<?php |
||||
/* |
||||
* Test basic functionality of scandir() |
||||
*/ |
||||
|
||||
echo "*** Testing scandir() : basic functionality ***\n"; |
||||
|
||||
// include file.inc for create_files function |
||||
include (__DIR__ . '/../file/file.inc'); |
||||
|
||||
// set up directory |
||||
$directory = __DIR__ . '/scandir_basic'; |
||||
mkdir($directory); |
||||
create_files($directory, 3); |
||||
|
||||
echo "\n-- scandir() with mandatory arguments --\n"; |
||||
var_dump(scandir($directory)); |
||||
|
||||
echo "\n-- scandir() with all arguments --\n"; |
||||
$sorting_order = SCANDIR_SORT_DESCENDING; |
||||
$context = stream_context_create(); |
||||
var_dump(scandir($directory, $sorting_order, $context)); |
||||
|
||||
delete_files($directory, 3); |
||||
?> |
||||
--CLEAN-- |
||||
<?php |
||||
$directory = __DIR__ . '/scandir_basic'; |
||||
rmdir($directory); |
||||
?> |
||||
--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) "." |
||||
} |
||||
@ -0,0 +1,33 @@ |
||||
--TEST-- |
||||
exec, system, passthru — Basic command execution functions |
||||
--SKIPIF-- |
||||
<?php |
||||
// If this does not work for Windows, please uncomment or fix test |
||||
// if(substr(PHP_OS, 0, 3) == "WIN") die("skip not for Windows"); |
||||
?> |
||||
--FILE-- |
||||
<?php |
||||
$cmd = "echo abc\n\0command"; |
||||
try { |
||||
var_dump(exec($cmd, $output)); |
||||
} catch (\ValueError $e) { |
||||
echo $e->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 |
||||
|
||||
@ -0,0 +1,11 @@ |
||||
--TEST-- |
||||
Basic syslog test |
||||
--FILE-- |
||||
<?php |
||||
openlog('phpt', LOG_NDELAY | LOG_PID, LOG_USER); |
||||
|
||||
syslog(LOG_WARNING, 'Basic syslog test'); |
||||
|
||||
closelog(); |
||||
?> |
||||
--EXPECT-- |
||||
@ -0,0 +1,25 @@ |
||||
--TEST-- |
||||
time_nanosleep — Delay for a number of seconds and nanoseconds |
||||
--SKIPIF-- |
||||
<?php if (!function_exists('time_nanosleep')) die("skip"); |
||||
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test"); |
||||
?> |
||||
--CREDITS-- |
||||
Àlex Corretgé - alex@corretge.cat |
||||
--FILE-- |
||||
<?php |
||||
$nano = time_nanosleep(2, 100000); |
||||
|
||||
if ($nano === true) { |
||||
echo "Slept for 2 seconds, 100 milliseconds.\n"; |
||||
} elseif ($nano === false) { |
||||
echo "Sleeping failed.\n"; |
||||
} elseif (is_array($nano)) { |
||||
$seconds = $nano['seconds']; |
||||
$nanoseconds = $nano['nanoseconds']; |
||||
echo "Interrupted by a signal.\n"; |
||||
echo "Time remaining: $seconds seconds, $nanoseconds nanoseconds."; |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
Slept for 2 seconds, 100 milliseconds. |
||||
@ -0,0 +1,18 @@ |
||||
--TEST-- |
||||
Test invalid bindto |
||||
--FILE-- |
||||
<?php |
||||
$ctx = stream_context_create([ |
||||
'socket' => [ |
||||
'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 |
||||
@ -0,0 +1,15 @@ |
||||
--TEST-- |
||||
Test closelog() function : basic functionality |
||||
--FILE-- |
||||
<?php |
||||
echo "*** Testing closelog() : basic functionality ***\n"; |
||||
|
||||
// Zero arguments |
||||
echo "\n-- Testing closelog() function with Zero arguments --\n"; |
||||
var_dump( closelog() ); |
||||
?> |
||||
--EXPECT-- |
||||
*** Testing closelog() : basic functionality *** |
||||
|
||||
-- Testing closelog() function with Zero arguments -- |
||||
bool(true) |
||||
@ -0,0 +1,54 @@ |
||||
--TEST-- |
||||
Test fsockopen() function : basic functionality |
||||
--FILE-- |
||||
<?php |
||||
echo "*** Testing fsockopen() : basic functionality ***\n"; |
||||
|
||||
echo "Open a server socket\n"; |
||||
|
||||
for ($i=0; $i<100; $i++) { |
||||
$port = rand(10000, 65000); |
||||
/* Setup socket server */ |
||||
$server = @stream_socket_server("tcp://127.0.0.1:$port"); |
||||
if ($server) { |
||||
break; |
||||
} |
||||
} |
||||
|
||||
// Initialise all required variables |
||||
$hostname = 'tcp://127.0.0.1'; // loopback address |
||||
$errno = null; |
||||
$errstr = null; |
||||
$timeout = 1.5; |
||||
|
||||
echo "\nCalling fsockopen() with all possible arguments:\n"; |
||||
$client = fsockopen($hostname, $port, $errno, $errstr, $timeout); |
||||
var_dump($client); |
||||
fclose($client); |
||||
|
||||
echo "\nCalling fsockopen() with mandatory arguments:\n"; |
||||
$second_client = fsockopen($hostname, $port); |
||||
var_dump($second_client); |
||||
fclose($second_client); |
||||
|
||||
echo "\nCalling fsockopen() with address and port in same string:\n"; |
||||
$address = $hostname . ':' . $port; |
||||
$third_client = fsockopen($address); |
||||
var_dump($third_client); |
||||
fclose($third_client); |
||||
|
||||
echo "Done"; |
||||
?> |
||||
--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 |
||||
@ -0,0 +1,41 @@ |
||||
--TEST-- |
||||
Test fsockopen() function : error conditions |
||||
--FILE-- |
||||
<?php |
||||
echo "*** Testing fsockopen() : basic error conditions ***\n"; |
||||
|
||||
echo "\n-- Attempting to connect to a non-existent socket --\n"; |
||||
$hostname = 'tcp://127.0.0.1'; // loopback address |
||||
$port = 31337; |
||||
$errno = null; |
||||
$errstr = null; |
||||
$timeout = 1.5; |
||||
var_dump( fsockopen($hostname, $port, $errno, $errstr, $timeout) ); |
||||
var_dump($errstr); |
||||
|
||||
echo "\n-- Attempting to connect using an invalid protocol --\n"; |
||||
$hostname = 'invalid://127.0.0.1'; // loopback address |
||||
$port = 31337; |
||||
$errno = null; |
||||
$errstr = null; |
||||
$timeout = 1.5; |
||||
var_dump( fsockopen($hostname, $port, $errno, $errstr, $timeout) ); |
||||
var_dump($errstr); |
||||
|
||||
echo "Done"; |
||||
?> |
||||
--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 |
||||
@ -0,0 +1,38 @@ |
||||
--TEST-- |
||||
testing fsockopen without a protocol string |
||||
--FILE-- |
||||
<?php |
||||
|
||||
echo "Open a server socket\n"; |
||||
for ($i=0; $i<100; $i++) { |
||||
$port = rand(10000, 65000); |
||||
/* Setup socket server */ |
||||
$server = @stream_socket_server("tcp://127.0.0.1:$port"); |
||||
if ($server) { |
||||
break; |
||||
} |
||||
} |
||||
|
||||
echo "\nCalling fsockopen() without a protocol in the hostname string:\n"; |
||||
$hostname = '127.0.0.1'; |
||||
$client = fsockopen($hostname, $port); |
||||
var_dump($client); |
||||
fclose($client); |
||||
|
||||
echo "\nCalling fsockopen() with address and port in same string, without a protocol:\n"; |
||||
$address = $hostname . ':' . $port; |
||||
$second_client = fsockopen($address); |
||||
var_dump($second_client); |
||||
fclose($second_client); |
||||
|
||||
echo "Done"; |
||||
?> |
||||
--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 |
||||
@ -0,0 +1,48 @@ |
||||
--TEST-- |
||||
testing fsockopen() with udp sockets |
||||
--FILE-- |
||||
<?php |
||||
|
||||
$hostname = 'udp://127.0.0.1'; |
||||
$port = '31337'; |
||||
|
||||
echo "Open a server socket\n"; |
||||
$server = stream_socket_server($hostname . ':' . $port, $errno, $errstr, STREAM_SERVER_BIND); |
||||
|
||||
echo "\nCalling fsockopen():\n"; |
||||
$client = fsockopen($hostname, $port); |
||||
var_dump($client); |
||||
|
||||
echo "\nPass some data between the sockets:\n"; |
||||
fwrite($client, "0123456789"); |
||||
var_dump(fread($server, 10)); |
||||
fclose($client); |
||||
|
||||
echo "\nCalling fsockopen() with address and port in same string:\n"; |
||||
$address = $hostname . ':' . $port; |
||||
$second_client = fsockopen($address); |
||||
var_dump($second_client); |
||||
|
||||
echo "\nPass some data between the sockets:\n"; |
||||
fwrite($second_client, "0123456789"); |
||||
var_dump(fread($server, 10)); |
||||
fclose($second_client); |
||||
|
||||
echo "Done"; |
||||
|
||||
?> |
||||
--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 |
||||
Loading…
Reference in new issue