You are here

public function CachedContainerBuilderTest::test_isCached_getContainerDefinition in Service Container 7

Same name and namespace in other branches
  1. 7.2 tests/src/DependencyInjection/CachedContainerBuilderTest.php \Drupal\Tests\service_container\DependencyInjection\CachedContainerBuilderTest::test_isCached_getContainerDefinition()

@covers ::isCached() @covers ::getContainerDefinition() @covers ::getCache() @covers ::setCache()

File

tests/src/DependencyInjection/CachedContainerBuilderTest.php, line 91
Contains \Drupal\Tests\service_container\DependencyInjection\CachedContainerBuilderTest

Class

CachedContainerBuilderTest
@coversDefaultClass \Drupal\service_container\DependencyInjection\CachedContainerBuilder @group dic

Namespace

Drupal\Tests\service_container\DependencyInjection

Code

public function test_isCached_getContainerDefinition() {
  $fake_definition = $this
    ->getFakeContainerDefinition();

  // Due to the nature of the isCached() functionality, here are some extra
  // tests to ensure the cached data is stored correctly.
  // It is cached, but isCached() was called before.
  $cached_container_builder = $this
    ->getCachedContainerBuilderMock('service_container:container_definition');
  $this
    ->assertTrue($cached_container_builder
    ->isCached(), 'CachedContainerBuilder is cached.');
  $this
    ->assertEquals($fake_definition, $cached_container_builder
    ->getContainerDefinition(), 'CachedContainerBuilder definition matches when cached.');

  // It is not cached, but isCached() was called before and then its cached.
  $uncached_container_builder = $this
    ->getCachedContainerBuilderMock('service_container:miss_container_definition');
  $this
    ->assertFalse($uncached_container_builder
    ->isCached(), 'CachedContainerBuilder is not cached.');
  $this
    ->assertEquals($fake_definition, $uncached_container_builder
    ->getContainerDefinition(), 'CachedContainerBuilder definition matches when not cached.');
  $this
    ->assertTrue($uncached_container_builder
    ->isCached(), 'CachedContainerBuilder is now cached.');
}