Do not (only) use PHP_SAPI to determine CLI mode

Created on 25 August 2017, about 8 years ago
Updated 30 January 2023, over 2 years ago

Currently, it is not possible to run the test suite with phpdbg because we detect CLI mode by simple checking if PHP_SAPI is 'cli'. That is not good enough because there are various other scenarios in which you are running in a command-line environment where the interface does not identify as "cli" but "phpdbg" or even as "php-cgi".

There are other ways to more reliably check this and it was even implemented much better in Drupal 7 https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drup.... I am not sure why we removed that / replaced it with a less capable implementation.... Anyways, in order be able to run the test suite with something like phpdbg we need to fix this.

See e.g. other places in popular PHP libraries that do something similar:

PHPUnit: https://github.com/sebastianbergmann/phpunit/blob/a1b5663a426b85854e97dc...
Symfony: https://github.com/symfony/symfony/blob/2b257d7c94ae89a777d6b7956e315a3d...

However, I believe that there is an even better way. We could check for whether STDIN / STDOUT / STDERR are defined which is only the case in a command-line environment.

I am providing a patch for this exact solution. Let me know what you think ...

πŸ“Œ Task
Status

Needs work

Version

10.1 ✨

Component
BaseΒ  β†’

Last updated 35 minutes ago

Created by

πŸ‡¦πŸ‡ΉAustria fubhy

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The Needs Review Queue Bot β†’ tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • πŸ‡«πŸ‡·France pdureau Paris

    With the patch from #19, Drupal\Component\Utility\Environment::isCli() is returning TRUE instead of FALSE when we use drush rs

Production build 0.71.5 2024