xref: /PHP-8.3/sapi/cli/tests/017.phpt (revision dcc3255b)
1--TEST--
2CLI -a and libedit
3--EXTENSIONS--
4readline
5--SKIPIF--
6<?php
7include "skipif.inc";
8if (readline_info('done') !== NULL) {
9    die ("skip need readline support using libedit");
10}
11?>
12--FILE--
13<?php
14$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
15$ini = getenv('TEST_PHP_EXTRA_ARGS');
16$descriptorspec = [['pipe', 'r'], STDOUT, STDERR];
17
18$codes = array();
19
20$codes[1] = <<<EOT
21echo 'Hello world';
22exit
23EOT;
24
25$codes[] = <<<EOT
26echo 'multine
27single
28quote';
29exit
30EOT;
31
32$codes[] = <<<EOT
33echo <<<HEREDOC
34Here
35comes
36the
37doc
38HEREDOC;
39EOT;
40
41$codes[] = <<<EOT
42if (0) {
43    echo "I'm not there";
44}
45echo "Done";
46EOT;
47
48$codes[] = <<<EOT
49function a_function_with_some_name() {
50    echo "I was called!";
51}
52a_function_w	);
53EOT;
54
55foreach ($codes as $key => $code) {
56    echo "\n--------------\nSnippet no. $key:\n--------------\n";
57    $proc = proc_open("$php $ini -a", $descriptorspec, $pipes);
58    fwrite($pipes[0], $code);
59    fclose($pipes[0]);
60    proc_close($proc);
61}
62
63echo "\nDone\n";
64?>
65--EXPECT--
66--------------
67Snippet no. 1:
68--------------
69Interactive shell
70
71Hello world
72
73--------------
74Snippet no. 2:
75--------------
76Interactive shell
77
78multine
79single
80quote
81
82--------------
83Snippet no. 3:
84--------------
85Interactive shell
86
87Here
88comes
89the
90doc
91
92--------------
93Snippet no. 4:
94--------------
95Interactive shell
96
97Done
98
99--------------
100Snippet no. 5:
101--------------
102Interactive shell
103
104
105Parse error: Unmatched ')' in php shell code on line 1
106
107Done
108