Skip to content

Commit 8eb8f6a

Browse files
committed
Added timeout setting for drush, since default timeout of 60 seconds might not be enough for some time-consuming commands. Also added new parameter $return_process.
1 parent 8a1aa8c commit 8eb8f6a

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

src/Codeception/Module/DrupalDrush.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* modules:
1414
* - DrupalDrush:
1515
* working_directory: './web'
16+
* timeout: 120
1617
* drush: './vendor/bin/drush'
1718
* alias: '@mysite.com'
1819
* options:
@@ -42,11 +43,14 @@ class DrupalDrush extends Module {
4243
* e.g. "en devel -y".
4344
* @param array $options
4445
* Associative array of options.
46+
* @param bool $return_process
47+
* If TRUE, the Process object will be returned. If false, the output of
48+
* Process::getOutput() will be returned. Defaults to FALSE.
4549
*
46-
* @return string
47-
* The process output.
50+
* @return string|\Symfony\Component\Process\Process
51+
* The process output, or the process itself.
4852
*/
49-
public function runDrush($command, array $options = []) {
53+
public function runDrush($command, array $options = [], $return_process = FALSE) {
5054
if ($alias = $this->_getConfig('alias')) {
5155
$command = $alias . ' ' . $command;
5256
}
@@ -56,7 +60,7 @@ public function runDrush($command, array $options = []) {
5660
elseif ($this->_getConfig('options')) {
5761
$command = $this->normalizeOptions($this->_getConfig('options')) . $command;
5862
}
59-
return Drush::runDrush($command, $this->_getConfig('drush'), $this->_getConfig('working_directory'));
63+
return Drush::runDrush($command, $this->_getConfig('drush'), $this->_getConfig('working_directory'), $this->_getConfig('timeout'), $return_process);
6064
}
6165

6266
/**

src/Codeception/Module/DrupalUser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function createUserWithRoles(array $roles = [], $password = FALSE) {
142142
*/
143143
public function logInAs($username) {
144144
$alias = $this->_getConfig('alias') ? $this->_getConfig('alias') . ' ' : '';
145-
$output = Drush::runDrush($alias. 'uli --name=' . $username, $this->_getConfig('drush'), $this->_getConfig('working_directory'));
145+
$output = Drush::runDrush($alias. 'uli --name=' . $username, $this->_getConfig('drush'), $this->_getConfig('working_directory'), $this->_getConfig('timeout'));
146146
$gen_url = str_replace(PHP_EOL, '', $output);
147147
$url = substr($gen_url, strpos($gen_url, '/user/reset'));
148148
$this->driver->amOnPage($url);

src/Codeception/Util/Drush.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,16 @@ class Drush {
2121
* The drush command to use.
2222
* @param string $pwd
2323
* Working directory.
24+
* @param int|float $timeout.
25+
* Drush execution timeout.
26+
* @param bool $return_process
27+
* If TRUE, the Process object will be returned. If false, the output of
28+
* Process::getOutput() will be returned. Defaults to FALSE.
2429
*
25-
* @return string
26-
* The process output.
30+
* @return string|\Symfony\Component\Process\Process
31+
* The process output, or the process object itself.
2732
*/
28-
public static function runDrush($command, $drush = 'drush', $pwd = NULL) {
33+
public static function runDrush($command, $drush = 'drush', $pwd = NULL, $timeout = NULL, $return_process = FALSE) {
2934
$command_args = array_merge([$drush], explode(' ', $command));
3035
$process = new Process($command_args);
3136

@@ -34,7 +39,14 @@ public static function runDrush($command, $drush = 'drush', $pwd = NULL) {
3439
$process->setWorkingDirectory($pwd);
3540
}
3641

37-
return $process->mustRun()->getOutput();
42+
// Set timeout if configured.
43+
if (isset($timeout)) {
44+
$process->setTimeout($timeout);
45+
}
46+
47+
$process->mustRun();
48+
49+
return $return_process ? $process : $process->getOutput();
3850
}
3951

4052
}

0 commit comments

Comments
 (0)