ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ArrayStorageTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25use PHPUnit\Framework\TestCase;
26
27class ArrayStorageTest extends TestCase
28{
30
31 public function setUp(): void
32 {
33 $this->storage = new Metrics\ArrayStorage();
34 }
35
36 public function testBasicStorage(): void
37 {
38 $m1 = new M(M::STABILITY_CONFIG, M::TYPE_BOOL, true, "desc1");
39 $m2 = new M(M::STABILITY_CONFIG, M::TYPE_BOOL, true, "desc2");
40
41 $this->storage->store("m1", $m1);
42 $this->storage->store("m2", $m2);
43
44 $expected = [
45 "m1" => $m1,
46 "m2" => $m2
47 ];
48
49 $this->assertEquals($expected, $this->storage->get());
50 }
51
52 public function testOverwrites(): void
53 {
54 $m1 = new M(M::STABILITY_CONFIG, M::TYPE_BOOL, true, "desc1");
55 $m2 = new M(M::STABILITY_CONFIG, M::TYPE_BOOL, true, "desc2");
56
57 $this->storage->store("m1", $m1);
58 $this->storage->store("m1", $m2);
59
60 $expected = [
61 "m1" => $m2
62 ];
63
64 $this->assertEquals($expected, $this->storage->get());
65 }
66
67 public function testNesting(): void
68 {
69 $m1 = new M(M::STABILITY_CONFIG, M::TYPE_BOOL, true, "desc1");
70
71 $this->storage->store("a.b.c", $m1);
72
73 $expected = [
74 "a" => [
75 "b" => [
76 "c" => $m1
77 ]
78 ]
79 ];
80
81 $this->assertEquals($expected, $this->storage->get());
82 }
83
84 public function testAsMetric(): void
85 {
86 $this->storage->store("a", new M(M::STABILITY_STABLE, M::TYPE_COUNTER, 0));
87 $this->storage->store("b.c", new M(M::STABILITY_VOLATILE, M::TYPE_BOOL, true));
88
89 $expected = new M(
90 M::STABILITY_MIXED,
91 M::TYPE_COLLECTION,
92 [
93 "a" => new M(M::STABILITY_STABLE, M::TYPE_COUNTER, 0),
94 "b" => new M(M::STABILITY_MIXED, M::TYPE_COLLECTION, [
95 "c" => new M(M::STABILITY_VOLATILE, M::TYPE_BOOL, true)
96 ])
97 ]
98 );
99
100 $this->assertEquals($expected, $this->storage->asMetric());
101 }
102}
A metric is something we can measure about the system.
Definition: Metric.php:34