You are here

function ServiceProviderTest::testServiceProviderRegistrationDynamic in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/ServiceProvider/ServiceProviderTest.php \Drupal\system\Tests\ServiceProvider\ServiceProviderTest::testServiceProviderRegistrationDynamic()

Tests that the DIC keeps up with module enable/disable in the same request.

File

core/modules/system/src/Tests/ServiceProvider/ServiceProviderTest.php, line 38
Contains \Drupal\system\Tests\ServiceProvider\ServiceProviderTest.

Class

ServiceProviderTest
Tests service provider registration to the DIC.

Namespace

Drupal\system\Tests\ServiceProvider

Code

function testServiceProviderRegistrationDynamic() {

  // Uninstall the module and ensure the service provider's service is not registered.
  \Drupal::service('module_installer')
    ->uninstall(array(
    'service_provider_test',
  ));
  $this
    ->assertFalse(\Drupal::hasService('service_provider_test_class'), 'The service_provider_test_class service does not exist in the DIC.');

  // Install the module and ensure the service provider's service is registered.
  \Drupal::service('module_installer')
    ->install(array(
    'service_provider_test',
  ));
  $this
    ->assertTrue(\Drupal::hasService('service_provider_test_class'), 'The service_provider_test_class service exists in the DIC.');
}