redis-8.x-1.x-dev/tests/src/Kernel/RedisLockTest.php
tests/src/Kernel/RedisLockTest.php
<?php
namespace Drupal\Tests\redis\Kernel;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Lock\LockBackendInterface;
use Drupal\KernelTests\Core\Lock\LockTest;
use Drupal\redis\Lock\RedisLock;
use Drupal\Tests\redis\Traits\RedisTestInterfaceTrait;
use Symfony\Component\DependencyInjection\Reference;
/**
* Tests the Redis non-persistent lock backend.
*
* Extends the core test to include test coverage for lockMayBeAvailable()
* method invoked on a non-yet acquired lock.
*
* @group redis
*/
class RedisLockTest extends LockTest {
use RedisTestInterfaceTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'redis',
];
/**
* {@inheritdoc}
*/
public function register(ContainerBuilder $container) {
self::setUpSettings();
parent::register($container);
$container->register('lock', LockBackendInterface::class)
->setFactory([new Reference('redis.lock.factory'), 'get']);
}
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->lock = $this->container->get('lock');
}
/**
* {@inheritdoc}
*/
public function testBackendLockRelease(): void {
// Verify that the correct lock backend is being instantiated by the
// factory.
$this->assertInstanceOf(RedisLock::class, $this->lock);
// Verify that a lock that has never been acquired is marked as available.
// @todo Remove this line when #3002640 lands.
// @see https://www.drupal.org/project/drupal/issues/3002640
$this->assertTrue($this->lock->lockMayBeAvailable('lock_a'));
parent::testBackendLockRelease();
}
}
