]> granicus.if.org Git - php/commitdiff
Add VT100 support for Windows
authorMichele Locati <michele@locati.it>
Mon, 29 Aug 2016 09:57:53 +0000 (11:57 +0200)
committerAnatol Belski <ab@php.net>
Fri, 28 Oct 2016 17:23:00 +0000 (19:23 +0200)
Fix function names prefix

Use Unicode version of GetFinalPathNameByHandle

Use EG(windows_version_info) instead of RtlGetVersion

Use the specified handle_id instead of STD_OUTPUT_HANDLE

Switch from stream name to stream resource

Allow running tests capturing only stdout and/or stderr

Add tests for stream_vt100_support function

Export Win32 console functions

Fix x64 build

Use zend_long instead of long long, use GetConsole instead of GetFinalPathNameByHandleW to check if a handle is a valid console stream

Always use zend_long on any platform

Use _get_osfhandle to determine the standard handle

Accept stream names

Raise warnings in case of invalid stream parameter

Return true if disabling VT100 support on a not-console/redirected stream or on old Windows versions

Remove php_win32_console_os_supports_vt100

Differentiate stdin vs stdout/stderr

Simplify setting flag

Allow avoid piping STDIN

Let stream_vt100_support accept only resources

Fix run-tests

Revert console flags in case of failure

Simplify logic of stream_vt100_support when setting the flag

Return true if succeeded, false otherwise

Drop support for STDIN

More comprehensive tests for stream_vt100_support

Remove old tests

Fix name of included file and use absolute paths

Enable ENABLE_VIRTUAL_TERMINAL_PROCESSING on Windows by default

Remove tests for stream_vt100_support

Split stream_vt100_support into stream_isatty+sapi_windows_vt100_support

Add tests for stream_isatty

Add tests for sapi_windows_vt100_support

Return null from stream_isatty is neither Windows nor Posix

Fallback to S_ISCHR if neither Windows nor Posix

Avoid defining argc since it's only used once

Better comment about php_win32_console_fileno_is_console

Use events instead of cNumberOfEvents

Do not restore previous console mode

We need to restore previous console mode on failing SetConsole calls only for STDIN

Don't configure STDOUT/STDERR on Windows with PHP_CLI_WIN32_NO_CONSOLE

29 files changed:
ext/standard/basic_functions.c
ext/standard/streamsfuncs.c
ext/standard/streamsfuncs.h
run-tests.php
sapi/cli/php_cli.c
tests/output/sapi_windows_vt100_support.inc [new file with mode: 0644]
tests/output/sapi_windows_vt100_support_notwindows.phpt [new file with mode: 0644]
tests/output/sapi_windows_vt100_support_winko_err.phpt [new file with mode: 0644]
tests/output/sapi_windows_vt100_support_winko_in-err.phpt [new file with mode: 0644]
tests/output/sapi_windows_vt100_support_winko_in-out-err.phpt [new file with mode: 0644]
tests/output/sapi_windows_vt100_support_winko_in-out.phpt [new file with mode: 0644]
tests/output/sapi_windows_vt100_support_winko_out-err.phpt [new file with mode: 0644]
tests/output/sapi_windows_vt100_support_winko_out.phpt [new file with mode: 0644]
tests/output/sapi_windows_vt100_support_winok_err.phpt [new file with mode: 0644]
tests/output/sapi_windows_vt100_support_winok_in-err.phpt [new file with mode: 0644]
tests/output/sapi_windows_vt100_support_winok_in-out-err.phpt [new file with mode: 0644]
tests/output/sapi_windows_vt100_support_winok_in-out.phpt [new file with mode: 0644]
tests/output/sapi_windows_vt100_support_winok_out-err.phpt [new file with mode: 0644]
tests/output/sapi_windows_vt100_support_winok_out.phpt [new file with mode: 0644]
tests/output/stream_isatty.inc [new file with mode: 0644]
tests/output/stream_isatty_err.phpt [new file with mode: 0644]
tests/output/stream_isatty_in-err.phpt [new file with mode: 0644]
tests/output/stream_isatty_in-out-err.phpt [new file with mode: 0644]
tests/output/stream_isatty_in-out.phpt [new file with mode: 0644]
tests/output/stream_isatty_out-err.phpt [new file with mode: 0644]
tests/output/stream_isatty_out.phpt [new file with mode: 0644]
win32/build/config.w32
win32/console.c [new file with mode: 0644]
win32/console.h [new file with mode: 0644]

index af66d1e0a679d07476d49fa22445c15672b09ec4..ba616dff2325d1fc776c1532e5101ef3d2aefaa3 100644 (file)
@@ -2013,6 +2013,17 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_stream_supports_lock, 0, 0, 1)
     ZEND_ARG_INFO(0, stream)
 ZEND_END_ARG_INFO()
 
+ZEND_BEGIN_ARG_INFO_EX(arginfo_stream_isatty, 0, 0, 1)
+       ZEND_ARG_INFO(0, stream)
+ZEND_END_ARG_INFO()
+
+#ifdef PHP_WIN32
+ZEND_BEGIN_ARG_INFO_EX(arginfo_sapi_windows_vt100_support, 0, 0, 1)
+       ZEND_ARG_INFO(0, stream)
+       ZEND_ARG_INFO(0, enable)
+ZEND_END_ARG_INFO()
+#endif
+
 ZEND_BEGIN_ARG_INFO_EX(arginfo_stream_select, 0, 0, 4)
        ZEND_ARG_INFO(1, read_streams) /* ARRAY_INFO(1, read_streams, 1) */
        ZEND_ARG_INFO(1, write_streams) /* ARRAY_INFO(1, write_streams, 1) */
@@ -3146,6 +3157,10 @@ const zend_function_entry basic_functions[] = { /* {{{ */
        PHP_FE(stream_copy_to_stream,                                                                                   arginfo_stream_copy_to_stream)
        PHP_FE(stream_get_contents,                                                                                             arginfo_stream_get_contents)
        PHP_FE(stream_supports_lock,                                                                                    arginfo_stream_supports_lock)
+       PHP_FE(stream_isatty,                                                                                                   arginfo_stream_isatty)
+#ifdef PHP_WIN32
+       PHP_FE(sapi_windows_vt100_support,                                                                              arginfo_sapi_windows_vt100_support)
+#endif
        PHP_FE(fgetcsv,                                                                                                                 arginfo_fgetcsv)
        PHP_FE(fputcsv,                                                                                                                 arginfo_fputcsv)
        PHP_FE(flock,                                                                                                                   arginfo_flock)
index 01a49e567930a51290738525dc326a85855c55e1..5979c8cccb3595e88123eeaa87e5c8ac2b48c156 100644 (file)
@@ -37,6 +37,7 @@ typedef unsigned long long php_timeout_ull;
 #else
 #include "win32/select.h"
 #include "win32/sockets.h"
+#include "win32/console.h"
 typedef unsigned __int64 php_timeout_ull;
 #endif
 
@@ -1569,6 +1570,119 @@ PHP_FUNCTION(stream_supports_lock)
        RETURN_TRUE;
 }
 
