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