Skip to content

Enable global and environment variables to be set in bulk #23

Description

@stevegrunwell

It would be helpful if there were setEnvironmentVariables() and setGlobalVariables() methods that would accept an array of environment/global variables to set at once.

Current:

$this->setEnvironmentVariable('FIRST_VAR', 'some-value');
$this->setEnvironmentVariable('SECOND_VAR', 'some-other-value');

Proposed:

$this->setEnvironmentVariables([
  'FIRST_VAR'  => 'some-value',
  'SECOND_VAR' => 'some-other-value',
]);

A good use-case would be in data providers:

/**
 * @test
 * @dataProvider provideEnvironmentVariableCombinations
 */
public function it_checks_the_environment_to_ensure_all_values_are_present(array $env): void
{
  $this->setEnvironmentVariables($env);

  // ...
}

public function provideEnvironmentVariableCombinations(): array
{
  return [
    'Missing all vars'   => [['FIRST_VAR' => null, 'SECOND_VAR' => null]],
    'Missing first var'  => [['FIRST_VAR' => null, 'SECOND_VAR' => 'some-other-value']],
    'Missing second var' => [['FIRST_VAR' => 'some-value', 'SECOND_VAR' => null]],
  ];
}

Under the hood, these methods could just loop through the array, passing the key/value combinations to the singular forms of the methods.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions