ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
MapValuesTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\Refinery\Factory as Refinery;
22use ILIAS\Data\Factory as DataFactory;
24use PHPUnit\Framework\TestCase;
25
26class MapValuesTest extends TestCase
27{
29 private array $test_array = [
30 "A" => 260,
31 "B" => 22,
32 "C" => 4010
33 ];
35 private array $result_array = [
36 "A" => 520,
37 "B" => 44,
38 "C" => 8020
39 ];
40 private Refinery $f;
42
43 protected function setUp(): void
44 {
45 $dataFactory = new DataFactory();
46 $language = $this->createMock(ILIAS\Language\Language::class);
47
48 $this->f = new Refinery($dataFactory, $language);
49 $this->map_values = $this->f->container()->mapValues($this->f->custom()->transformation(fn($v) => $v * 2));
50 }
51
52 public function testTransform(): void
53 {
54 $result = $this->map_values->transform($this->test_array);
55 $this->assertEquals($this->result_array, $result);
56 $this->assertEquals(["A", "B", "C"], array_keys($result));
57 }
58
59 public function testTransformFails(): void
60 {
61 $this->expectException(InvalidArgumentException::class);
62 $this->map_values->transform(null);
63 }
64}
Builds data types.
Definition: Factory.php:36
Transformation $map_values
A transformation is a function from one datatype to another.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.