function AutoconfigurationTest::testCoreServiceTags

Same name in other branches
  1. 10 core/tests/Drupal/KernelTests/Core/DependencyInjection/AutoconfigurationTest.php \Drupal\KernelTests\Core\DependencyInjection\AutoconfigurationTest::testCoreServiceTags()

Tests that core services do not use tags if autoconfiguration is enabled.

File

core/tests/Drupal/KernelTests/Core/DependencyInjection/AutoconfigurationTest.php, line 23

Class

AutoconfigurationTest
Tests autoconfiguration of services.

Namespace

Drupal\KernelTests\Core\DependencyInjection

Code

public function testCoreServiceTags() : void {
    $filenames = array_map(fn($module) => "core/modules/{$module[0]}/{$module[0]}.services.yml", $this->coreModuleListDataProvider());
    $filenames[] = 'core/core.services.yml';
    foreach (array_filter($filenames, 'file_exists') as $filename) {
        $services = Yaml::decode(file_get_contents($filename))['services'];
        if (!empty($services['_defaults']['autoconfigure'])) {
            foreach ($services as $id => $service) {
                if (is_array($service) && isset($service['tags'])) {
                    foreach ($service['tags'] as $tag) {
                        $tag_name = is_string($tag) ? $tag : $tag['name'];
                        $this->assertNotEquals('event_subscriber', $tag_name, "Service '{$id}' in {$filename} should not be tagged with 'event_subscriber'.");
                    }
                }
            }
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.