protected function ApigeeEdgeUtilTestTrait::createTestKey in Apigee Edge 8
Creates a test key from environment variables, using config key storage.
Using config storage , as opposed to environment vars, has the advantage of the key values persisting in subsequent page requests.
2 calls to ApigeeEdgeUtilTestTrait::createTestKey()
- ApigeeEdgeFunctionalTestTrait::initTestEnv in tests/
src/ Traits/ ApigeeEdgeFunctionalTestTrait.php - Initializes test environment with required configuration.
- ApigeeMockApiClientHelperTrait::initAuth in tests/
modules/ apigee_mock_api_client/ tests/ src/ Traits/ ApigeeMockApiClientHelperTrait.php - Initialize SDK connector.
File
- tests/
src/ Traits/ ApigeeEdgeUtilTestTrait.php, line 36
Class
- ApigeeEdgeUtilTestTrait
- Provides common functionality for the Apigee Edge test classes.
Namespace
Drupal\Tests\apigee_edge\TraitsCode
protected function createTestKey() : void {
$environment_variables = [];
$definition = \Drupal::service('plugin.manager.key.key_type')
->getDefinition('apigee_auth');
foreach ($definition['multivalue']['fields'] as $id => $field) {
$env_var_name = 'APIGEE_EDGE_' . mb_strtoupper($id);
if (getenv($env_var_name)) {
$environment_variables[$id] = getenv($env_var_name);
}
}
$key = Key::create([
'id' => 'test',
'label' => 'test',
'key_type' => 'apigee_auth',
'key_provider' => 'config',
'key_input' => 'none',
'key_provider_settings' => [
'key_value' => json_encode($environment_variables),
],
]);
try {
$key
->save();
} catch (EntityStorageException $exception) {
$this
->fail('Could not create key for testing.');
}
}