function InputTest::testDefaultInputFromEnvironmentVariables
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Recipe/InputTest.php \Drupal\KernelTests\Core\Recipe\InputTest::testDefaultInputFromEnvironmentVariables()
Tests getting default input values from environment variables.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Recipe/ InputTest.php, line 362
Class
- InputTest
- Tests Input.
Namespace
Drupal\KernelTests\Core\RecipeCode
public function testDefaultInputFromEnvironmentVariables() : void {
$this->config('system.site')
->set('name', 'Hello Thar')
->set('slogan', 'Very important')
->save();
$recipe = $this->createRecipe(<<<YAML
name: 'Input from environment variables'
input:
name:
data_type: string
description: The name of the site.
default:
source: env
env: SITE_NAME
config:
actions:
system.site:
simpleConfigUpdate:
name: \${name}
YAML);
putenv('SITE_NAME=Input Test');
// Mock a collector that only returns the default value.
$collector = $this->createMock(InputCollectorInterface::class);
$collector->expects($this->any())
->method('collectValue')
->withAnyParameters()
->willReturnArgument(2);
$recipe->input
->collectAll($collector);
RecipeRunner::processRecipe($recipe);
$config = $this->config('system.site');
$this->assertSame('Input Test', $config->get('name'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.