ILIAS  release_8 Revision v8.24
MapValuesTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21use ILIAS\Refinery\Factory as Refinery;
22use ILIAS\Data\Factory as DataFactory;
25use PHPUnit\Framework\TestCase;
26
27class MapValuesTest extends TestCase
28{
30 private array $test_array = [
31 "A" => 260,
32 "B" => 22,
33 "C" => 4010
34 ];
36 private array $result_array = [
37 "A" => 520,
38 "B" => 44,
39 "C" => 8020
40 ];
41 private Refinery $f;
43
44 protected function setUp(): void
45 {
46 $dataFactory = new DataFactory();
47 $language = $this->createMock(ilLanguage::class);
48
49 $this->f = new Refinery($dataFactory, $language);
50 $this->map_values = $this->f->container()->mapValues($this->f->custom()->transformation(fn ($v) => $v * 2));
51 }
52
53 public function testTransform(): void
54 {
55 $result = $this->map_values->transform($this->test_array);
56 $this->assertEquals($this->result_array, $result);
57 $this->assertEquals(["A", "B", "C"], array_keys($result));
58 }
59
60 public function testTransformFails(): void
61 {
62 $this->expectException(InvalidArgumentException::class);
63 $this->map_values->transform(null);
64 }
65}
Builds data types.
Definition: Factory.php:21
Adds to any array keys for each value.
Definition: MapValues.php:33
Transformation $map_values
A transformation is a function from one datatype to another.