ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
DictionaryTransformationTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
28 
30 {
34  public function testDictionaryTransformationValid(): void
35  {
36  $transformation = new DictionaryTransformation(new StringTransformation());
37 
38  $result = $transformation->transform(['hello' => 'world']);
39 
40  $this->assertEquals(['hello' => 'world'], $result);
41  }
42 
44  {
45  $this->expectNotToPerformAssertions();
46 
47  $transformation = new DictionaryTransformation(new StringTransformation());
48 
49  try {
50  $result = $transformation->transform(['world']);
51  } catch (UnexpectedValueException $exception) {
52  return;
53  }
54 
55  $this->fail();
56  }
57 
59  {
60  $this->expectNotToPerformAssertions();
61 
62  $transformation = new DictionaryTransformation(new StringTransformation());
63 
64  try {
65  $result = $transformation->transform(['hello' => 1]);
66  } catch (UnexpectedValueException $exception) {
67  return;
68  }
69 
70  $this->fail();
71  }
72 
74  {
75  $this->expectNotToPerformAssertions();
76 
77  $transformation = new DictionaryTransformation(new StringTransformation());
78 
79  try {
80  $result = $transformation->transform(1);
81  } catch (UnexpectedValueException $exception) {
82  return;
83  }
84 
85  $this->fail();
86  }
87 
88  public function testDictionaryApplyValid(): void
89  {
90  $transformation = new DictionaryTransformation(new StringTransformation());
91 
92  $result = $transformation->applyTo(new Ok(['hello' => 'world']));
93 
94  $this->assertEquals(['hello' => 'world'], $result->value());
95  }
96 
98  {
99  $transformation = new DictionaryTransformation(new StringTransformation());
100 
101  $result = $transformation->applyTo(new Ok(['world']));
102 
103  $this->assertTrue($result->isError());
104  }
105 
107  {
108  $transformation = new DictionaryTransformation(new StringTransformation());
109 
110  $result = $transformation->applyTo(new Ok(['hello' => 1]));
111 
112  $this->assertTrue($result->isError());
113  }
114 
116  {
117  $transformation = new DictionaryTransformation(new StringTransformation());
118 
119  $result = $transformation->applyTo(new Ok(1));
120 
121  $this->assertTrue($result->isError());
122  }
123 }
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...
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:16