Repaired tests + refactored code for tests
This commit is contained in:
parent
b327ad8083
commit
9de4fb51d3
37 changed files with 409 additions and 1125 deletions
|
|
@ -28,14 +28,11 @@ class PosixProcessControl implements ProcessControlInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Sends a TERMINATE or KILL signal to the process using posix_kill.
|
||||
*
|
||||
* @param int $pid
|
||||
* @param bool $forcefully Whether to send TERMINATE (false) or KILL (true).
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function kill($pid, $forcefully = false)
|
||||
{
|
||||
posix_kill($pid, $forcefully ? 9 : 15);
|
||||
return posix_kill($pid, $forcefully ? 9 : 15);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@ namespace PHPCensor\ProcessControl;
|
|||
*/
|
||||
interface ProcessControlInterface
|
||||
{
|
||||
/** Checks if a process exists.
|
||||
/**
|
||||
* Checks if a process exists.
|
||||
*
|
||||
* @param int $pid The process identifier.
|
||||
*
|
||||
|
|
@ -24,10 +25,13 @@ interface ProcessControlInterface
|
|||
*/
|
||||
public function isRunning($pid);
|
||||
|
||||
/** Terminate a running process.
|
||||
/**
|
||||
* Terminate a running process.
|
||||
*
|
||||
* @param int $pid The process identifier.
|
||||
* @param bool $forcefully Whether to gently (false) or forcefully (true) terminate the process.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function kill($pid, $forcefully = false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,14 +30,16 @@ class UnixProcessControl implements ProcessControlInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Sends a signal using the "kill" command.
|
||||
*
|
||||
* @param int $pid
|
||||
* @param bool $forcefully
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function kill($pid, $forcefully = false)
|
||||
{
|
||||
exec(sprintf("kill -%d %d", $forcefully ? 9 : 15, $pid));
|
||||
$output = [];
|
||||
$result = 1;
|
||||
|
||||
exec(sprintf("kill -%d %d", $forcefully ? 9 : 15, $pid), $output, $result);
|
||||
|
||||
return !$result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -31,15 +31,16 @@ class WindowsProcessControl implements ProcessControlInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Terminate the process using the "taskkill" command.
|
||||
*
|
||||
* @param integer $pid
|
||||
*
|
||||
* @param bool $forcefully
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function kill($pid, $forcefully = false)
|
||||
{
|
||||
$output = [];
|
||||
$result = 1;
|
||||
|
||||
exec(sprintf("taskkill /t /pid %d %s 2>nul:", $pid, $forcefully ? '/f' : ''));
|
||||
|
||||
return !$result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue