function SharedTempStoreTest::testDeleteIfOwner

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/TempStore/SharedTempStoreTest.php \Drupal\Tests\Core\TempStore\SharedTempStoreTest::testDeleteIfOwner()
  2. 8.9.x core/modules/user/tests/src/Unit/SharedTempStoreTest.php \Drupal\Tests\user\Unit\SharedTempStoreTest::testDeleteIfOwner()
  3. 8.9.x core/tests/Drupal/Tests/Core/TempStore/SharedTempStoreTest.php \Drupal\Tests\Core\TempStore\SharedTempStoreTest::testDeleteIfOwner()
  4. 11.x core/tests/Drupal/Tests/Core/TempStore/SharedTempStoreTest.php \Drupal\Tests\Core\TempStore\SharedTempStoreTest::testDeleteIfOwner()

Tests the deleteIfOwner() method.

@covers ::deleteIfOwner

File

core/tests/Drupal/Tests/Core/TempStore/SharedTempStoreTest.php, line 324

Class

SharedTempStoreTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21TempStore%21SharedTempStore.php/class/SharedTempStore/10" title="Stores and retrieves temporary data for a given owner." class="local">\Drupal\Core\TempStore\SharedTempStore</a> @group TempStore

Namespace

Drupal\Tests\Core\TempStore

Code

public function testDeleteIfOwner() {
    $this->lock
        ->expects($this->once())
        ->method('acquire')
        ->with('test_2')
        ->willReturn(TRUE);
    $calls = [
        'test_1',
        'test_2',
        'test_3',
    ];
    $this->keyValue
        ->expects($this->exactly(count($calls)))
        ->method('get')
        ->with($this->callback(function (string $key) use (&$calls) : bool {
        return array_shift($calls) == $key;
    }))
        ->willReturnOnConsecutiveCalls(FALSE, $this->ownObject, $this->otherObject);
    $this->keyValue
        ->expects($this->once())
        ->method('delete')
        ->with('test_2');
    $this->assertTrue($this->tempStore
        ->deleteIfOwner('test_1'));
    $this->assertTrue($this->tempStore
        ->deleteIfOwner('test_2'));
    $this->assertFalse($this->tempStore
        ->deleteIfOwner('test_3'));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.