Skip to content

Commit 20c54bb

Browse files
committed
Fix error reporting when terminating process that is not running
1 parent b20231a commit 20c54bb

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

src/Process.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ public function close()
181181
*/
182182
public function terminate($signal = null)
183183
{
184+
if ($this->process === null) {
185+
return false;
186+
}
187+
184188
if ($signal !== null) {
185189
return proc_terminate($this->process, $signal);
186190
}

tests/AbstractProcessTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,13 @@ public function testStartAlreadyRunningProcess()
284284
$process->start($this->createLoop());
285285
}
286286

287+
public function testTerminateProcesWithoutStartingReturnsFalse()
288+
{
289+
$process = new Process('sleep 1');
290+
291+
$this->assertFalse($process->terminate());
292+
}
293+
287294
public function testTerminateWithDefaultTermSignalUsingEventLoop()
288295
{
289296
if (defined('PHP_WINDOWS_VERSION_BUILD')) {

0 commit comments

Comments
 (0)