function LinearHistoryTest::testGetParents

Same name in other branches
  1. 10 core/tests/Drupal/Tests/Core/Config/Checkpoint/LinearHistoryTest.php \Drupal\Tests\Core\Config\Checkpoint\LinearHistoryTest::testGetParents()

@covers ::getParents

File

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

Class

LinearHistoryTest
@coversDefaultClass \Drupal\Core\Config\Checkpoint\LinearHistory @group Config

Namespace

Drupal\Tests\Core\Config\Checkpoint

Code

public function testGetParents() : void {
    $state = $this->prophesize(StateInterface::class);
    $test_data = [
        'hash1' => new Checkpoint('hash1', 'One', 1701539510, NULL),
        'hash2' => new Checkpoint('hash2', 'Two', 1701539520, 'hash1'),
        'hash3' => new Checkpoint('hash3', 'Three', 1701539530, 'hash2'),
    ];
    $state->get(self::CHECKPOINT_KEY, [])
        ->willReturn($test_data);
    $time = $this->prophesize(TimeInterface::class);
    $checkpoints = new LinearHistory($state->reveal(), $time->reveal());
    $this->assertSame([
        'hash2' => $test_data['hash2'],
        'hash1' => $test_data['hash1'],
    ], iterator_to_array($checkpoints->getParents('hash3')));
    $this->assertSame([
        'hash1' => $test_data['hash1'],
    ], iterator_to_array($checkpoints->getParents('hash2')));
    $this->assertSame([], iterator_to_array($checkpoints->getParents('hash1')));
}

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