function StateTest::testGet

Same name and namespace in other branches
  1. main core/tests/Drupal/Tests/Core/State/StateTest.php \Drupal\Tests\Core\State\StateTest::testGet()

Tests both get() & getMultiple() method.

Here checking the key with it proper value. It is also a helper for testGetStaticCache() function.

@legacy-covers ::get @legacy-covers ::getMultiple

File

core/tests/Drupal/Tests/Core/State/StateTest.php, line 92

Class

StateTest
Tests Drupal\Core\State\State.

Namespace

Drupal\Tests\Core\State

Code

public function testGet() : State {
  $values = [
    'existing' => 'the-value',
    'default-value' => 'the-value-2',
  ];
  $this->keyValueStorage
    ->expects($this->once())
    ->method('setMultiple')
    ->with($values);
  $this->state
    ->setMultiple($values);
  $this->assertEquals('the-value', $this->state
    ->get('existing'));
  $this->assertEquals('the-value-2', $this->state
    ->get('default-value', 'default'));
  $this->assertEquals([
    "existing" => "the-value",
  ], $this->state
    ->getMultiple([
    'existing',
  ]));
  $this->assertEquals([
    "default-value" => "the-value-2",
    "default" => NULL,
  ], $this->state
    ->getMultiple([
    'default-value',
    'default',
  ]));
  return $this->state;
}

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