class LockBackendAbstractTest
Tests Drupal\Core\Lock\LockBackendAbstract.
Attributes
#[CoversClass(LockBackendAbstract::class)]
#[Group('Lock')]
#[Medium]
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\Core\Lock\LockBackendAbstractTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of LockBackendAbstractTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Lock/ LockBackendAbstractTest.php, line 17
Namespace
Drupal\Tests\Core\LockView source
class LockBackendAbstractTest extends UnitTestCase {
/**
* The Mocked LockBackendAbstract object.
*/
protected LockBackendAbstract&MockObject $lock;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->lock = $this->getMockBuilder(StubLockBackendAbstract::class)
->onlyMethods([
'lockMayBeAvailable',
])
->getMock();
}
/**
* Tests the wait() method when lockMayBeAvailable() returns TRUE.
*/
public function testWaitFalse() : void {
$this->lock
->expects($this->any())
->method('lockMayBeAvailable')
->with($this->equalTo('test_name'))
->willReturn(TRUE);
$this->assertFalse($this->lock
->wait('test_name'));
}
/**
* Tests the wait() method when lockMayBeAvailable() returns FALSE.
*
* Waiting could take 1 second so we need to extend the possible runtime.
*/
public function testWaitTrue() : void {
$this->lock
->expects($this->any())
->method('lockMayBeAvailable')
->with($this->equalTo('test_name'))
->willReturn(FALSE);
$this->assertTrue($this->lock
->wait('test_name', 1));
}
/**
* Tests the getLockId() method.
*/
public function testGetLockId() : void {
$lock_id = $this->lock
->getLockId();
$this->assertIsString($lock_id);
// Example lock ID would be '7213141505232b6ee2cb967.27683891'.
$this->assertMatchesRegularExpression('/[\\da-f]+\\.\\d+/', $lock_id);
// Test the same lock ID is returned a second time.
$this->assertSame($lock_id, $this->lock
->getLockId());
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
|---|---|---|---|---|
| ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
| ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
| ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
| LockBackendAbstractTest::$lock | protected | property | The Mocked LockBackendAbstract object. | |
| LockBackendAbstractTest::setUp | protected | function | Overrides UnitTestCase::setUp | |
| LockBackendAbstractTest::testGetLockId | public | function | Tests the getLockId() method. | |
| LockBackendAbstractTest::testWaitFalse | public | function | Tests the wait() method when lockMayBeAvailable() returns TRUE. | |
| LockBackendAbstractTest::testWaitTrue | public | function | Tests the wait() method when lockMayBeAvailable() returns FALSE. | |
| 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. | |
| UnitTestCase::$root | protected | property | The app root. | |
| UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |
| UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |
| UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |
| UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |
| UnitTestCase::setDebugDumpHandler | public static | function | Registers the dumper CLI handler when the DebugDump extension is enabled. | |
| UnitTestCase::setupMockIterator | protected | function | Set up a traversable class mock to return specific items when iterated. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.