Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions ext/readline/tests/readline_cli_auto_prepend.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
Interactive shell: auto_prepend_file is executed before input
--EXTENSIONS--
readline
--SKIPIF--
<?php
if (!function_exists('proc_open')) die('skip proc_open() not available');
?>
--FILE--
<?php
$prepend = tempnam(sys_get_temp_dir(), 'readline_cli_prepend');
file_put_contents($prepend, <<<'PHP'
<?php
echo "prepended\n";
define('READLINE_CLI_PREPENDED', 'ok');
readline_completion_function(static fn() => []);
PHP);

$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
$ini = getenv('TEST_PHP_EXTRA_ARGS');
$descriptorspec = [['pipe', 'r'], STDOUT, STDERR];
$proc = proc_open("$php $ini -d auto_prepend_file=" . escapeshellarg($prepend) . " -a", $descriptorspec, $pipes);
fwrite($pipes[0], "echo READLINE_CLI_PREPENDED . \"\n\";\n");
fwrite($pipes[0], "exit\n");
fclose($pipes[0]);
proc_close($proc);
unlink($prepend);
?>
--EXPECTF--
%AInteractive shell%Aprepended%Aok%A
39 changes: 39 additions & 0 deletions ext/readline/tests/readline_cli_completion_readline.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--TEST--
Interactive shell: default completion function
--EXTENSIONS--
readline
--SKIPIF--
<?php
if (READLINE_LIB !== "readline") die('skip readline only');
if (!function_exists('shell_exec')) die('skip shell_exec() not available');
?>
--FILE--
<?php
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
$ini = getenv('TEST_PHP_EXTRA_ARGS');

putenv('TERM=VT100');

$code = <<<'PHP'
$readline_cli_completion_variable = "variable\n";
echo $readline_cli_completion_var ;
#prec 3
echo "precision=" . ini_get("precision") . "\n";
function readline_cli_completion_function() { echo "function\n"; }
readline_cli_completion_fun );
define('READLINE_CLI_COMPLETION_CONSTANT', "constant\n");
echo READLINE_CLI_COMPLETION_CON ;
class ReadlineCliCompletionClass {
public const COMPLETION_CLASS_CONSTANT = "class constant\n";
public static function completionMethod() { echo "method\n"; }
}
echo ReadlineCliCompletionCla ::class . "\n";
echo ReadlineCliCompletionClass::COMPLETION_CLASS_CON ;
ReadlineCliCompletionClass::completionM );
exit
PHP;

echo shell_exec("echo " . escapeshellarg($code) . " | $php $ini -a");
?>
--EXPECTF--
%AInteractive shell%Avariable%Aprecision=3%Afunction%Aconstant%AReadlineCliCompletionClass%Aclass constant%Amethod%A
22 changes: 22 additions & 0 deletions ext/readline/tests/readline_cli_long_input.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
Interactive shell: input buffer grows for long lines
--EXTENSIONS--
readline
--SKIPIF--
<?php
if (!function_exists('proc_open')) die('skip proc_open() not available');
?>
--FILE--
<?php
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
$ini = getenv('TEST_PHP_EXTRA_ARGS');
$descriptorspec = [['pipe', 'r'], STDOUT, STDERR];
$proc = proc_open("$php $ini -a", $descriptorspec, $pipes);
$long = str_repeat('x', 5000);
fwrite($pipes[0], 'echo strlen("' . $long . '") . "\n";' . "\n");
fwrite($pipes[0], "exit\n");
fclose($pipes[0]);
proc_close($proc);
?>
--EXPECTF--
%AInteractive shell%A5000%A
33 changes: 33 additions & 0 deletions ext/readline/tests/readline_cli_multiline_states.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--TEST--
Interactive shell: multiline input states
--EXTENSIONS--
readline
--SKIPIF--
<?php
if (!function_exists('proc_open')) die('skip proc_open() not available');
?>
--FILE--
<?php
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
$ini = getenv('TEST_PHP_EXTRA_ARGS');
$descriptorspec = [['pipe', 'r'], STDOUT, STDERR];
$proc = proc_open("$php $ini -a", $descriptorspec, $pipes);

fwrite($pipes[0], "\n");
fwrite($pipes[0], "# comment without ini assignment\n");
fwrite($pipes[0], "echo 'single \\\\ escape\n';\n");
fwrite($pipes[0], "echo \"double \\\\ escape\n\";\n");
fwrite($pipes[0], "echo strtoupper(\n\"paren\"\n);\n");
fwrite($pipes[0], "echo 6 /\n2;\n");
fwrite($pipes[0], "if (true) {\necho \"block\n\";\n}\n");
fwrite($pipes[0], "// line comment\n");
fwrite($pipes[0], "/*\n*/\necho \"comment\n\";\n");
fwrite($pipes[0], "#[AllowDynamicProperties]\nclass ReadlineCliCoverageClass {}\n");
fwrite($pipes[0], "echo \"attribute\n\";\n");
fwrite($pipes[0], "if (true) ?>outside-\n<?php\n{\necho \"inside\n\";\n}\n");
fwrite($pipes[0], "quit\n");
fclose($pipes[0]);
proc_close($proc);
?>
--EXPECTF--
%AInteractive shell%Asingle%Adouble%APAREN%A3%Ablock%Acomment%Aattribute%Aoutside-%Ainside%A
22 changes: 22 additions & 0 deletions ext/readline/tests/readline_cli_pager.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
Interactive shell: output through cli.pager
--EXTENSIONS--
readline
--SKIPIF--
<?php
if (!function_exists('proc_open')) die('skip proc_open() not available');
if (PHP_OS_FAMILY === 'Windows') die('skip cat pager is not portable on Windows');
?>
--FILE--
<?php
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
$ini = getenv('TEST_PHP_EXTRA_ARGS');
$descriptorspec = [['pipe', 'r'], STDOUT, STDERR];
$proc = proc_open("$php $ini -d cli.pager=cat -a", $descriptorspec, $pipes);
fwrite($pipes[0], "echo \"pager output\n\";\n");
fwrite($pipes[0], "quit\n");
fclose($pipes[0]);
proc_close($proc);
?>
--EXPECTF--
%Apager output%A
25 changes: 25 additions & 0 deletions ext/readline/tests/readline_cli_prompt.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
Interactive shell: custom prompt escape sequences
--EXTENSIONS--
readline
--SKIPIF--
<?php
if (READLINE_LIB !== "readline") die('skip readline only');
if (!function_exists('proc_open')) die('skip proc_open() not available');
?>
--FILE--
<?php
$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
$ini = getenv('TEST_PHP_EXTRA_ARGS');
$prompt = 'pre\\\\-\n-\t-\e-\v-\b-\>-\`-\q-' . "\xC3\xA9\xC3\xA9" . '-`echo "dyn";`-`-x ';
$descriptorspec = [['pipe', 'r'], STDOUT, STDERR];
$proc = proc_open("$php $ini -d " . escapeshellarg("cli.prompt=$prompt") . " -a", $descriptorspec, $pipes);
fwrite($pipes[0], "if (true) {\n");
fwrite($pipes[0], "echo \"prompt body\n\";\n");
fwrite($pipes[0], "}\n");
fwrite($pipes[0], "quit\n");
fclose($pipes[0]);
proc_close($proc);
?>
--EXPECTF--
%AInteractive shell%Aprompt contains unsupported unicode characters%Adyn%Aprompt body%A