class ServiceProviderTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/ServiceProvider/ServiceProviderTest.php \Drupal\KernelTests\Core\ServiceProvider\ServiceProviderTest
- 10 core/tests/Drupal/KernelTests/Core/ServiceProvider/ServiceProviderTest.php \Drupal\KernelTests\Core\ServiceProvider\ServiceProviderTest
- 8.9.x core/tests/Drupal/KernelTests/Core/ServiceProvider/ServiceProviderTest.php \Drupal\KernelTests\Core\ServiceProvider\ServiceProviderTest
Tests service provider registration to the DIC.
@group ServiceProvider
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\KernelTests\Core\ServiceProvider\ServiceProviderTest extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of ServiceProviderTest
File
-
core/
tests/ Drupal/ KernelTests/ Core/ ServiceProvider/ ServiceProviderTest.php, line 12
Namespace
Drupal\KernelTests\Core\ServiceProviderView source
class ServiceProviderTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'file',
'service_provider_test',
'system',
];
/**
* Tests that services provided by module service providers get registered to the DIC.
*/
public function testServiceProviderRegistration() {
$definition = $this->container
->getDefinition('file.usage');
$this->assertSame('Drupal\\service_provider_test\\TestFileUsage', $definition->getClass(), 'Class has been changed');
$this->assertTrue(\Drupal::hasService('service_provider_test_class'), 'The service_provider_test_class service has been registered to the DIC');
}
/**
* Tests that the DIC keeps up with module enable/disable in the same request.
*/
public function testServiceProviderRegistrationDynamic() {
// Uninstall the module and ensure the service provider's service is not registered.
\Drupal::service('module_installer')->uninstall([
'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([
'service_provider_test',
]);
$this->assertTrue(\Drupal::hasService('service_provider_test_class'), 'The service_provider_test_class service exists in the DIC.');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.