diff --git a/system/Commands/Utilities/Environment.php b/system/Commands/Utilities/Environment.php index 44df09ad3bee..778e1833becb 100644 --- a/system/Commands/Utilities/Environment.php +++ b/system/Commands/Utilities/Environment.php @@ -85,7 +85,7 @@ final class Environment extends BaseCommand */ public function run(array $params) { - if ($params === []) { + if (! isset($params[0])) { CLI::write(sprintf('Your environment is currently set as %s.', CLI::color(service('superglobals')->server('CI_ENVIRONMENT', ENVIRONMENT), 'green'))); CLI::newLine(); diff --git a/tests/system/Commands/Utilities/EnvironmentCommandTest.php b/tests/system/Commands/Utilities/EnvironmentCommandTest.php index ca5236f5ff5b..3513436fa9f9 100644 --- a/tests/system/Commands/Utilities/EnvironmentCommandTest.php +++ b/tests/system/Commands/Utilities/EnvironmentCommandTest.php @@ -64,6 +64,13 @@ public function testUsingCommandWithNoArgumentsGivesCurrentEnvironment(): void $this->assertStringContainsString(ENVIRONMENT, $this->getStreamFilterBuffer()); } + public function testUsingCommandWithOptionsOnlyGivesCurrentEnvironment(): void + { + command('env --foo'); + $this->assertStringContainsString('testing', $this->getStreamFilterBuffer()); + $this->assertStringContainsString(ENVIRONMENT, $this->getStreamFilterBuffer()); + } + public function testProvidingTestingAsEnvGivesErrorMessage(): void { command('env testing'); diff --git a/user_guide_src/source/changelogs/v4.7.3.rst b/user_guide_src/source/changelogs/v4.7.3.rst index 268f49ecd227..0234850c0d9e 100644 --- a/user_guide_src/source/changelogs/v4.7.3.rst +++ b/user_guide_src/source/changelogs/v4.7.3.rst @@ -33,6 +33,7 @@ Bugs Fixed ********** - **Autoloader:** Fixed a bug where ``Autoloader::unregister()`` (used during tests) silently failed to remove handlers from the SPL autoload stack, causing closures to accumulate permanently. +- **Commands:** Fixed a bug in the ``env`` command where passing options only would cause the command to throw a ``TypeError`` instead of showing the current environment. - **Common:** Fixed a bug where the ``command()`` helper function did not properly clean up output buffers, which could lead to risky tests when exceptions were thrown. - **Validation:** Fixed a bug where ``Validation::getValidated()`` dropped fields whose validated value was explicitly ``null``.