class LockBackendAbstractTest in Drupal 8
Same name and namespace in other branches
- 9 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
@coversDefaultClass \Drupal\Tests\Core\Lock\LockBackendAbstractTest @group Lock
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\Core\Lock\LockBackendAbstractTest
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;
protected function setUp() {
$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'))
->will($this
->returnValue(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'))
->will($this
->returnValue(FALSE));
$this
->assertTrue($this->lock
->wait('test_name', 1));
}
/**
* Test the getLockId() method.
*/
public function testGetLockId() {
$lock_id = $this->lock
->getLockId();
$this
->assertIsString($lock_id);
// Example lock ID would be '7213141505232b6ee2cb967.27683891'.
$this
->assertRegExp('/[\\da-f]+\\.\\d+/', $lock_id);
// Test the same lock ID is returned a second time.
$this
->assertSame($lock_id, $this->lock
->getLockId());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LockBackendAbstractTest:: |
protected | property | The Mocked LockBackendAbstract object. | |
LockBackendAbstractTest:: |
protected | function |
Overrides UnitTestCase:: |
|
LockBackendAbstractTest:: |
public | function | Test the getLockId() method. | |
LockBackendAbstractTest:: |
public | function | Tests the wait() method when lockMayBeAvailable() returns TRUE. | |
LockBackendAbstractTest:: |
public | function | Tests the wait() method when lockMayBeAvailable() returns FALSE. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |