19 declare(strict_types=1);
37 public function testConstructMetric(
string $stability,
string $type, $value,
string $description,
bool $success): void
40 $this->expectException(\InvalidArgumentException::class);
42 $metric =
new Metrics\Metric($stability, $type, $value, $description);
43 $this->assertEquals($stability, $metric->getStability());
44 $this->assertEquals($type, $metric->getType());
45 $this->assertEquals($value, $metric->getValue());
46 $this->assertEquals($description, $metric->getDescription());
66 "invalid_stability" => [
"no_stability", $bool,
true,
"",
false],
67 "invalid_type" => [$config,
"no_type",
true,
"",
false],
69 "bool" => [$config, $bool,
true,
"A boolean",
true],
70 "counter" => [$stable, $counter, 23,
"A counter",
true],
71 "gauge1" => [$volatile, $gauge, 42,
"A gauge",
true],
72 "gauge2" => [$volatile, $gauge, 13.37,
"A gauge",
true],
73 "timestamp" => [$config,
$timestamp, new \DateTimeImmutable(),
"A timestamp",
true],
74 "text" => [$stable, $text,
"some text",
"A text",
true],
75 "collection" => [$volatile, $collection, [
"other" => $other_metric],
"A collection",
true],
77 "no_bool1" => [$config, $bool, 1,
"",
false],
78 "no_bool2" => [$config, $bool,
"foo",
"",
false],
79 "no_bool3" => [$config, $bool, new \DateTimeImmutable(),
"",
false],
80 "no_bool4" => [$config, $bool, [],
"",
false],
82 "no_counter1" => [$stable, $counter,
false,
"",
false],
83 "no_counter2" => [$stable, $counter, 3.1,
"",
false],
84 "no_counter3" => [$stable, $counter,
"foo",
"",
false],
85 "no_counter4" => [$stable, $counter, new \DateTimeImmutable(),
"",
false],
86 "no_counter5" => [$stable, $counter, [],
"",
false],
88 "no_gauge1" => [$volatile, $gauge,
true,
"",
false],
89 "no_gauge2" => [$volatile, $gauge,
"foo",
"",
false],
90 "no_gauge3" => [$volatile, $gauge, new \DateTimeImmutable(),
"",
false],
91 "no_gauge4" => [$volatile, $gauge, [],
"",
false],
93 "no_timestamp1" => [$config,
$timestamp,
false,
"",
false],
94 "no_timestamp2" => [$config,
$timestamp, 1,
"",
false],
95 "no_timestamp3" => [$config,
$timestamp,
"foo",
"",
false],
96 "no_timestamp4" => [$config,
$timestamp, [],
"",
false],
98 "no_text1" => [$stable, $text,
true,
"",
false],
99 "no_text2" => [$stable, $text, 1,
"",
false],
100 "no_text3" => [$stable, $text, new \DateTimeImmutable(),
"",
false],
101 "no_text4" => [$stable, $text, [],
"",
false],
103 "no_collection1" => [$volatile, $collection,
false,
"",
false],
104 "no_collection2" => [$volatile, $collection, 1,
"",
false],
105 "no_collection3" => [$volatile, $collection, new \DateTimeImmutable(),
"",
false],
106 "no_collection4" => [$volatile, $collection,
"foo",
"",
false],
107 "no_collection5" => [$volatile, $collection, [
"a"],
"",
false],
109 "mixed_collection" => [$mixed, $collection, [],
"",
true],
110 "no_mixed_bool" => [$mixed, $bool,
true,
"",
false],
111 "no_mixed_counter" => [$mixed, $counter, 1,
"",
false],
112 "no_mixed_gauge" => [$mixed, $gauge, 1.0,
"",
false],
113 "no_mixed_timestamp" => [$mixed,
$timestamp, new \DateTimeImmutable(),
"",
false],
114 "no_mixed_text" => [$mixed, $text,
"",
"",
false],
123 $this->assertEquals($expected, $metric->toYAML());
129 "bool_true" => [
new M(M::STABILITY_STABLE, M::TYPE_BOOL,
true),
"true"],
130 "bool_false" => [
new M(M::STABILITY_STABLE, M::TYPE_BOOL,
false),
"false"],
131 "counter_0" => [
new M(M::STABILITY_STABLE, M::TYPE_COUNTER, 0),
"0"],
132 "counter_1337" => [
new M(M::STABILITY_STABLE, M::TYPE_COUNTER, 1337),
"1337"],
133 "gauge_23" => [
new M(M::STABILITY_STABLE, M::TYPE_GAUGE, 23),
"23"],
134 "gauge_42_0" => [
new M(M::STABILITY_STABLE, M::TYPE_GAUGE, 42.0),
"42.000"],
135 "gauge_42_001" => [
new M(M::STABILITY_STABLE, M::TYPE_GAUGE, 42.001),
"42.001"],
136 "timestamp" => [
new M(M::STABILITY_STABLE, M::TYPE_TIMESTAMP,
new \
DateTimeImmutable(
"1985-05-04T13:37:00+01:00")),
"1985-05-04T13:37:00+0100"],
137 "text" => [
new M(M::STABILITY_STABLE, M::TYPE_TEXT,
"some text"),
"some text"],
138 "text_with_nl" => [
new M(M::STABILITY_STABLE, M::TYPE_TEXT,
"some\ntext"),
">\nsome\ntext"],
144 $metrics =
new M(M::STABILITY_STABLE, M::TYPE_COLLECTION, [
145 "a" =>
new M(M::STABILITY_STABLE, M::TYPE_COLLECTION, [
146 "h" =>
new M(M::STABILITY_STABLE, M::TYPE_TEXT,
"a_h"),
147 "c" =>
new M(M::STABILITY_STABLE, M::TYPE_COLLECTION, [
148 "d" =>
new M(M::STABILITY_STABLE, M::TYPE_COLLECTION, [
149 "e" =>
new M(M::STABILITY_STABLE, M::TYPE_TEXT,
"a_c_d_e"),
150 "f" =>
new M(M::STABILITY_STABLE, M::TYPE_TEXT,
"a_c_d_f")
152 "g" =>
new M(M::STABILITY_STABLE, M::TYPE_TEXT,
"a_c_g")
154 "i" =>
new M(M::STABILITY_STABLE, M::TYPE_TEXT,
"a_i\na_i")
156 "b" =>
new M(M::STABILITY_STABLE, M::TYPE_COLLECTION, [
157 "j" =>
new M(M::STABILITY_STABLE, M::TYPE_TEXT,
"b_j")
159 "k" =>
new M(M::STABILITY_STABLE, M::TYPE_TEXT,
"k")
162 $expected = <<<METRIC
178 $this->assertEquals($expected, $metrics->toYAML());
183 $metrics =
new M(M::STABILITY_MIXED, M::TYPE_COLLECTION, [
184 "a" =>
new M(M::STABILITY_MIXED, M::TYPE_COLLECTION, [
185 "h" =>
new M(M::STABILITY_CONFIG, M::TYPE_TEXT,
"a_h"),
186 "c" =>
new M(M::STABILITY_MIXED, M::TYPE_COLLECTION, [
187 "d" =>
new M(M::STABILITY_MIXED, M::TYPE_COLLECTION, [
188 "e" =>
new M(M::STABILITY_STABLE, M::TYPE_TEXT,
"a_c_d_e"),
189 "f" =>
new M(M::STABILITY_VOLATILE, M::TYPE_TEXT,
"a_c_d_f")
191 "g" =>
new M(M::STABILITY_CONFIG, M::TYPE_TEXT,
"a_c_g")
193 "i" =>
new M(M::STABILITY_STABLE, M::TYPE_TEXT,
"a_i\na_i")
195 "b" =>
new M(M::STABILITY_MIXED, M::TYPE_COLLECTION, [
196 "j" =>
new M(M::STABILITY_VOLATILE, M::TYPE_TEXT,
"b_j")
198 "k" =>
new M(M::STABILITY_CONFIG, M::TYPE_TEXT,
"k")
201 $expected_extracted =
new M(M::STABILITY_CONFIG, M::TYPE_COLLECTION, [
202 "a" =>
new M(M::STABILITY_CONFIG, M::TYPE_COLLECTION, [
203 "h" =>
new M(M::STABILITY_CONFIG, M::TYPE_TEXT,
"a_h"),
204 "c" =>
new M(M::STABILITY_CONFIG, M::TYPE_COLLECTION, [
205 "g" =>
new M(M::STABILITY_CONFIG, M::TYPE_TEXT,
"a_c_g")
208 "k" =>
new M(M::STABILITY_CONFIG, M::TYPE_TEXT,
"k")
210 $expected_rest =
new M(M::STABILITY_MIXED, M::TYPE_COLLECTION, [
211 "a" =>
new M(M::STABILITY_MIXED, M::TYPE_COLLECTION, [
212 "c" =>
new M(M::STABILITY_MIXED, M::TYPE_COLLECTION, [
213 "d" =>
new M(M::STABILITY_MIXED, M::TYPE_COLLECTION, [
214 "e" =>
new M(M::STABILITY_STABLE, M::TYPE_TEXT,
"a_c_d_e"),
215 "f" =>
new M(M::STABILITY_VOLATILE, M::TYPE_TEXT,
"a_c_d_f")
218 "i" =>
new M(M::STABILITY_STABLE, M::TYPE_TEXT,
"a_i\na_i")
220 "b" =>
new M(M::STABILITY_MIXED, M::TYPE_COLLECTION, [
221 "j" =>
new M(M::STABILITY_VOLATILE, M::TYPE_TEXT,
"b_j")
225 list($extracted, $rest) = $metrics->extractByStability(M::STABILITY_CONFIG);
227 $this->assertEquals($expected_extracted, $extracted);
228 $this->assertEquals($expected_rest, $rest);
236 $this->assertEquals($expected, $metric->toArray());
241 $metric =
new M(M::STABILITY_STABLE, M::TYPE_COLLECTION, [
242 "bool_true" =>
new M(M::STABILITY_STABLE, M::TYPE_BOOL,
true)
245 $this->assertEquals([
"bool_true" =>
"true"], $metric->toArray());
250 $metric =
new M(M::STABILITY_STABLE, M::TYPE_COLLECTION, [
251 "db" =>
new M(M::STABILITY_STABLE, M::TYPE_COLLECTION, [
252 "bool_true" =>
new M(M::STABILITY_STABLE, M::TYPE_BOOL,
true)
256 $this->assertEquals([
"db" => [
"bool_true" =>
"true"]], $metric->toArray());
261 $factory = $this->createMock(Factory::class);
262 $listing_f =
new LF();
269 $legacy = $legacy_f->content(
"<pre>string</pre>");
272 ->expects($this->once())
274 ->willReturn($legacy);
277 ->expects($this->once())
279 ->willReturn($legacy_f)
283 ->expects($this->exactly(2))
285 ->willReturn($panel_f)
288 $metric =
new M(M::STABILITY_STABLE, M::TYPE_TEXT,
"string",
"");
290 $result = $metric->toUIReport($factory,
"Status");
292 $this->assertInstanceOf(Report::class, $result);
testConstructMetric(string $stability, string $type, $value, string $description, bool $success)
metricProvider
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)
typedMetricsProvider
A metric is something we can measure about the system.
testToArrayWithFlatValues(M $metric, string $expected)
typedMetricsProvider
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.