+/* {{{ proto proto stream_isatty(resource stream)
+Check if a stream is a TTY.
+*/
+PHP_FUNCTION(stream_isatty)
+{
+       zval *zsrc;
+       php_stream *stream;
+       zend_long fileno;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zsrc) == FAILURE) {
+               RETURN_FALSE;
+       }
+
+       php_stream_from_zval(stream, zsrc);
+
+       if (php_stream_can_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT) == SUCCESS) {
+               php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT, (void*)&fileno, 0);
+       }
+       else if (php_stream_can_cast(stream, PHP_STREAM_AS_FD) == SUCCESS) {
+               php_stream_cast(stream, PHP_STREAM_AS_FD, (void*)&fileno, 0);
+       }
+       else {
+               RETURN_FALSE;
+       }
+
+#ifdef PHP_WIN32
+       /* Check if the Windows standard handle is redirected to file */
+       if (php_win32_console_fileno_is_console(fileno)) {
+               RETURN_TRUE;
+       }
+       else {
+               RETURN_FALSE;
+       }
+#elif HAVE_POSIX
+       /* Check if the file descriptor identifier is a terminal */
+       if (isatty(fileno)) {
+               RETURN_TRUE;
+       }
+       else {
+               RETURN_FALSE;
+       }
+#else
+       zend_stat_t stat;
+       if (zend_fstat(fileno, &stat) == 0) {
+               if ((stat.st_mode & /*S_IFMT*/0170000) == /*S_IFCHR*/0020000) {
+                       RETURN_TRUE;
+               }
+       }
+       RETURN_NULL();
+#endif
+}
+
+#ifdef PHP_WIN32
+/* {{{ proto proto sapi_windows_vt100_support(resource stream[, bool enable])
+   Get or set VT100 support for the specified stream associated to an
+   output buffer of a Windows console.
+*/
+PHP_FUNCTION(sapi_windows_vt100_support)
+{
+       zval *zsrc;
+       php_stream *stream;
+       zend_bool enable;
+       zend_long fileno;
+
+       int argc = ZEND_NUM_ARGS();
+
+       if (zend_parse_parameters(argc, "r|b", &zsrc, &enable) == FAILURE) {
+               RETURN_FALSE;
+       }
+
+       php_stream_from_zval(stream, zsrc);
+
+       if (php_stream_can_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT) == SUCCESS) {
+               php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT, (void*)&fileno, 0);
+       }
+       else if (php_stream_can_cast(stream, PHP_STREAM_AS_FD) == SUCCESS) {
+               php_stream_cast(stream, PHP_STREAM_AS_FD, (void*)&fileno, 0);
+       }
+       else {
+               zend_internal_type_error(
+                       ZEND_ARG_USES_STRICT_TYPES(),
+                       "%s() was not able to analyze the specified stream",
+                       get_active_function_name()
+               );
+               RETURN_FALSE;
+       }
+
+       /* Check if the file descriptor is a console */
+       if (!php_win32_console_fileno_is_console(fileno)) {
+               RETURN_FALSE;
+       }
+
+       if (argc == 1) {
+               /* Check if the Windows standard handle has VT100 control codes enabled */
+               if (php_win32_console_fileno_has_vt100(fileno)) {
+                       RETURN_TRUE;
+               }
+               else {
+                       RETURN_FALSE;
+               }
+       }
+       else {
+               /* Enable/disable VT100 control codes support for the specified Windows standard handle */
+               if (php_win32_console_fileno_set_vt100(fileno, enable ? TRUE : FALSE)) {
+                       RETURN_TRUE;
+               }
+               else {
+                       RETURN_FALSE;
+               }
+       }
+}
+#endif
+
 #ifdef HAVE_SHUTDOWN
 /* {{{ proto int stream_socket_shutdown(resource stream, int how)
        causes all or part of a full-duplex connection on the socket associated
index 45f51c29549b85dbce6138ae22fe3b95e3066876..0b7b0c67059fb8edba5e158ee32fc036e5f7346f 100644 (file)
@@ -61,6 +61,10 @@ PHP_FUNCTION(stream_socket_shutdown);
 PHP_FUNCTION(stream_resolve_include_path);
 PHP_FUNCTION(stream_is_local);
 PHP_FUNCTION(stream_supports_lock);
+PHP_FUNCTION(stream_isatty);
+#ifdef PHP_WIN32
+PHP_FUNCTION(sapi_windows_vt100_support);
+#endif
 
 #if HAVE_SOCKETPAIR
 PHP_FUNCTION(stream_socket_pair);
index 20d148b0b0038488226645c06091cd69747f1cbd..247e7d531389c29b844387006368a1bc8029eefa 100755 (executable)
@@ -1057,7 +1057,7 @@ function error_report($testname, $logname, $tested)
        }
 }
 
-function system_with_timeout($commandline, $env = null, $stdin = null)
+function system_with_timeout($commandline, $env = null, $stdin = null, $captureStdIn = true, $captureStdOut = true, $captureStdErr = true)
 {
        global $leak_check, $cwd;
 
@@ -1068,21 +1068,29 @@ function system_with_timeout($commandline, $env = null, $stdin = null)
                $bin_env[$key] = $value;
        }
 
-       $proc = proc_open($commandline, array(
-               0 => array('pipe', 'r'),
-               1 => array('pipe', 'w'),
-               2 => array('pipe', 'w')
-               ), $pipes, $cwd, $bin_env, array('suppress_errors' => true, 'binary_pipes' => true));
+       $descriptorspec = array();
+       if ($captureStdIn) {
+               $descriptorspec[0] = array('pipe', 'r');
+       }
+       if ($captureStdOut) {
+               $descriptorspec[1] = array('pipe', 'w');
+       }
+       if ($captureStdErr) {
+               $descriptorspec[2] = array('pipe', 'w');
+       }
+       $proc = proc_open($commandline, $descriptorspec, $pipes, $cwd, $bin_env, array('suppress_errors' => true, 'binary_pipes' => true));
 
        if (!$proc) {
                return false;
        }
 
-       if (!is_null($stdin)) {
-               fwrite($pipes[0], $stdin);
+       if ($captureStdIn) {
+               if (!is_null($stdin)) {
+                       fwrite($pipes[0], $stdin);
+               }
+               fclose($pipes[0]);
+               unset($pipes[0]);
        }
-       fclose($pipes[0]);
-       unset($pipes[0]);
 
        $timeout = $leak_check ? 300 : (isset($env['TEST_TIMEOUT']) ? $env['TEST_TIMEOUT'] : 60);
 
@@ -1102,7 +1110,13 @@ function system_with_timeout($commandline, $env = null, $stdin = null)
                        proc_terminate($proc, 9);
                        return $data;
                } else if ($n > 0) {
-                       $line = fread($pipes[1], 8192);
+                       if ($captureStdOut) {
+                               $line = fread($pipes[1], 8192);
+                       } elseif ($captureStdErr) {
+                               $line = fread($pipes[2], 8192);
+                       } else {
+                               $line = '';
+                       }
                        if (strlen($line) == 0) {
                                /* EOF */
                                break;
@@ -1332,6 +1346,21 @@ TEST $file
                return 'BORKED';
        }
 
+       if (isset($section_text['CAPTURE_STDIO'])) {
+               $captureStdIn = stripos($section_text['CAPTURE_STDIO'], 'STDIN') !== false;
+               $captureStdOut = stripos($section_text['CAPTURE_STDIO'], 'STDOUT') !== false;
+               $captureStdErr = stripos($section_text['CAPTURE_STDIO'], 'STDERR') !== false;
+       } else {
+               $captureStdIn = true;
+               $captureStdOut = true;
+               $captureStdErr = true;
+       }
+       if ($captureStdOut && $captureStdErr) {
+               $cmdRedirect = ' 2>&1';
+       } else {
+               $cmdRedirect = '';
+       }
+
        $tested = trim($section_text['TEST']);
 
        /* For GET/POST/PUT tests, check if cgi sapi is available and if it is, use it. */
@@ -1740,7 +1769,7 @@ TEST $file
                }
 
                save_text($tmp_post, $request);
-               $cmd = "$php $pass_options $ini_settings -f \"$test_file\" 2>&1 < \"$tmp_post\"";
+               $cmd = "$php $pass_options $ini_settings -f \"$test_file\"$cmdRedirect < \"$tmp_post\"";
 
        } elseif (array_key_exists('PUT', $section_text) && !empty($section_text['PUT'])) {
 
@@ -1774,7 +1803,7 @@ TEST $file
                }
 
                save_text($tmp_post, $request);
-               $cmd = "$php $pass_options $ini_settings -f \"$test_file\" 2>&1 < \"$tmp_post\"";
+               $cmd = "$php $pass_options $ini_settings -f \"$test_file\"$cmdRedirect < \"$tmp_post\"";
 
        } else if (array_key_exists('POST', $section_text) && !empty($section_text['POST'])) {
 
@@ -1791,7 +1820,7 @@ TEST $file
                        $env['CONTENT_LENGTH'] = $content_length;
                }
 
