Skip to content
Snippets Groups Projects

Issue #3271144: Ensure new, changed or deleted service definitions are in the correct state after an update

Merged Issue #3271144: Ensure new, changed or deleted service definitions are in the correct state after an update
All threads resolved!
All threads resolved!
2 files
+ 32
31
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -97,36 +97,35 @@ class SystemChangeRecorder implements EventSubscriberInterface {
// Check if a permission added in the updated module is available.
$results['new permission exists'] = array_key_exists('added permission', $permissions) ? 'exists' : 'not exists';
// Check if changes to an existing service are picked up. The service itself
// is defined in updated_module, which is not, and should not be, a hard
// dependency of package_manager_test_api. So, we use ::hasService() to
// prevent an exception if updated_module is not installed.
if (\Drupal::hasService('updated_module.existing_service')) {
$results['value of existing service'] = \Drupal::service('updated_module.existing_service')->value;
}
// Check if changes to an existing service are picked up.
$this->recordServiceValue('updated_module.existing_service', $results);
// Check if a service removed from the updated module is available.
if (\Drupal::service('updated_module.deleted_service')) {
$results['deleted service exists'] = 'exists';
$results['value of deleted service'] = \Drupal::service('updated_module.deleted_service')->value;
}
else {
$results['deleted service exists'] = 'not exists';
}
$this->recordServiceValue('updated_module.deleted_service', $results);
// Check if a service added in the updated module is available.
if (\Drupal::hasService('updated_module.added_service')) {
$results['new service exists'] = 'exists';
$results['value of added service'] = \Drupal::service('updated_module.added_service')->value;
}
else {
$results['new service exists'] = 'not exists';
}
$this->recordServiceValue('updated_module.added_service', $results);
$phase = $event instanceof PreApplyEvent ? 'pre' : 'post';
$this->state->set("system_changes:$phase", $results);
}
/**
* Checks if a given service exists, and records its ->value property.
*
* @param string $service_id
* The ID of the service to check.
* @param array $results
* The current set of results, passed by reference.
*/
private function recordServiceValue(string $service_id, array &$results): void {
if (\Drupal::hasService($service_id)) {
$results["$service_id exists"] = 'exists';
$results["value of $service_id"] = \Drupal::service($service_id)->value;
}
else {
$results["$service_id exists"] = 'not exists';
}
}
/**
* Writes the results of ::recordSystemState() to file.
*
Loading