Skip to content

Commit 2329be1

Browse files
committed
MDL-87905 Behat: pause incorrectly thinks terminal not interactive
When run from behat/cli/run.php, the pause command may fail because it thinks the terminal is not interactive, even if the input and output is passed through from an interactive terminal run.
1 parent 09b2103 commit 2329be1

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

public/admin/tool/behat/cli/run.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@
224224
$cmds['singlerun'] = $runtestscommand;
225225

226226
echo "Running single behat site:" . PHP_EOL;
227+
// The inner PHP process is not marked as having an interactive terminal even if it's passed
228+
// through from this one which does, so we need to pass it through as an environment variable.
229+
if (function_exists('posix_isatty') && posix_isatty(STDOUT)) {
230+
putenv('MOODLE_BEHAT_RUNNING_IN_TTY=1');
231+
}
227232
passthru("php $runtestscommand", $status);
228233
$exitcodes['singlerun'] = $status;
229234
chdir($cwd);

public/lib/behat/classes/util.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ public static function pause(Session $session, string $message): void {
486486
$posixexists = function_exists('posix_isatty');
487487

488488
// Make sure this step is only used with interactive terminal (if detected).
489-
if ($posixexists && !@posix_isatty(STDOUT)) {
489+
if ($posixexists && !@posix_isatty(STDOUT) && getenv('MOODLE_BEHAT_RUNNING_IN_TTY') !== '1') {
490490
throw new ExpectationException('Break point should only be used with interactive terminal.', $session);
491491
}
492492

0 commit comments

Comments
 (0)