class LockBackendAbstractTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/Tests/Core/Lock/LockBackendAbstractTest.php \Drupal\Tests\Core\Lock\LockBackendAbstractTest
- 10 core/tests/Drupal/Tests/Core/Lock/LockBackendAbstractTest.php \Drupal\Tests\Core\Lock\LockBackendAbstractTest
- 8.9.x core/tests/Drupal/Tests/Core/Lock/LockBackendAbstractTest.php \Drupal\Tests\Core\Lock\LockBackendAbstractTest
@coversDefaultClass
@group Lock" class="local">\Drupal\Tests\Core\Lock\LockBackendAbstractTest
@group Lock
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait 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 11
Namespace
Drupal\Tests\Core\LockView source
class LockBackendAbstractTest extends UnitTestCase {
/**
* The Mocked LockBackendAbstract object.
*
* @var \Drupal\Core\Lock\LockBackendAbstract|\PHPUnit\Framework\MockObject\MockObject
*/
protected $lock;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
$this->lock = $this->getMockForAbstractClass('Drupal\\Core\\Lock\\LockBackendAbstract');
}
/**
* Tests the wait() method when lockMayBeAvailable() returns TRUE.
*/
public function testWaitFalse() {
$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.
* @medium
*/
public function testWaitTrue() {
$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() {
$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());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.