function CacheCollectorTest::testSetAndGetNull

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php \Drupal\Tests\Core\Cache\CacheCollectorTest::testSetAndGetNull()
  2. 10 core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php \Drupal\Tests\Core\Cache\CacheCollectorTest::testSetAndGetNull()
  3. 11.x core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php \Drupal\Tests\Core\Cache\CacheCollectorTest::testSetAndGetNull()

Makes sure that NULL is a valid value and is collected.

File

core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php, line 90

Class

CacheCollectorTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Cache%21CacheCollector.php/class/CacheCollector/9" title="Default implementation for CacheCollectorInterface." class="local">\Drupal\Core\Cache\CacheCollector</a> @group Cache

Namespace

Drupal\Tests\Core\Cache

Code

public function testSetAndGetNull() {
    $key = $this->randomMachineName();
    $value = NULL;
    $this->cacheBackend
        ->expects($this->once())
        ->method('invalidate')
        ->with($this->cid);
    $this->collector
        ->set($key, $value);
    $this->assertTrue($this->collector
        ->has($key));
    $this->assertEquals($value, $this->collector
        ->get($key));
    // Ensure that getting a value that isn't set does not mark it as
    // existent.
    $non_existing_key = $this->randomMachineName(7);
    $this->collector
        ->get($non_existing_key);
    $this->assertFalse($this->collector
        ->has($non_existing_key));
}

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