Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
stevegrunwell opened this issue Jan 12, 2021 · 0 comments
Open

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

stevegrunwell opened this issue Jan 12, 2021 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@stevegrunwell
Copy link
Member

stevegrunwell commented Jan 12, 2021

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.

@stevegrunwell stevegrunwell added enhancement New feature or request good first issue Good for newcomers labels Jan 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant