|
| 1 | +--TEST-- |
| 2 | +Check cli_process_title support in Windows |
| 3 | +--SKIPIF-- |
| 4 | +<?php |
| 5 | +if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') |
| 6 | + die("skip"); |
| 7 | +?> |
| 8 | +--FILE-- |
| 9 | +<?php |
| 10 | + |
| 11 | +// On Windows 8, this test does not work the same way. When the PowerShell command |
| 12 | +// "get-process" is executed using shell_exec, it overwrites the ConsoleTitle with |
| 13 | +// "Windows PowerShell" and this title ONLY clears away when the php.exe |
| 14 | +// process exits i.e. the test finishes. |
| 15 | +// On older versions like Windows 7 though, running the command appends |
| 16 | +// "Windows PowerShell" to the ConsoleTitle temporarily and the title reverts |
| 17 | +// back to the original once shell_exec is done. |
| 18 | +// Hence on Windows 8, we don't verify that the title is actually set by |
| 19 | +// cli_set_process_title(). We're only making the API calls to ensure there are |
| 20 | +// no warnings/errors. |
| 21 | + |
| 22 | +$is_windows8 = false; |
| 23 | +$ps_output = shell_exec("PowerShell \"(Get-Host).UI.RawUI.WindowTitle\""); |
| 24 | +if ($ps_output === null) |
| 25 | +{ |
| 26 | + echo "Get-Host failed\n"; |
| 27 | + die(); |
| 28 | +} |
| 29 | + |
| 30 | +$ps_output = trim($ps_output); |
| 31 | +if ($ps_output == "Windows PowerShell") |
| 32 | + $is_windows8 = true; |
| 33 | + |
| 34 | +echo "*** Testing setting the process title ***\n"; |
| 35 | + |
| 36 | +$original_title = uniqid("title", true); |
| 37 | +$pid = getmypid(); |
| 38 | + |
| 39 | +if (cli_set_process_title($original_title) === true) |
| 40 | + echo "Successfully set title\n"; |
| 41 | + |
| 42 | +if ($is_windows8) |
| 43 | +{ |
| 44 | + $loaded_title = $original_title; |
| 45 | +} |
| 46 | +else |
| 47 | +{ |
| 48 | + $loaded_title = shell_exec("PowerShell \"get-process cmd*,powershell* | Select-Object mainWindowTitle | ft -hide\""); |
| 49 | + |
| 50 | + if ($loaded_title === null) |
| 51 | + { |
| 52 | + echo "Reading title using get-process failed\n"; |
| 53 | + die(); |
| 54 | + } |
| 55 | + |
| 56 | + // Kind of convoluted. So when the test is run on Windows 7 or older, the console where |
| 57 | + // the run-tests.php is executed forks a php.exe, which forks a cmd.exe, which then forks |
| 58 | + // a final php.exe to run the actual test. But the console title is set for the original console. |
| 59 | + // I couldn't figure out a good way to navigate this, so we're "grep'ing" all possible |
| 60 | + // console windows for our very unique title. It should occur exactly once in the grep |
| 61 | + // output. |
| 62 | + $pos = strpos($loaded_title, $original_title, 0); |
| 63 | + if ($pos !== false) |
| 64 | + { |
| 65 | + $pos = strpos($loaded_title, $original_title, $pos + strlen($original_title)); |
| 66 | + if ($pos === false) |
| 67 | + $loaded_title = $original_title; |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +if ($loaded_title == $original_title) |
| 72 | + echo "Successfully verified title using get-process\n"; |
| 73 | +else |
| 74 | + echo "Actually loaded from get-process: $loaded_title\n"; |
| 75 | + |
| 76 | +$read_title = cli_get_process_title(); |
| 77 | +if ($read_title == $original_title) |
| 78 | + echo "Successfully verified title using get\n"; |
| 79 | +else |
| 80 | + echo "Actually loaded from get: $read_title\n"; |
| 81 | + |
| 82 | +?> |
| 83 | +--EXPECTF-- |
| 84 | +*** Testing setting the process title *** |
| 85 | +Successfully set title |
| 86 | +Successfully verified title using get-process |
| 87 | +Successfully verified title using get |
0 commit comments