From 2329be1d565e8e7e27b8b820f52bcce8fa30fe8a Mon Sep 17 00:00:00 2001 From: sam marshall Date: Mon, 9 Feb 2026 12:02:21 +0000 Subject: [PATCH] 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. --- public/admin/tool/behat/cli/run.php | 5 +++++ public/lib/behat/classes/util.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/public/admin/tool/behat/cli/run.php b/public/admin/tool/behat/cli/run.php index e7d346d62c0..b393f2102a9 100644 --- a/public/admin/tool/behat/cli/run.php +++ b/public/admin/tool/behat/cli/run.php @@ -224,6 +224,11 @@ if (empty($parallelrun)) { $cmds['singlerun'] = $runtestscommand; echo "Running single behat site:" . PHP_EOL; + // The inner PHP process is not marked as having an interactive terminal even if it's passed + // through from this one which does, so we need to pass it through as an environment variable. + if (function_exists('posix_isatty') && posix_isatty(STDOUT)) { + putenv('MOODLE_BEHAT_RUNNING_IN_TTY=1'); + } passthru("php $runtestscommand", $status); $exitcodes['singlerun'] = $status; chdir($cwd); diff --git a/public/lib/behat/classes/util.php b/public/lib/behat/classes/util.php index 83c64db4f26..cd347ca934a 100644 --- a/public/lib/behat/classes/util.php +++ b/public/lib/behat/classes/util.php @@ -486,7 +486,7 @@ class behat_util extends testing_util { $posixexists = function_exists('posix_isatty'); // Make sure this step is only used with interactive terminal (if detected). - if ($posixexists && !@posix_isatty(STDOUT)) { + if ($posixexists && !@posix_isatty(STDOUT) && getenv('MOODLE_BEHAT_RUNNING_IN_TTY') !== '1') { throw new ExpectationException('Break point should only be used with interactive terminal.', $session); }