3 declare(strict_types=1);
36 $refinery =
new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
38 $c1 = $this->newAgent();
39 $c2 = $this->newAgent();
40 $c3 = $this->newAgent();
41 $c4 = $this->newAgent();
43 $c1->method(
"hasConfig")->willReturn(
true);
44 $c2->method(
"hasConfig")->willReturn(
true);
45 $c3->method(
"hasConfig")->willReturn(
false);
46 $c4->method(
"hasConfig")->willReturn(
false);
54 $this->assertTrue($col1->hasConfig());
55 $this->assertTrue($col2->hasConfig());
56 $this->assertTrue($col3->hasConfig());
57 $this->assertFalse($col4->hasConfig());
58 $this->assertFalse($col5->hasConfig());
63 $refinery =
new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
65 $c1 = $this->newAgent();
66 $c2 = $this->newAgent();
67 $c3 = $this->newAgent();
69 $conf1 = $this->newConfig();
70 $conf3 = $this->newConfig();
72 foreach ([$c1,$c3] as
$c) {
81 $arr = [
"c1" => [
"c1_data"],
"c3" => [
"c3_data"]];
84 ->expects($this->once())
85 ->method(
"getArrayToConfigTransformation")
87 ->willReturn(
$refinery->custom()->transformation(
function ($v) use ($conf1) {
88 $this->assertEquals($v, [
"c1_data"]);
92 ->expects($this->never())
93 ->method(
"getArrayToConfigTransformation");
95 ->expects($this->once())
96 ->method(
"getArrayToConfigTransformation")
98 ->willReturn(
$refinery->custom()->transformation(
function ($v) use ($conf3) {
99 $this->assertEquals($v, [
"c3_data"]);
104 $trafo = $col->getArrayToConfigTransformation();
105 $conf = $trafo($arr);
107 $this->assertInstanceOf(Setup\ConfigCollection::class, $conf);
108 $this->assertEquals([
"c1",
"c3"], $conf->getKeys());
109 $this->assertEquals($conf1, $conf->getConfig(
"c1"));
110 $this->assertEquals($conf3, $conf->getConfig(
"c3"));
115 $refinery =
new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
117 $c1 = $this->newAgent();
118 $c2 = $this->newAgent();
119 $c3 = $this->newAgent();
121 $conf1 = $this->newConfig();
122 $conf3 = $this->newConfig();
124 foreach ([$c1,$c3] as
$c) {
126 ->method(
"hasConfig")
130 ->method(
"hasConfig")
133 $arr = [
"c1" => [
"c1_data"]];
136 ->expects($this->once())
137 ->method(
"getArrayToConfigTransformation")
139 ->willReturn(
$refinery->custom()->transformation(
function ($v) use ($conf1) {
140 $this->assertEquals($v, [
"c1_data"]);
144 ->expects($this->never())
145 ->method(
"getArrayToConfigTransformation");
147 ->expects($this->once())
148 ->method(
"getArrayToConfigTransformation")
150 ->willReturn(
$refinery->custom()->transformation(
function ($v) use ($conf3) {
151 $this->assertEquals($v, null);
156 $trafo = $col->getArrayToConfigTransformation();
157 $conf = $trafo($arr);
159 $this->assertInstanceOf(Setup\ConfigCollection::class, $conf);
160 $this->assertEquals([
"c1",
"c3"], $conf->getKeys());
161 $this->assertEquals($conf1, $conf->getConfig(
"c1"));
162 $this->assertEquals($conf3, $conf->getConfig(
"c3"));
167 $refinery =
new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
169 $c1 = $this->newAgent();
170 $c2 = $this->newAgent();
172 $g1 = $this->newObjective();
173 $g2 = $this->newObjective();
175 $conf1 = $this->newConfig();
178 ->expects($this->once())
179 ->method(
"hasConfig")
182 ->expects($this->once())
183 ->method(
"hasConfig")
187 ->expects($this->once())
188 ->method(
"getInstallObjective")
192 ->expects($this->once())
193 ->method(
"getInstallObjective")
200 $g = $col->getInstallObjective($conf);
202 $this->assertInstanceOf(Setup\ObjectiveCollection::class, $g);
203 $this->assertEquals([$g1, $g2], $g->getObjectives());
208 $refinery =
new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
209 $storage = $this->createMock(Setup\Metrics\Storage::class);
211 $c1 = $this->newAgent();
212 $c2 = $this->newAgent();
214 $g1 = $this->newObjective();
215 $g2 = $this->newObjective();
221 ->expects($this->once())
222 ->method(
"getStatusObjective")
226 ->expects($this->once())
227 ->method(
"getStatusObjective")
234 $g = $col->getStatusObjective($storage);
236 $this->assertInstanceOf(Setup\ObjectiveCollection::class, $g);
237 $this->assertEquals([$g1, $g2], $g->getObjectives());
242 $refinery =
new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
244 $c1 = $this->newAgent();
245 $c2 = $this->newAgent();
247 $g1 = $this->newObjective();
248 $g2 = $this->newObjective();
250 $conf1 = $this->newConfig();
253 ->expects($this->once())
254 ->method(
"getUpdateObjective")
258 ->expects($this->once())
259 ->method(
"getUpdateObjective")
266 $g = $col->getUpdateObjective($conf);
268 $this->assertInstanceOf(Setup\ObjectiveCollection::class, $g);
269 $this->assertEquals([$g1, $g2], $g->getObjectives());
274 $refinery = $this->createMock(Refinery::class);
276 $c1 = $this->newAgent();
277 $c2 = $this->newAgent();
278 $c3 = $this->newAgent();
279 $c4 = $this->newAgent();
283 [
"c1" => $c1,
"c2" => $c2,
"c3" => $c3,
"c4" => $c4]
286 $this->assertSame($c1,
$c->getAgent(
"c1"));
287 $this->assertSame($c2,
$c->getAgent(
"c2"));
288 $this->assertSame($c3,
$c->getAgent(
"c3"));
289 $this->assertSame($c4,
$c->getAgent(
"c4"));
290 $this->assertNull(
$c->getAgent(
"c5"));
295 $refinery = $this->createMock(Refinery::class);
297 $c1 = $this->newAgent();
298 $c2 = $this->newAgent();
299 $c3 = $this->newAgent();
300 $c4 = $this->newAgent();
304 [
"c1" => $c1,
"c2" => $c2,
"c3" => $c3,
"c4" => $c4]
306 $cb = $ca->withRemovedAgent(
"c2");
308 $this->assertNotSame($ca, $cb);
310 $this->assertSame($c1, $ca->getAgent(
"c1"));
311 $this->assertSame($c2, $ca->getAgent(
"c2"));
312 $this->assertSame($c3, $ca->getAgent(
"c3"));
313 $this->assertSame($c4, $ca->getAgent(
"c4"));
314 $this->assertNull($ca->getAgent(
"c5"));
316 $this->assertSame($c1, $cb->getAgent(
"c1"));
317 $this->assertNull($cb->getAgent(
"c2"));
318 $this->assertSame($c3, $cb->getAgent(
"c3"));
319 $this->assertSame($c4, $cb->getAgent(
"c4"));
320 $this->assertNull($cb->getAgent(
"c5"));
325 $refinery = $this->createMock(Refinery::class);
327 $c1 = $this->newAgent();
328 $c2 = $this->newAgent();
329 $c3 = $this->newAgent();
330 $c4 = $this->newAgent();
334 [
"c1" => $c1,
"c2" => $c2,
"c3" => $c3]
336 $cb = $ca->withAdditionalAgent(
"c4", $c4);
338 $this->assertNotSame($ca, $cb);
340 $this->assertSame($c1, $ca->getAgent(
"c1"));
341 $this->assertSame($c2, $ca->getAgent(
"c2"));
342 $this->assertSame($c3, $ca->getAgent(
"c3"));
343 $this->assertNull($ca->getAgent(
"c4"));
344 $this->assertNull($ca->getAgent(
"c5"));
346 $this->assertSame($c1, $cb->getAgent(
"c1"));
347 $this->assertSame($c2, $cb->getAgent(
"c2"));
348 $this->assertSame($c3, $cb->getAgent(
"c3"));
349 $this->assertSame($c4, $cb->getAgent(
"c4"));
350 $this->assertNull($cb->getAgent(
"c5"));
355 $refinery = $this->createMock(Refinery::class);
358 $aAgent = $this->newAgent();
359 $bAgent = $this->newAgent();
360 $cAgent = $this->newAgent();
361 $dAgent = $this->newAgent();
364 "a-2" => $this->newObjectiveConstructor(),
365 "a-1" => $this->newObjectiveConstructor()
369 "b-1" => $this->newObjectiveConstructor(),
370 "b-3" => $this->newObjectiveConstructor(),
371 "b-2" => $this->newObjectiveConstructor(),
375 "c-2" => $this->newObjectiveConstructor(),
376 "c-1" => $this->newObjectiveConstructor()
380 "d-2" => $this->newObjectiveConstructor(),
381 "d-3" => $this->newObjectiveConstructor(),
382 "d-1" => $this->newObjectiveConstructor()
386 ->expects($this->once())
387 ->method(
"getNamedObjectives")
388 ->willReturn($aReturn);
391 ->expects($this->once())
392 ->method(
"getNamedObjectives")
393 ->willReturn($bReturn);
396 ->expects($this->once())
397 ->method(
"getNamedObjectives")
398 ->willReturn($cReturn);
401 ->expects($this->once())
402 ->method(
"getNamedObjectives")
403 ->willReturn($dReturn);
407 [
"aAgent" => $aAgent,
"cAgent" => $cAgent,
"bAgent" => $bAgent,
"dAgent" => $dAgent]
411 "aAgent.a-1" => $aReturn[
"a-1"],
412 "aAgent.a-2" => $aReturn[
"a-2"],
413 "bAgent.b-1" => $bReturn[
"b-1"],
414 "bAgent.b-2" => $bReturn[
"b-2"],
415 "bAgent.b-3" => $bReturn[
"b-3"],
416 "cAgent.c-1" => $cReturn[
"c-1"],
417 "cAgent.c-2" => $cReturn[
"c-2"],
418 "dAgent.d-1" => $dReturn[
"d-1"],
419 "dAgent.d-2" => $dReturn[
"d-2"],
420 "dAgent.d-3" => $dReturn[
"d-3"],
423 $this->assertSame($expected, $testAgentCollection->getNamedObjectives(
$config));
428 $refinery = $this->createMock(Refinery::class);
431 $aAgent = $this->newAgent();
432 $bAgent = $this->newAgent();
435 "a-1" => $this->newObjectiveConstructor(),
436 "a-2" => $this->newObjectiveConstructor()
440 "b-1" => $this->newObjectiveConstructor(),
441 "b-2" => $this->newObjectiveConstructor(),
445 ->expects($this->once())
446 ->method(
"getNamedObjectives")
447 ->willReturn($aReturn);
449 ->expects($this->once())
450 ->method(
"getNamedObjectives")
451 ->willReturn($bReturn);
455 [
"aAgent" => $aAgent,
"bAgent" => $bAgent]
458 $result = $testAgentCollection->getNamedObjectives(
$config);
460 $this->assertSame($aReturn[
"a-1"], $result[
"aAgent.a-1"]);
461 $this->assertSame($aReturn[
"a-2"], $result[
"aAgent.a-2"]);
462 $this->assertSame($bReturn[
"b-1"], $result[
"bAgent.b-1"]);
463 $this->assertSame($bReturn[
"b-2"], $result[
"bAgent.b-2"]);
468 $refinery = $this->createMock(Refinery::class);
469 $agent = $this->newAgent();
473 ->method(
"getNamedObjectives")
474 ->will($this->returnCallback(
function (
$config) use (&$seen_config) {
484 $agent_config = $this->createMock(Setup\Config::class);
486 [
"agent" => $agent_config]
489 $result = $collection->getNamedObjectives(
$config);
491 $this->assertSame($agent_config, $seen_config);
496 $refinery = $this->createMock(Refinery::class);
498 $c1 = $this->newAgent();
499 $c2 = $this->newAgent();
500 $c3 = $this->newAgent();
501 $c4 = $this->newAgent();
505 [
"c1" => $c1,
"c2" => $c2,
"c3" => $c3,
"c4" => $c4]
508 $this->assertEquals([
513 ], $agentCollection->getAgents());
testWithAdditionalAgent()
testGetInstallObjective()
An agent that is just a collection of some other agents.
testGetCollectMetricsObjective()
testArrayToConfigTransformationAllowsUnsetFields()
testGetArrayToConfigTransformation()
testGetNamedObjectivesSorting()
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...
testGetNamedObjectivePassesCorrectConfig()
A collection of some configurations.
Refinery Factory $refinery