ILIAS  release_7 Revision v7.30-3-g800a261c036
ArrayStorageTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2019 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
6
9use PHPUnit\Framework\TestCase;
10
11class ArrayStorageTest extends TestCase
12{
13 public function setUp() : void
14 {
15 $this->storage = new Metrics\ArrayStorage;
16 }
17
18 public function testBasicStorage()
19 {
20 $m1 = new M(M::STABILITY_CONFIG, M::TYPE_BOOL, true, "desc1");
21 $m2 = new M(M::STABILITY_CONFIG, M::TYPE_BOOL, true, "desc2");
22
23 $this->storage->store("m1", $m1);
24 $this->storage->store("m2", $m2);
25
26 $expected = [
27 "m1" => $m1,
28 "m2" => $m2
29 ];
30
31 $this->assertEquals($expected, $this->storage->get());
32 }
33
34 public function testOverwrites()
35 {
36 $m1 = new M(M::STABILITY_CONFIG, M::TYPE_BOOL, true, "desc1");
37 $m2 = new M(M::STABILITY_CONFIG, M::TYPE_BOOL, true, "desc2");
38
39 $this->storage->store("m1", $m1);
40 $this->storage->store("m1", $m2);
41
42 $expected = [
43 "m1" => $m2
44 ];
45
46 $this->assertEquals($expected, $this->storage->get());
47 }
48
49 public function testNesting()
50 {
51 $m1 = new M(M::STABILITY_CONFIG, M::TYPE_BOOL, true, "desc1");
52
53 $this->storage->store("a.b.c", $m1);
54
55 $expected = [
56 "a" => [
57 "b" => [
58 "c" => $m1
59 ]
60 ]
61 ];
62
63 $this->assertEquals($expected, $this->storage->get());
64 }
65
66 public function testAsMetric()
67 {
68 $this->storage->store("a", new M(M::STABILITY_STABLE, M::TYPE_COUNTER, 0));
69 $this->storage->store("b.c", new M(M::STABILITY_VOLATILE, M::TYPE_BOOL, true));
70
71 $expected = new M(
72 M::STABILITY_MIXED,
73 M::TYPE_COLLECTION,
74 [
75 "a" => new M(M::STABILITY_STABLE, M::TYPE_COUNTER, 0),
76 "b" => new M(M::STABILITY_MIXED, M::TYPE_COLLECTION, [
77 "c" => new M(M::STABILITY_VOLATILE, M::TYPE_BOOL, true)
78 ])
79 ]
80 );
81
82 $this->assertEquals($expected, $this->storage->asMetric());
83 }
84}
An exception for terminatinating execution or to throw for unit testing.
A metric is something we can measure about the system.
Definition: Metric.php:18