Skip to content

Commit 554be61

Browse files
authored
fix: ensure calling env command with options only would not throw (#10114)
1 parent 855d60a commit 554be61

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

system/Commands/Utilities/Environment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ final class Environment extends BaseCommand
8585
*/
8686
public function run(array $params)
8787
{
88-
if ($params === []) {
88+
if (! isset($params[0])) {
8989
CLI::write(sprintf('Your environment is currently set as %s.', CLI::color(service('superglobals')->server('CI_ENVIRONMENT', ENVIRONMENT), 'green')));
9090
CLI::newLine();
9191

tests/system/Commands/Utilities/EnvironmentCommandTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ public function testUsingCommandWithNoArgumentsGivesCurrentEnvironment(): void
6464
$this->assertStringContainsString(ENVIRONMENT, $this->getStreamFilterBuffer());
6565
}
6666

67+
public function testUsingCommandWithOptionsOnlyGivesCurrentEnvironment(): void
68+
{
69+
command('env --foo');
70+
$this->assertStringContainsString('testing', $this->getStreamFilterBuffer());
71+
$this->assertStringContainsString(ENVIRONMENT, $this->getStreamFilterBuffer());
72+
}
73+
6774
public function testProvidingTestingAsEnvGivesErrorMessage(): void
6875
{
6976
command('env testing');

user_guide_src/source/changelogs/v4.7.3.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Bugs Fixed
3737
**********
3838

3939
- **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.
40+
- **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.
4041
- **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.
4142
- **Validation:** Fixed a bug where ``Validation::getValidated()`` dropped fields whose validated value was explicitly ``null``.
4243

0 commit comments

Comments
 (0)