-               $cmd = "$php $pass_options $ini_settings -f \"$test_file\" 2>&1 < \"$tmp_post\"";
+               $cmd = "$php $pass_options $ini_settings -f \"$test_file\"$cmdRedirect < \"$tmp_post\"";
 
        } else if (array_key_exists('GZIP_POST', $section_text) && !empty($section_text['GZIP_POST'])) {
 
@@ -1806,7 +1835,7 @@ TEST $file
                $env['CONTENT_TYPE']   = 'application/x-www-form-urlencoded';
                $env['CONTENT_LENGTH'] = $content_length;
 
-               $cmd = "$php $pass_options $ini_settings -f \"$test_file\" 2>&1 < \"$tmp_post\"";
+               $cmd = "$php $pass_options $ini_settings -f \"$test_file\"$cmdRedirect < \"$tmp_post\"";
 
        } else if (array_key_exists('DEFLATE_POST', $section_text) && !empty($section_text['DEFLATE_POST'])) {
                $post = trim($section_text['DEFLATE_POST']);
@@ -1819,7 +1848,7 @@ TEST $file
                $env['CONTENT_TYPE']   = 'application/x-www-form-urlencoded';
                $env['CONTENT_LENGTH'] = $content_length;
 
-               $cmd = "$php $pass_options $ini_settings -f \"$test_file\" 2>&1 < \"$tmp_post\"";
+               $cmd = "$php $pass_options $ini_settings -f \"$test_file\"$cmdRedirect < \"$tmp_post\"";
 
        } else {
 
@@ -1827,7 +1856,7 @@ TEST $file
                $env['CONTENT_TYPE']   = '';
                $env['CONTENT_LENGTH'] = '';
 
-               $cmd = "$php $pass_options $ini_settings -f \"$test_file\" $args 2>&1";
+               $cmd = "$php $pass_options $ini_settings -f \"$test_file\" $args$cmdRedirect";
        }
 
        if ($leak_check) {
@@ -1863,7 +1892,7 @@ COMMAND $cmd
 
        junit_start_timer($shortname);
 
-       $out = system_with_timeout($cmd, $env, isset($section_text['STDIN']) ? $section_text['STDIN'] : null);
+       $out = system_with_timeout($cmd, $env, isset($section_text['STDIN']) ? $section_text['STDIN'] : null, $captureStdIn, $captureStdOut, $captureStdErr);
 
        junit_finish_timer($shortname);
 
index dc92045ae7402ad16566a9024453820a26c69da8..56ab3fec6db4d2607f7f362822698014db092b8c 100644 (file)
@@ -38,6 +38,7 @@
 #ifdef PHP_WIN32
 #include "win32/time.h"
 #include "win32/signal.h"
+#include "win32/console.h"
 #include <process.h>
 #include <shellapi.h>
 #endif
@@ -243,6 +244,9 @@ static void print_extensions(void) /* {{{ */
 #ifndef STDOUT_FILENO
 #define STDOUT_FILENO 1
 #endif
+#ifndef STDERR_FILENO
+#define STDERR_FILENO 2
+#endif
 
 static inline int sapi_cli_select(int fd)
 {
@@ -1208,6 +1212,11 @@ int main(int argc, char *argv[])
         */
        argv = save_ps_args(argc, argv);
 
+#if defined(PHP_WIN32) && !defined(PHP_CLI_WIN32_NO_CONSOLE)
+       php_win32_console_fileno_set_vt100(STDOUT_FILENO, TRUE);
+       php_win32_console_fileno_set_vt100(STDERR_FILENO, TRUE);
+#endif
+
        cli_sapi_module.additional_functions = additional_functions;
 
 #if defined(PHP_WIN32) && defined(_DEBUG) && defined(PHP_WIN32_DEBUG_HEAP)
diff --git a/tests/output/sapi_windows_vt100_support.inc b/tests/output/sapi_windows_vt100_support.inc
new file mode 100644 (file)
index 0000000..9ac54ce
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+
+function resetVT100State()
+{
+    $state = array(
+        sapi_windows_vt100_support(STDIN),
+        sapi_windows_vt100_support(STDOUT),
+        sapi_windows_vt100_support(STDERR),
+    );
+    sapi_windows_vt100_support(STDIN, false);
+    sapi_windows_vt100_support(STDOUT, false);
+    sapi_windows_vt100_support(STDERR, false);
+
+    return $state;
+}
+
+function restoreVT100State(array $state)
+{
+    sapi_windows_vt100_support(STDIN, $state[0]);
+    sapi_windows_vt100_support(STDOUT, $state[1]);
+    sapi_windows_vt100_support(STDERR, $state[2]);
+}
+
+function testToStdOut()
+{
+    $state = resetVT100State();
+
+    $sampleStreams = array(
+        'STDIN (constant)'              => STDIN,
+        'STDIN (fopen)'                 => fopen('php://stdin', 'rb'),
+        'STDIN (php://fd/0)'            => fopen('php://fd/0', 'rb'),
+        'STDOUT (constant)'             => STDOUT,
+        'STDOUT (fopen)'                => fopen('php://stdout', 'wb'),
+        'STDOUT (php://fd/1)'           => fopen('php://fd/1', 'wb'),
+        'STDERR (constant)'             => STDERR,
+        'STDERR (fopen)'                => fopen('php://stderr', 'wb'),
+        'STDERR (php://fd/2)'           => fopen('php://fd/2', 'wb'),
+        'Not a stream'                  => 'foo',
+        'Invalid stream (php://temp)'   => fopen('php://temp', 'wb'),
+        'Invalid stream (php://input)'  => fopen('php://input', 'wb'),
+        'Invalid stream (php://memory)' => fopen('php://memory', 'wb'),
+        'File stream'                   => $closeMe = fopen(__FILE__, 'rb'),
+    );
+
+    foreach ($sampleStreams as $name => $stream) {
+        echo "$name:\n";
+        echo "- current value  : "; var_dump(sapi_windows_vt100_support($stream));
+        echo "- enabling VT100 : "; var_dump(sapi_windows_vt100_support($stream, true));
+        echo "- current value  : "; var_dump(sapi_windows_vt100_support($stream));
+        echo "- disabling VT100: "; var_dump(sapi_windows_vt100_support($stream, false));
+        echo "- current value  : "; var_dump(sapi_windows_vt100_support($stream));
+    }
+
+    fclose($closeMe);
+    restoreVT100State($state);
+}
+
+function testToStdErr()
+{
+    ob_start();
+    testToStdOut();
+    $result = ob_get_contents();
+    ob_end_clean();
+    fwrite(STDERR, $result);
+}
diff --git a/tests/output/sapi_windows_vt100_support_notwindows.phpt b/tests/output/sapi_windows_vt100_support_notwindows.phpt
new file mode 100644 (file)
index 0000000..5ff3823
--- /dev/null
@@ -0,0 +1,14 @@
+--TEST--
+Test that sapi_windows_vt100_support exists only on Windows
+--SKIPIF--
+<?php
+if (stripos(PHP_OS, 'WIN') === 0) {
+    echo "skip Only for not Windows systems";
+}
+?>
+--FILE--
+<?php
+var_dump(function_exists('sapi_windows_vt100_support'));
+?>
+--EXPECT--
+bool(false)
diff --git a/tests/output/sapi_windows_vt100_support_winko_err.phpt b/tests/output/sapi_windows_vt100_support_winko_err.phpt
new file mode 100644 (file)
index 0000000..c722e54
--- /dev/null
@@ -0,0 +1,145 @@
+--TEST--
+Test sapi_windows_vt100_support on older Windows versions with redirected STDERR
+--SKIPIF--
+<?php
+if (stripos(PHP_OS, 'WIN') !== 0) {
+    echo "skip Only for Windows systems";
+} elseif (version_compare(
+    PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD,
+        '10.0.10586'
+) >= 0) {
+       echo "skip Only for Windows systems < 10.0.10586";
+}
+?>
+--CAPTURE_STDIO--
+STDERR
+--FILE--
+<?php
+require dirname(__FILE__).'/sapi_windows_vt100_support.inc';
+testToStdErr();
+?>
+--EXPECTF--
+STDIN (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDIN (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDIN (php://fd/0):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDOUT (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(true)
+- current value  : bool(false)
+STDOUT (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(true)
+- current value  : bool(false)
+STDOUT (php://fd/1):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(true)
+- current value  : bool(false)
+STDERR (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDERR (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDERR (php://fd/2):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+Not a stream:
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+Invalid stream (php://temp):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+Invalid stream (php://input):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+Invalid stream (php://memory):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+File stream:
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
diff --git a/tests/output/sapi_windows_vt100_support_winko_in-err.phpt b/tests/output/sapi_windows_vt100_support_winko_in-err.phpt
new file mode 100644 (file)
index 0000000..0e8097e
--- /dev/null
@@ -0,0 +1,145 @@
+--TEST--
+Test sapi_windows_vt100_support on older Windows versions with redirected STDIN/STDERR
+--SKIPIF--
+<?php
+if (stripos(PHP_OS, 'WIN') !== 0) {
+    echo "skip Only for Windows systems";
+} elseif (version_compare(
+    PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD,
+        '10.0.10586'
+) >= 0) {
+       echo "skip Only for Windows systems < 10.0.10586";
+}
+?>
+--CAPTURE_STDIO--
+STDIN STDERR
+--FILE--
+<?php
+require dirname(__FILE__).'/sapi_windows_vt100_support.inc';
+testToStdErr();
+?>
+--EXPECTF--
+STDIN (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDIN (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDIN (php://fd/0):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDOUT (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(true)
+- current value  : bool(false)
+STDOUT (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(true)
+- current value  : bool(false)
+STDOUT (php://fd/1):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(true)
+- current value  : bool(false)
+STDERR (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDERR (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDERR (php://fd/2):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+Not a stream:
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+Invalid stream (php://temp):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+Invalid stream (php://input):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+Invalid stream (php://memory):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+File stream:
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
diff --git a/tests/output/sapi_windows_vt100_support_winko_in-out-err.phpt b/tests/output/sapi_windows_vt100_support_winko_in-out-err.phpt
new file mode 100644 (file)
index 0000000..496f467
--- /dev/null
@@ -0,0 +1,145 @@
+--TEST--
+Test sapi_windows_vt100_support on older Windows versions with redirected STDIN/STDOUT/STDERR
+--SKIPIF--
+<?php
+if (stripos(PHP_OS, 'WIN') !== 0) {
+    echo "skip Only for Windows systems";
+} elseif (version_compare(
+    PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD,
+        '10.0.10586'
+) >= 0) {
+       echo "skip Only for Windows systems < 10.0.10586";
+}
+?>
+--CAPTURE_STDIO--
+STDIN STDOUT STDERR
+--FILE--
+<?php
+require dirname(__FILE__).'/sapi_windows_vt100_support.inc';
+testToStdErr();
+?>
+--EXPECTF--
+STDIN (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDIN (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDIN (php://fd/0):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDOUT (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDOUT (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDOUT (php://fd/1):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDERR (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDERR (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDERR (php://fd/2):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+Not a stream:
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+Invalid stream (php://temp):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+Invalid stream (php://input):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+Invalid stream (php://memory):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+File stream:
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
diff --git a/tests/output/sapi_windows_vt100_support_winko_in-out.phpt b/tests/output/sapi_windows_vt100_support_winko_in-out.phpt
new file mode 100644 (file)
index 0000000..da9a237
--- /dev/null
@@ -0,0 +1,145 @@
+--TEST--
+Test sapi_windows_vt100_support on older Windows versions with redirected STDIN/STDOUT
+--SKIPIF--
+<?php
+if (stripos(PHP_OS, 'WIN') !== 0) {
+    echo "skip Only for Windows systems";
+} elseif (version_compare(
+    PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD,
+        '10.0.10586'
+) >= 0) {
+       echo "skip Only for Windows systems < 10.0.10586";
+}
+?>
+--CAPTURE_STDIO--
+STDIN STDOUT
+--FILE--
+<?php
+require dirname(__FILE__).'/sapi_windows_vt100_support.inc';
+testToStdOut();
+?>
+--EXPECTF--
+STDIN (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDIN (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDIN (php://fd/0):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDOUT (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDOUT (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDOUT (php://fd/1):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDERR (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(true)
+- current value  : bool(false)
+STDERR (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(true)
+- current value  : bool(false)
+STDERR (php://fd/2):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(true)
+- current value  : bool(false)
+Not a stream:
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+Invalid stream (php://temp):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+Invalid stream (php://input):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+Invalid stream (php://memory):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+File stream:
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
diff --git a/tests/output/sapi_windows_vt100_support_winko_out-err.phpt b/tests/output/sapi_windows_vt100_support_winko_out-err.phpt
new file mode 100644 (file)
index 0000000..94604ba
--- /dev/null
@@ -0,0 +1,145 @@
+--TEST--
+Test sapi_windows_vt100_support on older Windows versions with redirected STDOUT/STDERR
+--SKIPIF--
+<?php
+if (stripos(PHP_OS, 'WIN') !== 0) {
+    echo "skip Only for Windows systems";
+} elseif (version_compare(
+    PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD,
+        '10.0.10586'
+) >= 0) {
+       echo "skip Only for Windows systems < 10.0.10586";
+}
+?>
+--CAPTURE_STDIO--
+STDOUT STDERR
+--FILE--
+<?php
+require dirname(__FILE__).'/sapi_windows_vt100_support.inc';
+testToStdErr();
+?>
+--EXPECTF--
+STDIN (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDIN (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDIN (php://fd/0):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDOUT (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDOUT (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDOUT (php://fd/1):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDERR (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDERR (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDERR (php://fd/2):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+Not a stream:
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+Invalid stream (php://temp):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+Invalid stream (php://input):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+Invalid stream (php://memory):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+File stream:
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
diff --git a/tests/output/sapi_windows_vt100_support_winko_out.phpt b/tests/output/sapi_windows_vt100_support_winko_out.phpt
new file mode 100644 (file)
index 0000000..563a328
--- /dev/null
@@ -0,0 +1,145 @@
+--TEST--
+Test sapi_windows_vt100_support on older Windows versions with redirected STDOUT
+--SKIPIF--
+<?php
+if (stripos(PHP_OS, 'WIN') !== 0) {
+    echo "skip Only for Windows systems";
+} elseif (version_compare(
+    PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD,
+        '10.0.10586'
+) >= 0) {
+       echo "skip Only for Windows systems < 10.0.10586";
+}
+?>
+--CAPTURE_STDIO--
+STDOUT
+--FILE--
+<?php
+require dirname(__FILE__).'/sapi_windows_vt100_support.inc';
+testToStdOut();
+?>
+--EXPECTF--
+STDIN (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDIN (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDIN (php://fd/0):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDOUT (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDOUT (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDOUT (php://fd/1):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDERR (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(true)
+- current value  : bool(false)
+STDERR (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(true)
+- current value  : bool(false)
+STDERR (php://fd/2):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(true)
+- current value  : bool(false)
+Not a stream:
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+Invalid stream (php://temp):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+Invalid stream (php://input):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+Invalid stream (php://memory):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+File stream:
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
diff --git a/tests/output/sapi_windows_vt100_support_winok_err.phpt b/tests/output/sapi_windows_vt100_support_winok_err.phpt
new file mode 100644 (file)
index 0000000..58b3f6b
--- /dev/null
@@ -0,0 +1,145 @@
+--TEST--
+Test sapi_windows_vt100_support on newer Windows versions with redirected STDERR
+--SKIPIF--
+<?php
+if (stripos(PHP_OS, 'WIN') !== 0) {
+    echo "skip Only for Windows systems";
+} elseif (version_compare(
+    PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD,
+        '10.0.10586'
+) < 0) {
+       echo "skip Only for Windows systems >= 10.0.10586";
+}
+?>
+--CAPTURE_STDIO--
+STDERR
+--FILE--
+<?php
+require dirname(__FILE__).'/sapi_windows_vt100_support.inc';
+testToStdErr();
+?>
+--EXPECTF--
+STDIN (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDIN (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDIN (php://fd/0):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDOUT (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(true)
+- current value  : bool(true)
+- disabling VT100: bool(true)
+- current value  : bool(false)
+STDOUT (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(true)
+- current value  : bool(true)
+- disabling VT100: bool(true)
+- current value  : bool(false)
+STDOUT (php://fd/1):
+- current value  : bool(false)
+- enabling VT100 : bool(true)
+- current value  : bool(true)
+- disabling VT100: bool(true)
+- current value  : bool(false)
+STDERR (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDERR (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDERR (php://fd/2):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+Not a stream:
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+Invalid stream (php://temp):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+Invalid stream (php://input):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+Invalid stream (php://memory):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+File stream:
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
diff --git a/tests/output/sapi_windows_vt100_support_winok_in-err.phpt b/tests/output/sapi_windows_vt100_support_winok_in-err.phpt
new file mode 100644 (file)
index 0000000..4eda2c4
--- /dev/null
@@ -0,0 +1,145 @@
+--TEST--
+Test sapi_windows_vt100_support on newer Windows versions with redirected STDIN/STDERR
+--SKIPIF--
+<?php
+if (stripos(PHP_OS, 'WIN') !== 0) {
+    echo "skip Only for Windows systems";
+} elseif (version_compare(
+    PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD,
+        '10.0.10586'
+) < 0) {
+       echo "skip Only for Windows systems >= 10.0.10586";
+}
+?>
+--CAPTURE_STDIO--
+STDIN STDERR
+--FILE--
+<?php
+require dirname(__FILE__).'/sapi_windows_vt100_support.inc';
+testToStdErr();
+?>
+--EXPECTF--
+STDIN (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDIN (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDIN (php://fd/0):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDOUT (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(true)
+- current value  : bool(true)
+- disabling VT100: bool(true)
+- current value  : bool(false)
+STDOUT (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(true)
+- current value  : bool(true)
+- disabling VT100: bool(true)
+- current value  : bool(false)
+STDOUT (php://fd/1):
+- current value  : bool(false)
+- enabling VT100 : bool(true)
+- current value  : bool(true)
+- disabling VT100: bool(true)
+- current value  : bool(false)
+STDERR (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDERR (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDERR (php://fd/2):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+Not a stream:
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+Invalid stream (php://temp):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+Invalid stream (php://input):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+Invalid stream (php://memory):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+File stream:
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
diff --git a/tests/output/sapi_windows_vt100_support_winok_in-out-err.phpt b/tests/output/sapi_windows_vt100_support_winok_in-out-err.phpt
new file mode 100644 (file)
index 0000000..62ed43c
--- /dev/null
@@ -0,0 +1,145 @@
+--TEST--
+Test sapi_windows_vt100_support on newer Windows versions with redirected STDIN/STDOUT/STDERR
+--SKIPIF--
+<?php
+if (stripos(PHP_OS, 'WIN') !== 0) {
+    echo "skip Only for Windows systems";
+} elseif (version_compare(
+    PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD,
+        '10.0.10586'
+) < 0) {
+       echo "skip Only for Windows systems >= 10.0.10586";
+}
+?>
+--CAPTURE_STDIO--
+STDIN STDOUT STDERR
+--FILE--
+<?php
+require dirname(__FILE__).'/sapi_windows_vt100_support.inc';
+testToStdOut();
+?>
+--EXPECTF--
+STDIN (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDIN (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDIN (php://fd/0):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDOUT (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDOUT (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDOUT (php://fd/1):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDERR (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDERR (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDERR (php://fd/2):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+Not a stream:
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+Invalid stream (php://temp):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+Invalid stream (php://input):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+Invalid stream (php://memory):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+File stream:
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
diff --git a/tests/output/sapi_windows_vt100_support_winok_in-out.phpt b/tests/output/sapi_windows_vt100_support_winok_in-out.phpt
new file mode 100644 (file)
index 0000000..d146c5d
--- /dev/null
@@ -0,0 +1,145 @@
+--TEST--
+Test sapi_windows_vt100_support on newer Windows versions with redirected STDIN/STDOUT
+--SKIPIF--
+<?php
+if (stripos(PHP_OS, 'WIN') !== 0) {
+    echo "skip Only for Windows systems";
+} elseif (version_compare(
+    PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD,
+        '10.0.10586'
+) < 0) {
+       echo "skip Only for Windows systems >= 10.0.10586";
+}
+?>
+--CAPTURE_STDIO--
+STDIN STDOUT
+--FILE--
+<?php
+require dirname(__FILE__).'/sapi_windows_vt100_support.inc';
+testToStdOut();
+?>
+--EXPECTF--
+STDIN (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDIN (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDIN (php://fd/0):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDOUT (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDOUT (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDOUT (php://fd/1):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDERR (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(true)
+- current value  : bool(true)
+- disabling VT100: bool(true)
+- current value  : bool(false)
+STDERR (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(true)
+- current value  : bool(true)
+- disabling VT100: bool(true)
+- current value  : bool(false)
+STDERR (php://fd/2):
+- current value  : bool(false)
+- enabling VT100 : bool(true)
+- current value  : bool(true)
+- disabling VT100: bool(true)
+- current value  : bool(false)
+Not a stream:
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+Invalid stream (php://temp):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+Invalid stream (php://input):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+Invalid stream (php://memory):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+File stream:
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
diff --git a/tests/output/sapi_windows_vt100_support_winok_out-err.phpt b/tests/output/sapi_windows_vt100_support_winok_out-err.phpt
new file mode 100644 (file)
index 0000000..223b0dd
--- /dev/null
@@ -0,0 +1,145 @@
+--TEST--
+Test sapi_windows_vt100_support on newer Windows versions with redirected STDOUT/STDERR
+--SKIPIF--
+<?php
+if (stripos(PHP_OS, 'WIN') !== 0) {
+    echo "skip Only for Windows systems";
+} elseif (version_compare(
+    PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD,
+        '10.0.10586'
+) < 0) {
+       echo "skip Only for Windows systems >= 10.0.10586";
+}
+?>
+--CAPTURE_STDIO--
+STDOUT STDERR
+--FILE--
+<?php
+require dirname(__FILE__).'/sapi_windows_vt100_support.inc';
+testToStdOut();
+?>
+--EXPECTF--
+STDIN (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDIN (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDIN (php://fd/0):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDOUT (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDOUT (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDOUT (php://fd/1):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDERR (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDERR (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDERR (php://fd/2):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+Not a stream:
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+Invalid stream (php://temp):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+Invalid stream (php://input):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+Invalid stream (php://memory):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+File stream:
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
diff --git a/tests/output/sapi_windows_vt100_support_winok_out.phpt b/tests/output/sapi_windows_vt100_support_winok_out.phpt
new file mode 100644 (file)
index 0000000..69cb508
--- /dev/null
@@ -0,0 +1,145 @@
+--TEST--
+Test sapi_windows_vt100_support on newer Windows versions with redirected STDOUT
+--SKIPIF--
+<?php
+if (stripos(PHP_OS, 'WIN') !== 0) {
+    echo "skip Only for Windows systems";
+} elseif (version_compare(
+    PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD,
+        '10.0.10586'
+) < 0) {
+       echo "skip Only for Windows systems >= 10.0.10586";
+}
+?>
+--CAPTURE_STDIO--
+STDOUT
+--FILE--
+<?php
+require dirname(__FILE__).'/sapi_windows_vt100_support.inc';
+testToStdOut();
+?>
+--EXPECTF--
+STDIN (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDIN (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDIN (php://fd/0):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDOUT (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDOUT (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDOUT (php://fd/1):
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
+STDERR (constant):
+- current value  : bool(false)
+- enabling VT100 : bool(true)
+- current value  : bool(true)
+- disabling VT100: bool(true)
+- current value  : bool(false)
+STDERR (fopen):
+- current value  : bool(false)
+- enabling VT100 : bool(true)
+- current value  : bool(true)
+- disabling VT100: bool(true)
+- current value  : bool(false)
+STDERR (php://fd/2):
+- current value  : bool(false)
+- enabling VT100 : bool(true)
+- current value  : bool(true)
+- disabling VT100: bool(true)
+- current value  : bool(false)
+Not a stream:
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+Invalid stream (php://temp):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+Invalid stream (php://input):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+Invalid stream (php://memory):
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- enabling VT100 : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- disabling VT100: 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+- current value  : 
+Warning: sapi_windows_vt100_support() was not able to analyze the specified stream in %s on line %d
+bool(false)
+File stream:
+- current value  : bool(false)
+- enabling VT100 : bool(false)
+- current value  : bool(false)
+- disabling VT100: bool(false)
+- current value  : bool(false)
diff --git a/tests/output/stream_isatty.inc b/tests/output/stream_isatty.inc
new file mode 100644 (file)
index 0000000..4b7f399
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+
+function testToStdOut()
+{
+    $sampleStreams = array(
+        'STDIN (constant)'              => STDIN,
+        'STDIN (fopen)'                 => fopen('php://stdin', 'rb'),
+        'STDIN (php://fd/0)'            => fopen('php://fd/0', 'rb'),
+        'STDOUT (constant)'             => STDOUT,
+        'STDOUT (fopen)'                => fopen('php://stdout', 'wb'),
+        'STDOUT (php://fd/1)'           => fopen('php://fd/1', 'wb'),
+        'STDERR (constant)'             => STDERR,
+        'STDERR (fopen)'                => fopen('php://stderr', 'wb'),
+        'STDERR (php://fd/2)'           => fopen('php://fd/2', 'wb'),
+        'Not a stream'                  => 'foo',
+        'Invalid stream (php://temp)'   => fopen('php://temp', 'wb'),
+        'Invalid stream (php://input)'  => fopen('php://input', 'wb'),
+        'Invalid stream (php://memory)' => fopen('php://memory', 'wb'),
+        'File stream'                   => $closeMe = fopen(__FILE__, 'rb'),
+    );
+
+    foreach ($sampleStreams as $name => $stream) {
+        echo "$name: "; var_dump(stream_isatty($stream));
+    }
+
+    fclose($closeMe);
+}
+
+function testToStdErr()
+{
+    ob_start();
+    testToStdOut();
+    $result = ob_get_contents();
+    ob_end_clean();
+    fwrite(STDERR, $result);
+}
diff --git a/tests/output/stream_isatty_err.phpt b/tests/output/stream_isatty_err.phpt
new file mode 100644 (file)
index 0000000..65a4564
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+Test stream_isatty with redirected STDERR
+--CAPTURE_STDIO--
+STDERR
+--FILE--
+<?php
+require dirname(__FILE__).'/stream_isatty.inc';
+testToStdErr();
+?>
+--EXPECTF--
+STDIN (constant): bool(true)
+STDIN (fopen): bool(true)
+STDIN (php://fd/0): bool(true)
+STDOUT (constant): bool(true)
+STDOUT (fopen): bool(true)
+STDOUT (php://fd/1): bool(true)
+STDERR (constant): bool(false)
+STDERR (fopen): bool(false)
+STDERR (php://fd/2): bool(false)
+Not a stream: 
+Warning: stream_isatty() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+Invalid stream (php://temp): bool(false)
+Invalid stream (php://input): bool(false)
+Invalid stream (php://memory): bool(false)
+File stream: bool(false)
diff --git a/tests/output/stream_isatty_in-err.phpt b/tests/output/stream_isatty_in-err.phpt
new file mode 100644 (file)
index 0000000..b93ea03
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+Test stream_isatty with redirected STDIN/STDERR
+--CAPTURE_STDIO--
+STDIN STDERR
+--FILE--
+<?php
+require dirname(__FILE__).'/stream_isatty.inc';
+testToStdErr();
+?>
+--EXPECTF--
+STDIN (constant): bool(false)
+STDIN (fopen): bool(false)
+STDIN (php://fd/0): bool(false)
+STDOUT (constant): bool(true)
+STDOUT (fopen): bool(true)
+STDOUT (php://fd/1): bool(true)
+STDERR (constant): bool(false)
+STDERR (fopen): bool(false)
+STDERR (php://fd/2): bool(false)
+Not a stream: 
+Warning: stream_isatty() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+Invalid stream (php://temp): bool(false)
+Invalid stream (php://input): bool(false)
+Invalid stream (php://memory): bool(false)
+File stream: bool(false)
diff --git a/tests/output/stream_isatty_in-out-err.phpt b/tests/output/stream_isatty_in-out-err.phpt
new file mode 100644 (file)
index 0000000..733d024
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+Test stream_isatty with redirected STDIN/STDOUT/STDERR
+--CAPTURE_STDIO--
+STDIN STDOUT STDERR
+--FILE--
+<?php
+require dirname(__FILE__).'/stream_isatty.inc';
+testToStdOut();
+?>
+--EXPECTF--
+STDIN (constant): bool(false)
+STDIN (fopen): bool(false)
+STDIN (php://fd/0): bool(false)
+STDOUT (constant): bool(false)
+STDOUT (fopen): bool(false)
+STDOUT (php://fd/1): bool(false)
+STDERR (constant): bool(false)
+STDERR (fopen): bool(false)
+STDERR (php://fd/2): bool(false)
+Not a stream: 
+Warning: stream_isatty() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+Invalid stream (php://temp): bool(false)
+Invalid stream (php://input): bool(false)
+Invalid stream (php://memory): bool(false)
+File stream: bool(false)
diff --git a/tests/output/stream_isatty_in-out.phpt b/tests/output/stream_isatty_in-out.phpt
new file mode 100644 (file)
index 0000000..755ee82
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+Test stream_isatty with redirected STDIN/STDOUT
+--CAPTURE_STDIO--
+STDIN STDOUT
+--FILE--
+<?php
+require dirname(__FILE__).'/stream_isatty.inc';
+testToStdOut();
+?>
+--EXPECTF--
+STDIN (constant): bool(false)
+STDIN (fopen): bool(false)
+STDIN (php://fd/0): bool(false)
+STDOUT (constant): bool(false)
+STDOUT (fopen): bool(false)
+STDOUT (php://fd/1): bool(false)
+STDERR (constant): bool(true)
+STDERR (fopen): bool(true)
+STDERR (php://fd/2): bool(true)
+Not a stream: 
+Warning: stream_isatty() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+Invalid stream (php://temp): bool(false)
+Invalid stream (php://input): bool(false)
+Invalid stream (php://memory): bool(false)
+File stream: bool(false)
diff --git a/tests/output/stream_isatty_out-err.phpt b/tests/output/stream_isatty_out-err.phpt
new file mode 100644 (file)
index 0000000..97d8046
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+Test stream_isatty with redirected STDOUT/STDERR
+--CAPTURE_STDIO--
+STDOUT STDERR
+--FILE--
+<?php
+require dirname(__FILE__).'/stream_isatty.inc';
+testToStdOut();
+?>
+--EXPECTF--
+STDIN (constant): bool(true)
+STDIN (fopen): bool(true)
+STDIN (php://fd/0): bool(true)
+STDOUT (constant): bool(false)
+STDOUT (fopen): bool(false)
+STDOUT (php://fd/1): bool(false)
+STDERR (constant): bool(false)
+STDERR (fopen): bool(false)
+STDERR (php://fd/2): bool(false)
+Not a stream: 
+Warning: stream_isatty() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+Invalid stream (php://temp): bool(false)
+Invalid stream (php://input): bool(false)
+Invalid stream (php://memory): bool(false)
+File stream: bool(false)
diff --git a/tests/output/stream_isatty_out.phpt b/tests/output/stream_isatty_out.phpt
new file mode 100644 (file)
index 0000000..ed592f1
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+Test stream_isatty with redirected STDOUT
+--CAPTURE_STDIO--
+STDOUT
+--FILE--
+<?php
+require dirname(__FILE__).'/stream_isatty.inc';
+testToStdOut();
+?>
+--EXPECTF--
+STDIN (constant): bool(true)
+STDIN (fopen): bool(true)
+STDIN (php://fd/0): bool(true)
+STDOUT (constant): bool(false)
+STDOUT (fopen): bool(false)
+STDOUT (php://fd/1): bool(false)
+STDERR (constant): bool(true)
+STDERR (fopen): bool(true)
+STDERR (php://fd/2): bool(true)
+Not a stream: 
+Warning: stream_isatty() expects parameter 1 to be resource, string given in %s on line %d
+bool(false)
+Invalid stream (php://temp): bool(false)
+Invalid stream (php://input): bool(false)
+Invalid stream (php://memory): bool(false)
+File stream: bool(false)
index 682f1bd27418c1c8bcfbfa760a4f61e304f5a711..c727cf80819ac0e558dd2dcc4bd997d8c0e625dd 100644 (file)
@@ -165,7 +165,7 @@ ADD_FLAG("CFLAGS_BD_MAIN_STREAMS", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
 ADD_SOURCES("win32", "dllmain.c glob.c readdir.c \
        registry.c select.c sendmail.c time.c winutil.c wsyslog.c globals.c \
        getrusage.c ftok.c ioutil.c codepage.c nice.c \
-       inet.c fnmatch.c sockets.c");
+       inet.c fnmatch.c sockets.c console.c");
 
 ADD_FLAG("CFLAGS_BD_WIN32", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
 
@@ -302,4 +302,4 @@ ARG_WITH("all-shared", "Force all the non obligatory extensions to be shared", "
 // so that it can be executed like: cofig.<name> instead of a long list of parameters
 //
 // Note, nice as a name is disallowed and will generate a warning and skip saving
-ARG_WITH('config-profile', 'Name of the configuration profile to save this to in php-src/config.name.bat', 'no');
\ No newline at end of file
+ARG_WITH('config-profile', 'Name of the configuration profile to save this to in php-src/config.name.bat', 'no');
diff --git a/win32/console.c b/win32/console.c
new file mode 100644 (file)
index 0000000..a133e0e
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+   +----------------------------------------------------------------------+
+   | PHP Version 7                                                        |
+   +----------------------------------------------------------------------+
+   | Copyright (c) 1997-2016 The PHP Group                                |
+   +----------------------------------------------------------------------+
+   | This source file is subject to version 3.01 of the PHP license,      |
+   | that is bundled with this package in the file LICENSE, and is        |
+   | available through the world-wide-web at the following url:           |
+   | http://www.php.net/license/3_01.txt                                  |
+   | If you did not receive a copy of the PHP license and are unable to   |
+   | obtain it through the world-wide-web, please send a note to          |
+   | license@php.net so we can mail you a copy immediately.               |
+   +----------------------------------------------------------------------+
+   | Author: Michele Locati <mlocati@gmail.com>                           |
+   +----------------------------------------------------------------------+
+ */
+
+/* $Id$ */
+
+#include "win32/console.h"
+
+
+PHP_WINUTIL_API BOOL php_win32_console_fileno_is_console(zend_long fileno)
+{
+       BOOL result = FALSE;
+       HANDLE handle = (HANDLE) _get_osfhandle(fileno);
+
+       if (handle != INVALID_HANDLE_VALUE) {
+        DWORD mode;
+        if (GetConsoleMode(handle, &mode)) {
+            result = TRUE;
+               }
+       }
+       return result;
+}
+
+PHP_WINUTIL_API BOOL php_win32_console_fileno_has_vt100(zend_long fileno)
+{
+       BOOL result = FALSE;
+       HANDLE handle = (HANDLE) _get_osfhandle(fileno);
+
+       if (handle != INVALID_HANDLE_VALUE) {
+               DWORD events;
+
+               if (fileno != 0 && !GetNumberOfConsoleInputEvents(handle, &events)) {
+                       // Not STDIN
+                       DWORD mode;
+
+                       if (GetConsoleMode(handle, &mode)) {
+                               if (mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING) {
+                                       result = TRUE;
+                               }
+                       }
+               }
+       }
+       return result;
+}
+
+PHP_WINUTIL_API BOOL php_win32_console_fileno_set_vt100(zend_long fileno, BOOL enable)
+{
+       BOOL result = FALSE;
+       HANDLE handle = (HANDLE) _get_osfhandle(fileno);
+
+       if (handle != INVALID_HANDLE_VALUE) {
+               DWORD events;
+
+               if (fileno != 0 && !GetNumberOfConsoleInputEvents(handle, &events)) {
+                       // Not STDIN
+                       DWORD mode;
+
+                       if (GetConsoleMode(handle, &mode)) {
+                               DWORD newMode;
+
+                               if (enable) {
+                                       newMode = mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING;
+                               }
+                               else {
+                                       newMode = mode & ~ENABLE_VIRTUAL_TERMINAL_PROCESSING;
+                               }
+                               if (newMode == mode) {
+                                       result = TRUE;
+                               }
+                               else {
+                                       if (SetConsoleMode(handle, newMode)) {
+                                               result = TRUE;
+                                       }
+                               }
+                       }
+               }
+       }
+       return result;
+}
diff --git a/win32/console.h b/win32/console.h
new file mode 100644 (file)
index 0000000..e32bf04
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+  +----------------------------------------------------------------------+
+  | PHP Version 7                                                        |
+  +----------------------------------------------------------------------+
+  | Copyright (c) 1997-2016 The PHP Group                                |
+  +----------------------------------------------------------------------+
+  | This source file is subject to version 3.01 of the PHP license,      |
+  | that is bundled with this package in the file LICENSE, and is        |
+  | available through the world-wide-web at the following url:           |
+  | http://www.php.net/license/3_01.txt                                  |
+  | If you did not receive a copy of the PHP license and are unable to   |
+  | obtain it through the world-wide-web, please send a note to          |
+  | license@php.net so we can mail you a copy immediately.               |
+  +----------------------------------------------------------------------+
+  | Author: Michele Locati <mlocati@gmail.com>                           |
+  +----------------------------------------------------------------------+
+*/
+
+/* $Id$ */
+
+#ifndef PHP_WIN32_CONSOLE_H
+#define PHP_WIN32_CONSOLE_H
+
+#ifndef PHP_WINUTIL_API
+#ifdef PHP_EXPORTS
+# define PHP_WINUTIL_API __declspec(dllexport)
+#else
+# define PHP_WINUTIL_API __declspec(dllimport)
+#endif
+#endif
+
+#include "php.h"
+#include "php_streams.h"
+#include <windows.h>
+
+#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
+#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
+#endif
+
+
+/*
+Check if a file descriptor associated to a stream is a console
+(valid fileno, neither redirected nor piped)
+*/
+PHP_WINUTIL_API BOOL php_win32_console_fileno_is_console(zend_long fileno);
+
+/*
+Check if the console attached to a file descriptor (screen buffer, not STDIN)
+has the ENABLE_VIRTUAL_TERMINAL_PROCESSING flag set
+*/
+PHP_WINUTIL_API BOOL php_win32_console_fileno_has_vt100(zend_long fileno);
+
+/*
+Set/unset the ENABLE_VIRTUAL_TERMINAL_PROCESSING flag for the screen buffer (STDOUT/STDERR)
+associated to a file descriptor
+*/
+PHP_WINUTIL_API BOOL php_win32_console_fileno_set_vt100(zend_long fileno, BOOL enable);
+
+#endif