ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
MapValuesTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
26 
27 class 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 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
A transformation is a function from one datatype to another.
Transformation $map_values