class LockTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Lock/LockTest.php \Drupal\KernelTests\Core\Lock\LockTest
- 10 core/tests/Drupal/KernelTests/Core/Lock/LockTest.php \Drupal\KernelTests\Core\Lock\LockTest
- 9 core/tests/Drupal/KernelTests/Core/Lock/LockTest.php \Drupal\KernelTests\Core\Lock\LockTest
- 8.9.x core/tests/Drupal/KernelTests/Core/Lock/LockTest.php \Drupal\KernelTests\Core\Lock\LockTest
Tests the Database lock backend.
Attributes
#[Group('Lock')]
#[RunTestsInSeparateProcesses]
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\Tests\BrowserHtmlDebugTrait, \Drupal\Tests\HttpKernelUiHelperTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\KernelTests\Core\Lock\LockTest extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of LockTest
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Lock/ LockTest.php, line 16
Namespace
Drupal\KernelTests\Core\LockView source
class LockTest extends KernelTestBase {
/**
* Database lock backend to test.
*
* @var \Drupal\Core\Lock\DatabaseLockBackend
*/
protected $lock;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->lock = new DatabaseLockBackend($this->container
->get('database'));
}
/**
* Tests backend release functionality.
*/
public function testBackendLockRelease() : void {
$success = $this->lock
->acquire('lock_a');
$this->assertTrue($success, 'Could acquire first lock.');
// This function is not part of the backend, but the default database
// backend implement it, we can here use it safely.
$is_free = $this->lock
->lockMayBeAvailable('lock_a');
$this->assertFalse($is_free, 'First lock is unavailable.');
$this->lock
->release('lock_a');
$is_free = $this->lock
->lockMayBeAvailable('lock_a');
$this->assertTrue($is_free, 'First lock has been released.');
$success = $this->lock
->acquire('lock_b');
$this->assertTrue($success, 'Could acquire second lock.');
$success = $this->lock
->acquire('lock_b');
$this->assertTrue($success, 'Could acquire second lock a second time within the same request.');
$this->lock
->release('lock_b');
// Test acquiring and releasing a lock with a long key (over 255 chars).
$long_key = 'long_key:BZoMiSf9IIPULsJ98po18TxJ6T4usd3MZrLE0d3qMgG6iAgDlOi1G3oMap7zI5df84l7LtJBg4bOj6XvpO6vDRmP5h5QbA0Bj9rVFiPIPAIQZ9qFvJqTALiK1OR3GpOkWQ4vgEA4LkY0UfznrWBeuK7IWZfv1um6DLosnVXd1z1cJjvbEUqYGJj92rwHfhYihLm8IO9t3P2gAvEkH5Mhc8GBoiTsIDnP01Te1kxGFHO3RuvJIxPnHmZtSdBggmuVN7x9';
$success = $this->lock
->acquire($long_key);
$this->assertTrue($success, 'Could acquire long key lock.');
// This function is not part of the backend, but the default database
// backend implement it, we can here use it safely.
$is_free = $this->lock
->lockMayBeAvailable($long_key);
$this->assertFalse($is_free, 'Long key lock is unavailable.');
$this->lock
->release($long_key);
$is_free = $this->lock
->lockMayBeAvailable($long_key);
$this->assertTrue($is_free, 'Long key lock has been released.');
}
/**
* Tests backend release functionality.
*/
public function testBackendLockReleaseAll() : void {
$success = $this->lock
->acquire('lock_a');
$this->assertTrue($success, 'Could acquire first lock.');
$success = $this->lock
->acquire('lock_b');
$this->assertTrue($success, 'Could acquire second lock.');
$this->lock
->releaseAll();
$is_free = $this->lock
->lockMayBeAvailable('lock_a');
$this->assertTrue($is_free, 'First lock has been released.');
$is_free = $this->lock
->lockMayBeAvailable('lock_b');
$this->assertTrue($is_free, 'Second lock has been released.');
// Test that the semaphore table having been removed does not cause
// exceptions.
$success = $this->lock
->acquire('lock_a');
$this->assertTrue($success, 'Could re-acquire first lock.');
Database::getConnection()->schema()
->dropTable('semaphore');
$this->lock
->releaseAll();
$is_free = $this->lock
->lockMayBeAvailable('lock_a');
$this->assertTrue($is_free, 'Re-acquired lock has been released.');
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary | Overrides |
|---|---|---|---|---|
| AssertContentTrait::$content | protected | property | The current raw content. | |
| AssertContentTrait::$drupalSettings | protected | property | The drupalSettings value from the current raw $content. | |
| AssertContentTrait::$elements | protected | property | The XML structure parsed from the current raw $content. | |
| AssertContentTrait::$plainTextContent | protected | property | The plain-text content of raw $content (text nodes). | |
| AssertContentTrait::assertField | protected | function | Asserts that a field exists with the given name or ID. | |
| AssertContentTrait::assertFieldByName | protected | function | Asserts that a field exists with the given name and value. | |
| AssertContentTrait::assertFieldByXPath | protected | function | Asserts that a field exists in the current page by the given XPath. | |
| AssertContentTrait::assertFieldsByValue | protected | function | Asserts that a field exists in the current page with a given Xpath result. | |
| AssertContentTrait::assertNoPattern | protected | function | Triggers a pass if the perl regex pattern is not found in raw content. | |
| AssertContentTrait::assertPattern | protected | function | Triggers a pass if the Perl regex pattern is found in the raw content. | |
| AssertContentTrait::assertThemeOutput | protected | function | Asserts themed output. | |
| AssertContentTrait::assertTitle | protected | function | Pass if the page title is the given string. | |
| AssertContentTrait::constructFieldXpath | protected | function | Helper: Constructs an XPath for the given set of attributes and value. | |
| AssertContentTrait::getSelectedItem | protected | function | Get the selected value from a select field. | |
| BrowserHtmlDebugTrait::$htmlOutputBaseUrl | protected | property | The Base URI to use for links to the output files. | |
| BrowserHtmlDebugTrait::$htmlOutputClassName | protected | property | Class name for HTML output logging. | |
| BrowserHtmlDebugTrait::$htmlOutputCounter | protected | property | Counter for HTML output logging. | |
| BrowserHtmlDebugTrait::$htmlOutputCounterStorage | protected | property | Counter storage for HTML output logging. | |
| BrowserHtmlDebugTrait::$htmlOutputDirectory | protected | property | Directory name for HTML output logging. | |
| BrowserHtmlDebugTrait::$htmlOutputEnabled | protected | property | HTML output enabled. | |
| BrowserHtmlDebugTrait::$htmlOutputTestId | protected | property | HTML output test ID. | |
| BrowserHtmlDebugTrait::formatHtmlOutputHeaders | protected | function | Formats HTTP headers as string for HTML output logging. | |
| BrowserHtmlDebugTrait::getHtmlOutputHeaders | protected | function | Returns headers in HTML output format. | 1 |
| BrowserHtmlDebugTrait::getResponseLogHandler | protected | function | Provides a Guzzle middleware handler to log every response received. | |
| BrowserHtmlDebugTrait::getTestMethodCaller | protected | function | Retrieves the current calling line in the class under test. | 1 |
| BrowserHtmlDebugTrait::htmlOutput | protected | function | Logs a HTML output message in a text file. | |
| BrowserHtmlDebugTrait::initBrowserOutputFile | protected | function | Creates the directory to store browser output. | |
| ConfigTestTrait::configImporter | protected | function | Returns a ConfigImporter object to import test configuration. | |
| ConfigTestTrait::copyConfig | protected | function | Copies configuration objects from source storage to target storage. | |
| DrupalTestCaseTrait::$root | protected | property | The Drupal root directory. | |
| ExtensionListTestTrait::getModulePath | protected | function | Gets the path for the specified module. | |
| ExtensionListTestTrait::getThemePath | protected | function | Gets the path for the specified theme. | |
| HttpKernelUiHelperTrait::$mink | protected | property | Mink session manager. | |
| HttpKernelUiHelperTrait::assertSession | public | function | Returns WebAssert object. | |
| HttpKernelUiHelperTrait::buildUrl | protected | function | Builds a URL from a system path or a URL object. | |
| HttpKernelUiHelperTrait::clickLink | protected | function | Follows a link by complete name. | |
| HttpKernelUiHelperTrait::drupalGet | protected | function | Retrieves a Drupal path. | |
| HttpKernelUiHelperTrait::getDefaultDriverInstance | protected | function | Gets an instance of the default Mink driver. | |
| HttpKernelUiHelperTrait::getNodeElementsByXpath | protected | function | Performs an xpath search on the contents of the internal browser. | |
| HttpKernelUiHelperTrait::getSession | public | function | Returns Mink session. | |
| HttpKernelUiHelperTrait::getUrl | protected | function | Gets the current URL from the browser. | |
| HttpKernelUiHelperTrait::initMink | protected | function | Initializes Mink sessions. | |
| KernelTestBase::$classLoader | protected | property | The class loader. | |
| KernelTestBase::$configImporter | protected | property | The configuration importer. | |
| KernelTestBase::$configSchemaCheckerExclusions | protected static | property | An array of config object names that are excluded from schema checking. | 4 |
| KernelTestBase::$container | protected | property | The test container. | |
| KernelTestBase::$databasePrefix | protected | property | The test database prefix. | |
| KernelTestBase::$keyValue | protected | property | The key_value service that must persist between container rebuilds. | |
| KernelTestBase::$modules | protected static | property | Modules to install. | 624 |
| KernelTestBase::$siteDirectory | protected | property | The relative path to the test site directory. | |
| KernelTestBase::$strictConfigSchema | protected | property | Set to TRUE to strict check all configuration saved. | 9 |
| KernelTestBase::$usesSuperUserAccessPolicy | protected | property | Set to TRUE to make user 1 a super user. | 1 |
| KernelTestBase::$vfsRoot | protected | property | The virtual filesystem root directory. | |
| LockTest::$lock | protected | property | Database lock backend to test. | |
| RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
| RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
| RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
| RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
| StorageCopyTrait::replaceStorageContents | protected static | function | Copy the configuration from one storage to another and remove stale items. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.