1--TEST-- 2CLI -a and libedit 3--EXTENSIONS-- 4readline 5--ENV-- 6PHP_HISTFILE= 7--SKIPIF-- 8<?php 9include "skipif.inc"; 10if (readline_info('done') !== NULL) { 11 die ("skip need readline support using libedit"); 12} 13?> 14--FILE-- 15<?php 16function runReplCodes($codes) { 17 $php = getenv('TEST_PHP_EXECUTABLE_ESCAPED'); 18 $ini = getenv('TEST_PHP_EXTRA_ARGS'); 19 $descriptorspec = [['pipe', 'r'], STDOUT, STDERR]; 20 foreach ($codes as $key => $code) { 21 echo "\n--------------\nSnippet no. $key:\n--------------\n"; 22 $proc = proc_open("$php $ini -a", $descriptorspec, $pipes); 23 fwrite($pipes[0], $code); 24 fclose($pipes[0]); 25 proc_close($proc); 26 } 27} 28 29$codes = array(); 30 31$codes[1] = <<<EOT 32echo 'Hello world'; 33exit 34EOT; 35 36$codes[] = <<<EOT 37echo 'multine 38single 39quote'; 40exit 41EOT; 42 43$codes[] = <<<EOT 44echo <<<HEREDOC 45Here 46comes 47the 48doc 49HEREDOC; 50EOT; 51 52$codes[] = <<<EOT 53if (0) { 54 echo "I'm not there"; 55} 56echo "Done"; 57EOT; 58 59$codes[] = <<<EOT 60function a_function_with_some_name() { 61 echo "I was called!"; 62} 63a_function_w ); 64EOT; 65 66runReplCodes($codes); 67echo "\nDone\n"; 68 69$dir = PHP_OS_FAMILY == 'Windows' ? getenv("USERPROFILE") : getenv("HOME"); 70var_dump(file_exists($dir . '/.php_history')); 71 72$php_history_tmp = sprintf('%s%s%s', sys_get_temp_dir(), DIRECTORY_SEPARATOR, 'php_history'); 73putenv('PHP_HISTFILE=' . $php_history_tmp); 74var_dump(file_exists($php_history_tmp)); 75 76$last[6] = <<<EOT 77echo 'Hello World'; 78exit 79EOT; 80runReplCodes($last); 81echo "\nDone\n"; 82 83$php_history_path = PHP_OS_FAMILY == 'Windows' ? getenv("USERPROFILE") : $php_history_tmp; 84var_dump(file_exists($php_history_path)); 85@unlink($php_history_tmp); 86?> 87--EXPECT-- 88-------------- 89Snippet no. 1: 90-------------- 91Interactive shell 92 93Hello world 94 95-------------- 96Snippet no. 2: 97-------------- 98Interactive shell 99 100multine 101single 102quote 103 104-------------- 105Snippet no. 3: 106-------------- 107Interactive shell 108 109Here 110comes 111the 112doc 113 114-------------- 115Snippet no. 4: 116-------------- 117Interactive shell 118 119Done 120 121-------------- 122Snippet no. 5: 123-------------- 124Interactive shell 125 126 127Parse error: Unmatched ')' in php shell code on line 1 128 129Done 130bool(true) 131bool(false) 132 133-------------- 134Snippet no. 6: 135-------------- 136Interactive shell 137 138Hello World 139 140Done 141bool(true) 142