class DrupalKernelSiteTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/DrupalKernel/DrupalKernelSiteTest.php \Drupal\KernelTests\Core\DrupalKernel\DrupalKernelSiteTest
- 10 core/tests/Drupal/KernelTests/Core/DrupalKernel/DrupalKernelSiteTest.php \Drupal\KernelTests\Core\DrupalKernel\DrupalKernelSiteTest
Tests site-specific service overrides.
@group DrupalKernel
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \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 implements \PHPUnit\Framework\TestCase
- class \Drupal\KernelTests\Core\DrupalKernel\DrupalKernelSiteTest implements \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of DrupalKernelSiteTest
File
-
core/
tests/ Drupal/ KernelTests/ Core/ DrupalKernel/ DrupalKernelSiteTest.php, line 13
Namespace
Drupal\KernelTests\Core\DrupalKernelView source
class DrupalKernelSiteTest extends KernelTestBase {
/**
* Tests services.yml in site directory.
*/
public function testServicesYml() {
$container_yamls = Settings::get('container_yamls');
$container_yamls[] = $this->siteDirectory . '/services.yml';
$this->setSetting('container_yamls', $container_yamls);
$this->assertFalse($this->container
->has('site.service.yml'));
// A service provider class always has precedence over services.yml files.
// KernelTestBase::buildContainer() swaps out many services with in-memory
// implementations already, so those cannot be tested.
$this->assertSame('Drupal\\Core\\Cache\\DatabaseBackendFactory', get_class($this->container
->get('cache.backend.database')));
$class = __CLASS__;
$doc = <<<EOD
services:
# Add a new service.
site.service.yml:
class: {<span class="php-variable">$class</span>}
# Swap out a core service.
cache.backend.database:
class: Drupal\\Core\\Cache\\MemoryBackendFactory
EOD;
file_put_contents($this->siteDirectory . '/services.yml', $doc);
// Rebuild the container.
$this->container
->get('kernel')
->rebuildContainer();
$this->assertTrue($this->container
->has('site.service.yml'));
$this->assertSame('Drupal\\Core\\Cache\\MemoryBackendFactory', get_class($this->container
->get('cache.backend.database')));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.