Skip to content
This repository was archived by the owner on Dec 14, 2020. It is now read-only.

Commit 9cedfdf

Browse files
authored
Merge pull request #6 from karriereat/feature/process-timeout-flag
Add parameter "ptimeout"
2 parents 24ec64f + a562450 commit 9cedfdf

File tree

7 files changed

+35
-1
lines changed

7 files changed

+35
-1
lines changed

src/CodeCoverage.php

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public static function run(Event $event)
2626

2727
$process = new Process($command);
2828
$process->setTtyByArguments($eventArguments);
29+
$process->setProcessTimeoutByArguments($eventArguments);
2930
$process->run();
3031

3132
return $process->getExitCode();

src/CodeStyleChecker.php

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public static function run(Event $event)
3232

3333
$process = new Process($command);
3434
$process->setTtyByArguments($eventArguments);
35+
$process->setProcessTimeoutByArguments($eventArguments);
3536
$process->run();
3637

3738
$composerIO->write($process->getOutput());

src/CodeStyleFixer.php

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public static function run(Event $event)
2727

2828
$process = new Process(self::$command);
2929
$process->setTtyByArguments($eventArguments);
30+
$process->setProcessTimeoutByArguments($eventArguments);
3031
$process->run();
3132

3233
$composerIO->write($process->getOutput());

src/MessDetector.php

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public static function run(Event $event)
2626

2727
$process = new Process($command);
2828
$process->setTtyByArguments($eventArguments);
29+
$process->setProcessTimeoutByArguments($eventArguments);
2930
$process->run();
3031

3132
return $process->getExitCode();

src/Process/Process.php

+23-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ class Process extends SymfonyProcess
1717
*/
1818
const NO_TTY_FLAG = 'notty';
1919

20+
/**
21+
* Flag to set the symfony process timeout as parameter.
22+
*
23+
* @var string
24+
*/
25+
const PROCESS_TIMEOUT = 'ptimeout';
26+
2027
public function __construct($commandline)
2128
{
2229
parent::__construct($commandline);
@@ -25,7 +32,7 @@ public function __construct($commandline)
2532
/**
2633
* Check if the process was started with a 'notty' flag, if yes, deactivate it.
2734
*
28-
* @param $eventArguments
35+
* @param array $eventArguments
2936
* @return bool
3037
*/
3138
public function setTtyByArguments($eventArguments)
@@ -44,4 +51,19 @@ public function setTtyByArguments($eventArguments)
4451

4552
return true;
4653
}
54+
55+
/**
56+
* Check if the process was started with a 'ptimeout' flag, if not, use default 60s timeout
57+
*
58+
* @param array $eventArguments
59+
* @return bool
60+
*/
61+
public function setProcessTimeoutByArguments($eventArguments)
62+
{
63+
if (self::hasParameterOption(self::PROCESS_TIMEOUT, $eventArguments)) {
64+
$this->setTimeout($eventArguments[self::PROCESS_TIMEOUT]);
65+
}
66+
67+
return true;
68+
}
4769
}

src/SpecificationTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public static function run(Event $event)
3232

3333
$process = new Process($command);
3434
$process->setTtyByArguments($eventArguments);
35+
$process->setProcessTimeoutByArguments($eventArguments);
3536
$process->run();
3637

3738
$composerIO->write($process->getOutput());

tests/specs/Process/ProcessSpec.php

+7
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,11 @@ function its_tty_mode_can_be_set()
3838
// Testing for `true` or `false` doesn't make sense, so we skip this test.
3939
}
4040
}
41+
42+
function its_process_timeout_can_be_set()
43+
{
44+
$this->setProcessTimeoutByArguments(array(Process::PROCESS_TIMEOUT => 3600))->shouldReturn(true);
45+
46+
$this->getTimeout()->shouldReturn((double) 3600);
47+
}
4148
}

0 commit comments

Comments
 (0)