function PrivateTempStoreTest::testDelete

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

Tests the delete() method.

@covers ::delete

File

core/tests/Drupal/Tests/Core/TempStore/PrivateTempStoreTest.php, line 244

Class

PrivateTempStoreTest
@coversDefaultClass \Drupal\Core\TempStore\PrivateTempStore @group TempStore

Namespace

Drupal\Tests\Core\TempStore

Code

public function testDelete() : void {
    $this->lock
        ->expects($this->once())
        ->method('acquire')
        ->with('1:test_2')
        ->willReturn(TRUE);
    $calls = [
        '1:test_1',
        '1:test_2',
        '1: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('1:test_2');
    $this->assertTrue($this->tempStore
        ->delete('test_1'));
    $this->assertTrue($this->tempStore
        ->delete('test_2'));
    $this->assertFalse($this->tempStore
        ->delete('test_3'));
}

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