function StateTest::testSetMultipleLock
Same name and namespace in other branches
- 11.x core/tests/Drupal/Tests/Core/State/StateTest.php \Drupal\Tests\Core\State\StateTest::testSetMultipleLock()
Tests setMultiple() method with different lock behavior.
Attributes
#[TestWith([
TRUE,
])]
#[TestWith([
FALSE,
])]
File
-
core/
tests/ Drupal/ Tests/ Core/ State/ StateTest.php, line 290
Class
- StateTest
- Tests Drupal\Core\State\State.
Namespace
Drupal\Tests\Core\StateCode
public function testSetMultipleLock(bool $lock_acquired) : void {
$this->keyValueStorage = $this->createMock(KeyValueStoreInterface::class);
$factory = $this->createMock(KeyValueFactoryInterface::class);
$factory->expects($this->once())
->method('get')
->with('state')
->willReturn($this->keyValueStorage);
$lock = $this->createMock(LockBackendInterface::class);
$cache = $this->createMock(CacheBackendInterface::class);
if ($lock_acquired) {
$lock->expects($this->once())
->method('acquire')
->willReturn(TRUE);
$lock->expects($this->once())
->method('release');
$cache->expects($this->once())
->method('set');
}
else {
$lock->expects($this->exactly(2))
->method('acquire')
->willReturn(FALSE);
$cache->expects($this->exactly(2))
->method('set');
$lock->expects($this->never())
->method('release');
}
$state = new State($factory, $cache, $lock);
$values = [
'key1' => 'value1',
'key2' => 'value2',
'key3' => 'value3',
];
$this->keyValueStorage
->expects($this->once())
->method('setMultiple')
->with($values);
$state->setMultiple($values);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.