Skip to content

Commit e5d9695

Browse files
committed
fix: ensure calling env command with options only would not throw
1 parent 2010172 commit e5d9695

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
@@ -33,6 +33,7 @@ Bugs Fixed
3333
**********
3434

3535
- **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.
36+
- **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.
3637
- **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.
3738
- **Validation:** Fixed a bug where ``Validation::getValidated()`` dropped fields whose validated value was explicitly ``null``.
3839

0 commit comments

Comments
 (0)