RedisLockFunctionalTest.php in Redis 8
File
tests/src/Functional/Lock/RedisLockFunctionalTest.php
View source
<?php
namespace Drupal\Tests\redis\Functional\Lock;
use Drupal\Component\Utility\OpCodeCache;
use Drupal\Core\Database\Database;
use Drupal\Core\Site\Settings;
use Drupal\Tests\system\Functional\Lock\LockFunctionalTest;
use Drupal\Tests\redis\Traits\RedisTestInterfaceTrait;
class RedisLockFunctionalTest extends LockFunctionalTest {
use RedisTestInterfaceTrait;
public static $modules = [
'redis',
];
protected function setUp() {
parent::setUp();
$filename = $this->siteDirectory . '/settings.php';
chmod($filename, 0666);
$contents = file_get_contents($filename);
$redis_interface = self::getRedisInterfaceEnv();
$module_path = drupal_get_path('module', 'redis');
$contents .= "\n\n" . "\$settings['container_yamls'][] = '{$module_path}/example.services.yml';";
$contents .= "\n\n" . '$settings["redis.connection"]["interface"] = \'' . $redis_interface . '\';';
file_put_contents($filename, $contents);
$settings = Settings::getAll();
$settings['container_yamls'][] = $module_path . '/example.services.yml';
$settings['redis.connection']['interface'] = $redis_interface;
new Settings($settings);
OpCodeCache::invalidate(DRUPAL_ROOT . '/' . $filename);
$this
->rebuildContainer();
$db_schema = Database::getConnection()
->schema();
$db_schema
->dropTable('semaphore');
}
public function testLockAcquire() {
$redis_interface = self::getRedisInterfaceEnv();
$lock = $this->container
->get('lock');
$this
->assertInstanceOf('\\Drupal\\redis\\Lock\\' . $redis_interface, $lock);
$this
->assertTrue($lock
->lockMayBeAvailable('system_test_lock_acquire'));
parent::testLockAcquire();
}
public function testPersistentLock() {
$redis_interface = self::getRedisInterfaceEnv();
$persistent_lock = $this->container
->get('lock.persistent');
$this
->assertInstanceOf('\\Drupal\\redis\\PersistentLock\\' . $redis_interface, $persistent_lock);
$this
->assertTrue($persistent_lock
->lockMayBeAvailable('lock1'));
parent::testPersistentLock();
}
}