3 namespace Drupal\Tests\Core\Lock;
5 use Drupal\Tests\UnitTestCase;
8 * @coversDefaultClass \Drupal\Tests\Core\Lock\LockBackendAbstractTest
11 class LockBackendAbstractTest extends UnitTestCase {
14 * The Mocked LockBackendAbstract object.
16 * @var \Drupal\Core\Lock\LockBackendAbstract|\PHPUnit_Framework_MockObject_MockObject
20 protected function setUp() {
21 $this->lock = $this->getMockForAbstractClass('Drupal\Core\Lock\LockBackendAbstract');
25 * Tests the wait() method when lockMayBeAvailable() returns TRUE.
27 public function testWaitFalse() {
28 $this->lock->expects($this->any())
29 ->method('lockMayBeAvailable')
30 ->with($this->equalTo('test_name'))
31 ->will($this->returnValue(TRUE));
33 $this->assertFalse($this->lock->wait('test_name'));
37 * Tests the wait() method when lockMayBeAvailable() returns FALSE.
39 * Waiting could take 1 second so we need to extend the possible runtime.
42 public function testWaitTrue() {
43 $this->lock->expects($this->any())
44 ->method('lockMayBeAvailable')
45 ->with($this->equalTo('test_name'))
46 ->will($this->returnValue(FALSE));
48 $this->assertTrue($this->lock->wait('test_name', 1));
52 * Test the getLockId() method.
54 public function testGetLockId() {
55 $lock_id = $this->lock->getLockId();
56 $this->assertInternalType('string', $lock_id);
57 // Example lock ID would be '7213141505232b6ee2cb967.27683891'.
58 $this->assertRegExp('/[\da-f]+\.\d+/', $lock_id);
59 // Test the same lock ID is returned a second time.
60 $this->assertSame($lock_id, $this->lock->getLockId());