Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions integration-tests/variable_write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,23 @@ func TestVariableCreate(t *testing.T) {
assertTrimmed(t, "false", f.Run("var:get", "-p", p, "env:TEST", "-l", "p", "-P", "visible_runtime"))
}

func TestVariableCreateDefaultEnvironment(t *testing.T) {
// Regression test for CLI-164: using "-e ." (the default-environment code)
// must not fail form validation of the --environment option.
s := setupVariableTest(t)
s.apiHandler.SetEnvironments([]*mockapi.Environment{s.mainEnv})

f, p := s.factory, s.projectID

_, stdErr, err := f.RunCombinedOutput("var:create", "-p", p, "-e", ".", "-l", "e", "env:FOOBAR", "--value", "bar foo")
assert.NoError(t, err)
assert.Contains(t, stdErr, "Selecting default environment")
assert.Contains(t, stdErr, "Creating variable env:FOOBAR on the environment main")
assert.NotContains(t, stdErr, "is not one of")

assertTrimmed(t, "bar foo", f.Run("var:get", "-p", p, "-e", "main", "env:FOOBAR", "-P", "value"))
}

func TestVariableCreateWithAppScope(t *testing.T) {
s := setupVariableTest(t)

Expand Down
8 changes: 8 additions & 0 deletions legacy/src/Command/Variable/VariableCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$selection = $this->selector->getSelection($input, new SelectorConfig(envRequired: false));
$this->selection = $selection;

// The 'environment' form field validates the --environment option
// against the list of environment IDs. Replace the default-environment
// placeholder ('.') with the resolved environment ID so validation
// succeeds. See CLI-164.
if ($selection->hasEnvironment() && $input->getOption('environment') === Selector::DEFAULT_ENVIRONMENT_CODE) {
$input->setOption('environment', $selection->getEnvironment()->id);
}

// Merge the 'name' argument with the --name option.
if ($input->getArgument('name')) {
if ($input->getOption('name')) {
Expand Down