You are here

class LockBackendAbstractTest in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Lock/LockBackendAbstractTest.php \Drupal\Tests\Core\Lock\LockBackendAbstractTest
  2. 9 core/tests/Drupal/Tests/Core/Lock/LockBackendAbstractTest.php \Drupal\Tests\Core\Lock\LockBackendAbstractTest

@coversDefaultClass \Drupal\Tests\Core\Lock\LockBackendAbstractTest @group Lock

Hierarchy

Expanded class hierarchy of LockBackendAbstractTest

File

core/tests/Drupal/Tests/Core/Lock/LockBackendAbstractTest.php, line 11

Namespace

Drupal\Tests\Core\Lock
View source
class LockBackendAbstractTest extends UnitTestCase {

  /**
   * The Mocked LockBackendAbstract object.
   *
   * @var \Drupal\Core\Lock\LockBackendAbstract|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $lock;
  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'))
      ->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));
  }

  /**
   * 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());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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.
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
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::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUpBeforeClass public static function