ILIAS  release_7 Revision v7.30-3-g800a261c036
StateTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2020 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
5use PHPUnit\Framework\TestCase;
7
8class StateTest extends TestCase
9{
10 public function testGetNullValue()
11 {
12 $state = new State();
13 $this->assertNull($state->getValueFor('invalid_key'));
14 return $state;
15 }
16
20 public function testValue(State $state)
21 {
22 $key = 'key';
23 $value = 'value';
24 $state = $state->withValueFor($key, $value);
25 $this->assertEquals($value, $state->getValueFor($key));
26 return $state;
27 }
28
32 public function testSerialize(State $state)
33 {
34 $expected = json_encode(['key' => 'value']);
35 $this->assertEquals($expected, $state->serialize());
36 }
37
41 public function testRemoveValue(State $state)
42 {
43 $state = $state->withValueFor('keep', 'this');
44 $state = $state->withoutKey('key');
45 $expected = json_encode(['keep' => 'this']);
46 $this->assertEquals($expected, $state->serialize());
47 }
48}
An exception for terminatinating execution or to throw for unit testing.
Keeps the state of a view in a simple stringly type key-value store.
Definition: State.php:10
withValueFor(string $key, string $value)
Set a value for a key of the state.
Definition: State.php:20
withoutKey(string $key)
Remove the key-value-pair.
Definition: State.php:30
serialize()
Get the key-value store as string.
Definition: State.php:51
getValueFor(string $key)
Get the value for the given key.
Definition: State.php:40
testValue(State $state)
@depends testGetNullValue
Definition: StateTest.php:20
testRemoveValue(State $state)
@depends testValue
Definition: StateTest.php:41
testGetNullValue()
Definition: StateTest.php:10
testSerialize(State $state)
@depends testValue
Definition: StateTest.php:32