function LinearHistoryTest::testAddException

@covers ::add

File

core/tests/Drupal/Tests/Core/Config/Checkpoint/LinearHistoryTest.php, line 79

Class

LinearHistoryTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Config%21Checkpoint%21LinearHistory.php/class/LinearHistory/11.x" title="A chronological list of Checkpoint objects." class="local">\Drupal\Core\Config\Checkpoint\LinearHistory</a> @group Config

Namespace

Drupal\Tests\Core\Config\Checkpoint

Code

public function testAddException() : void {
    $state = $this->prophesize(StateInterface::class);
    $state->get(self::CHECKPOINT_KEY, [])
        ->willReturn([]);
    $state->set(self::CHECKPOINT_KEY, Argument::any())
        ->willReturn(NULL);
    $time = $this->prophesize(TimeInterface::class);
    $time->getCurrentTime()
        ->willReturn(1701539520, 1701539994);
    $checkpoints = new LinearHistory($state->reveal(), $time->reveal());
    $checkpoints->add('hash1', 'Label');
    // Add another checkpoint with the same ID and an exception should be
    // triggered.
    $this->expectException(CheckpointExistsException::class);
    $this->expectExceptionMessage('Cannot create a checkpoint with the ID "hash1" as it already exists');
    $checkpoints->add('hash1', 'Label');
}

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