function StorageTestBase::testNonExistingKeys
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/KeyValueStore/StorageTestBase.php \Drupal\KernelTests\Core\KeyValueStore\StorageTestBase::testNonExistingKeys()
- 8.9.x core/tests/Drupal/KernelTests/Core/KeyValueStore/StorageTestBase.php \Drupal\KernelTests\Core\KeyValueStore\StorageTestBase::testNonExistingKeys()
- 11.x core/tests/Drupal/KernelTests/Core/KeyValueStore/StorageTestBase.php \Drupal\KernelTests\Core\KeyValueStore\StorageTestBase::testNonExistingKeys()
Tests expected behavior for non-existing keys.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ KeyValueStore/ StorageTestBase.php, line 132
Class
- StorageTestBase
- Base class for testing key-value storages.
Namespace
Drupal\KernelTests\Core\KeyValueStoreCode
public function testNonExistingKeys() : void {
$stores = $this->createStorage();
// Verify that a non-existing key returns NULL as value.
$this->assertNull($stores[0]->get('foo'));
// Verify that a non-existing key with a default returns the default.
$this->assertSame('bar', $stores[0]->get('foo', 'bar'));
// Verify that a FALSE value can be stored.
$stores[0]->set('foo', FALSE);
$this->assertFalse($stores[0]->get('foo'));
// Verify that a deleted key returns NULL as value.
$stores[0]->delete('foo');
$this->assertNull($stores[0]->get('foo'));
// Verify that a non-existing key is not returned when getting multiple keys.
$stores[0]->set('bar', 'baz');
$values = $stores[0]->getMultiple([
'foo',
'bar',
]);
$this->assertFalse(isset($values['foo']), "Key 'foo' not found.");
$this->assertSame('baz', $values['bar']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.