cli_process_title_windows.phpt [plain text]
--TEST--
Check cli_process_title support in Windows
--SKIPIF--
<?php
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')
die("skip");
?>
--FILE--
<?php
$is_windows8 = false;
$ps_output = shell_exec("PowerShell -NoProfile \"(Get-Host).UI.RawUI.WindowTitle\"");
if ($ps_output === null)
{
echo "Get-Host failed\n";
die();
}
$ps_output = trim($ps_output);
$end_title_windows8 = ": Windows PowerShell";
if (($ps_output == "Windows PowerShell") || (strlen($ps_output) > strlen($end_title_windows8) && substr($ps_output,-strlen($end_title_windows8)) === $end_title_windows8))
$is_windows8 = true;
echo "*** Testing setting the process title ***\n";
$original_title = uniqid("title", true);
$pid = getmypid();
if (cli_set_process_title($original_title) === true)
echo "Successfully set title\n";
if ($is_windows8)
{
$loaded_title = $original_title;
}
else
{
$loaded_title = shell_exec("PowerShell -NoProfile \"get-process cmd*,powershell* | Select-Object mainWindowTitle | ft -hide\"");
if ($loaded_title === null)
{
echo "Reading title using get-process failed\n";
die();
}
if (substr_count($loaded_title, $original_title, 0) == 1)
$loaded_title = $original_title;
}
if ($loaded_title == $original_title)
echo "Successfully verified title using get-process\n";
else
echo "Actually loaded from get-process: $loaded_title\n";
$read_title = cli_get_process_title();
if (substr_count($read_title, $original_title, 0) == 1)
echo "Successfully verified title using get\n";
else
echo "Actually loaded from get: $read_title\n";
?>
--EXPECTF--
*** Testing setting the process title ***
Successfully set title
Successfully verified title using get-process
Successfully verified title using get