19 declare(strict_types=1);
34 #[\PHPUnit\Framework\Attributes\DataProvider('metricProvider')] 35 public function testConstructMetric(
string $stability,
string $type, $value,
string $description,
bool $success): void
38 $this->expectException(\InvalidArgumentException::class);
40 $metric =
new Metrics\Metric($stability, $type, $value, $description);
41 $this->assertEquals($stability, $metric->getStability());
42 $this->assertEquals($type, $metric->getType());
43 $this->assertEquals($value, $metric->getValue());
44 $this->assertEquals($description, $metric->getDescription());
64 "invalid_stability" => [
"no_stability", $bool,
true,
"",
false],
65 "invalid_type" => [$config,
"no_type",
true,
"",
false],
67 "bool" => [$config, $bool,
true,
"A boolean",
true],
68 "counter" => [$stable, $counter, 23,
"A counter",
true],
69 "gauge1" => [$volatile, $gauge, 42,
"A gauge",
true],
70 "gauge2" => [$volatile, $gauge, 13.37,
"A gauge",
true],
71 "timestamp" => [$config,
$timestamp, new \DateTimeImmutable(),
"A timestamp",
true],
72 "text" => [$stable, $text,
"some text",
"A text",
true],
73 "collection" => [$volatile, $collection, [
"other" => $other_metric],
"A collection",
true],
75 "no_bool1" => [$config, $bool, 1,
"",
false],
76 "no_bool2" => [$config, $bool,
"foo",
"",
false],
77 "no_bool3" => [$config, $bool, new \DateTimeImmutable(),
"",
false],
78 "no_bool4" => [$config, $bool, [],
"",
false],
80 "no_counter1" => [$stable, $counter,
false,
"",
false],
81 "no_counter2" => [$stable, $counter, 3.1,
"",
false],
82 "no_counter3" => [$stable, $counter,
"foo",
"",
false],
83 "no_counter4" => [$stable, $counter, new \DateTimeImmutable(),
"",
false],
84 "no_counter5" => [$stable, $counter, [],
"",
false],
86 "no_gauge1" => [$volatile, $gauge,
true,
"",
false],
87 "no_gauge2" => [$volatile, $gauge,
"foo",
"",
false],
88 "no_gauge3" => [$volatile, $gauge, new \DateTimeImmutable(),
"",
false],
89 "no_gauge4" => [$volatile, $gauge, [],
"",
false],
91 "no_timestamp1" => [$config,
$timestamp,
false,
"",
false],
92 "no_timestamp2" => [$config,
$timestamp, 1,
"",
false],
93 "no_timestamp3" => [$config,
$timestamp,
"foo",
"",
false],
94 "no_timestamp4" => [$config,
$timestamp, [],
"",
false],
96 "no_text1" => [$stable, $text,
true,
"",
false],
97 "no_text2" => [$stable, $text, 1,
"",
false],
98 "no_text3" => [$stable, $text, new \DateTimeImmutable(),
"",
false],
99 "no_text4" => [$stable, $text, [],
"",
false],
101 "no_collection1" => [$volatile, $collection,
false,
"",
false],
102 "no_collection2" => [$volatile, $collection, 1,
"",
false],
103 "no_collection3" => [$volatile, $collection, new \DateTimeImmutable(),
"",
false],
104 "no_collection4" => [$volatile, $collection,
"foo",
"",
false],
105 "no_collection5" => [$volatile, $collection, [
"a"],
"",
false],
107 "mixed_collection" => [$mixed, $collection, [],
"",
true],
108 "no_mixed_bool" => [$mixed, $bool,
true,
"",
false],
109 "no_mixed_counter" => [$mixed, $counter, 1,
"",
false],
110 "no_mixed_gauge" => [$mixed, $gauge, 1.0,
"",
false],
111 "no_mixed_timestamp" => [$mixed,
$timestamp, new \DateTimeImmutable(),
"",
false],
112 "no_mixed_text" => [$mixed, $text,
"",
"",
false],
116 #[\PHPUnit\Framework\Attributes\DataProvider('typedMetricsProvider')] 119 $this->assertEquals($expected, $metric->toYAML());
125 "bool_true" => [
new M(M::STABILITY_STABLE, M::TYPE_BOOL,
true),
"true"],
126 "bool_false" => [
new M(M::STABILITY_STABLE, M::TYPE_BOOL,
false),
"false"],
127 "counter_0" => [
new M(M::STABILITY_STABLE, M::TYPE_COUNTER, 0),
"0"],
128 "counter_1337" => [
new M(M::STABILITY_STABLE, M::TYPE_COUNTER, 1337),
"1337"],
129 "gauge_23" => [
new M(M::STABILITY_STABLE, M::TYPE_GAUGE, 23),
"23"],
130 "gauge_42_0" => [
new M(M::STABILITY_STABLE, M::TYPE_GAUGE, 42.0),
"42.000"],
131 "gauge_42_001" => [
new M(M::STABILITY_STABLE, M::TYPE_GAUGE, 42.001),
"42.001"],
132 "timestamp" => [
new M(M::STABILITY_STABLE, M::TYPE_TIMESTAMP,
new \
DateTimeImmutable(
"1985-05-04T13:37:00+01:00")),
"1985-05-04T13:37:00+0100"],
133 "text" => [
new M(M::STABILITY_STABLE, M::TYPE_TEXT,
"some text"),
"some text"],
134 "text_with_nl" => [
new M(M::STABILITY_STABLE, M::TYPE_TEXT,
"some\ntext"),
">\nsome\ntext"],
140 $metrics =
new M(M::STABILITY_STABLE, M::TYPE_COLLECTION, [
141 "a" =>
new M(M::STABILITY_STABLE, M::TYPE_COLLECTION, [
142 "h" =>
new M(M::STABILITY_STABLE, M::TYPE_TEXT,
"a_h"),
143 "c" =>
new M(M::STABILITY_STABLE, M::TYPE_COLLECTION, [
144 "d" =>
new M(M::STABILITY_STABLE, M::TYPE_COLLECTION, [
145 "e" =>
new M(M::STABILITY_STABLE, M::TYPE_TEXT,
"a_c_d_e"),
146 "f" =>
new M(M::STABILITY_STABLE, M::TYPE_TEXT,
"a_c_d_f")
148 "g" =>
new M(M::STABILITY_STABLE, M::TYPE_TEXT,
"a_c_g")
150 "i" =>
new M(M::STABILITY_STABLE, M::TYPE_TEXT,
"a_i\na_i")
152 "b" =>
new M(M::STABILITY_STABLE, M::TYPE_COLLECTION, [
153 "j" =>
new M(M::STABILITY_STABLE, M::TYPE_TEXT,
"b_j")
155 "k" =>
new M(M::STABILITY_STABLE, M::TYPE_TEXT,
"k")
158 $expected = <<<METRIC
174 $this->assertEquals($expected, $metrics->toYAML());
179 $metrics =
new M(M::STABILITY_MIXED, M::TYPE_COLLECTION, [
180 "a" =>
new M(M::STABILITY_MIXED, M::TYPE_COLLECTION, [
181 "h" =>
new M(M::STABILITY_CONFIG, M::TYPE_TEXT,
"a_h"),
182 "c" =>
new M(M::STABILITY_MIXED, M::TYPE_COLLECTION, [
183 "d" =>
new M(M::STABILITY_MIXED, M::TYPE_COLLECTION, [
184 "e" =>
new M(M::STABILITY_STABLE, M::TYPE_TEXT,
"a_c_d_e"),
185 "f" =>
new M(M::STABILITY_VOLATILE, M::TYPE_TEXT,
"a_c_d_f")
187 "g" =>
new M(M::STABILITY_CONFIG, M::TYPE_TEXT,
"a_c_g")
189 "i" =>
new M(M::STABILITY_STABLE, M::TYPE_TEXT,
"a_i\na_i")
191 "b" =>
new M(M::STABILITY_MIXED, M::TYPE_COLLECTION, [
192 "j" =>
new M(M::STABILITY_VOLATILE, M::TYPE_TEXT,
"b_j")
194 "k" =>
new M(M::STABILITY_CONFIG, M::TYPE_TEXT,
"k")
197 $expected_extracted =
new M(M::STABILITY_CONFIG, M::TYPE_COLLECTION, [
198 "a" =>
new M(M::STABILITY_CONFIG, M::TYPE_COLLECTION, [
199 "h" =>
new M(M::STABILITY_CONFIG, M::TYPE_TEXT,
"a_h"),
200 "c" =>
new M(M::STABILITY_CONFIG, M::TYPE_COLLECTION, [
201 "g" =>
new M(M::STABILITY_CONFIG, M::TYPE_TEXT,
"a_c_g")
204 "k" =>
new M(M::STABILITY_CONFIG, M::TYPE_TEXT,
"k")
206 $expected_rest =
new M(M::STABILITY_MIXED, M::TYPE_COLLECTION, [
207 "a" =>
new M(M::STABILITY_MIXED, M::TYPE_COLLECTION, [
208 "c" =>
new M(M::STABILITY_MIXED, M::TYPE_COLLECTION, [
209 "d" =>
new M(M::STABILITY_MIXED, M::TYPE_COLLECTION, [
210 "e" =>
new M(M::STABILITY_STABLE, M::TYPE_TEXT,
"a_c_d_e"),
211 "f" =>
new M(M::STABILITY_VOLATILE, M::TYPE_TEXT,
"a_c_d_f")
214 "i" =>
new M(M::STABILITY_STABLE, M::TYPE_TEXT,
"a_i\na_i")
216 "b" =>
new M(M::STABILITY_MIXED, M::TYPE_COLLECTION, [
217 "j" =>
new M(M::STABILITY_VOLATILE, M::TYPE_TEXT,
"b_j")
221 list($extracted, $rest) = $metrics->extractByStability(M::STABILITY_CONFIG);
223 $this->assertEquals($expected_extracted, $extracted);
224 $this->assertEquals($expected_rest, $rest);
227 #[\PHPUnit\Framework\Attributes\DataProvider('typedMetricsProvider')] 230 $this->assertEquals($expected, $metric->toArray());
235 $metric =
new M(M::STABILITY_STABLE, M::TYPE_COLLECTION, [
236 "bool_true" =>
new M(M::STABILITY_STABLE, M::TYPE_BOOL,
true)
239 $this->assertEquals([
"bool_true" =>
"true"], $metric->toArray());
244 $metric =
new M(M::STABILITY_STABLE, M::TYPE_COLLECTION, [
245 "db" =>
new M(M::STABILITY_STABLE, M::TYPE_COLLECTION, [
246 "bool_true" =>
new M(M::STABILITY_STABLE, M::TYPE_BOOL,
true)
250 $this->assertEquals([
"db" => [
"bool_true" =>
"true"]], $metric->toArray());
255 $factory = $this->createMock(Factory::class);
256 $listing_f =
new LF();
263 $legacy = $legacy_f->content(
"<pre>string</pre>");
266 ->expects($this->once())
268 ->willReturn($legacy);
271 ->expects($this->once())
273 ->willReturn($legacy_f)
277 ->expects($this->exactly(2))
279 ->willReturn($panel_f)
282 $metric =
new M(M::STABILITY_STABLE, M::TYPE_TEXT,
"string",
"");
284 $result = $metric->toUIReport($factory,
"Status");
286 $this->assertInstanceOf(Report::class, $result);
testConstructMetric(string $stability, string $type, $value, string $description, bool $success)
Interface Observer Contains several chained tasks and infos about them.
const TYPE_BOOL
The type of the metric tells what to expect of the values.
testToYAML(M $metric, string $expected)
A metric is something we can measure about the system.
testToArrayWithFlatValues(M $metric, string $expected)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
foreach($mandatory_scripts as $file) $timestamp
static typedMetricsProvider()
const STABILITY_CONFIG
The stability of a metric tells how often we expect changes in the metric.