ILIAS  trunk Revision v11.0_alpha-2645-g16283d3b3f8
StateTest.php
Go to the documentation of this file.
1 <?php
2 
21 
22 class StateTest extends TestCase
23 {
24  public function testGetNullValue(): State
25  {
26  $state = new State();
27  $this->assertNull($state->getValueFor('invalid_key'));
28  return $state;
29  }
30 
31  #[\PHPUnit\Framework\Attributes\Depends('testGetNullValue')]
32  public function testValue(State $state): State
33  {
34  $key = 'key';
35  $value = 'value';
36  $state = $state->withValueFor($key, $value);
37  $this->assertEquals($value, $state->getValueFor($key));
38  return $state;
39  }
40 
41  #[\PHPUnit\Framework\Attributes\Depends('testValue')]
42  public function testSerialize(State $state): void
43  {
44  $expected = json_encode(['key' => 'value'], JSON_THROW_ON_ERROR);
45  $this->assertEquals($expected, $state->serialize());
46  }
47 
48  #[\PHPUnit\Framework\Attributes\Depends('testValue')]
49  public function testRemoveValue(State $state): void
50  {
51  $state = $state->withValueFor('keep', 'this');
52  $state = $state->withoutKey('key');
53  $expected = json_encode(['keep' => 'this'], JSON_THROW_ON_ERROR);
54  $this->assertEquals($expected, $state->serialize());
55  }
56 }
withValueFor(string $key, string $value)
Set a value for a key of the state.
Definition: State.php:36
getValueFor(string $key)
Get the value for the given key.
Definition: State.php:56
testValue(State $state)
Definition: StateTest.php:32
testGetNullValue()
Definition: StateTest.php:24
testSerialize(State $state)
Definition: StateTest.php:42
serialize()
Get the key-value store as string.
Definition: State.php:67
testRemoveValue(State $state)
Definition: StateTest.php:49
withoutKey(string $key)
Remove the key-value-pair.
Definition: State.php:46