ILIAS  trunk Revision v11.0_alpha-1851-ga8564da6fed
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
TupleTransformationTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
29 
30 class TupleTransformationTest extends TestCase
31 {
35  public function testTupleTransformationsAreCorrect(): void
36  {
37  $transformation = new TupleTransformation(
39  );
40 
41  $result = $transformation->transform([1, 2]);
42 
43  $this->assertEquals([1, 2], $result);
44  }
45 
47  {
48  $this->expectNotToPerformAssertions();
49 
50  $transformation = new TupleTransformation(
52  );
53 
54  try {
55  $result = $transformation->transform([1, 2]);
56  } catch (UnexpectedValueException $exception) {
57  return;
58  }
59 
60  $this->fail();
61  }
62 
64  {
65  $this->expectNotToPerformAssertions();
66 
67  $transformation = new TupleTransformation(
68  [new IntegerTransformation(), 'hello' => new IntegerTransformation()]
69  );
70 
71  try {
72  $result = $transformation->transform([1, 2]);
73  } catch (UnexpectedValueException $exception) {
74  return;
75  }
76 
77  $this->fail();
78  }
79 
80 
81  public function testToManyValuesForTransformation(): void
82  {
83  $this->expectNotToPerformAssertions();
84 
85  $transformation = new TupleTransformation(
87  );
88 
89  try {
90  $result = $transformation->transform([1, 2, 3]);
91  } catch (UnexpectedValueException $exception) {
92  return;
93  }
94  $this->fail();
95  }
96 
97  public function testTupleAppliesAreCorrect(): void
98  {
99  $transformation = new TupleTransformation(
101  );
102 
103  $result = $transformation->applyTo(new Result\Ok([1, 2]));
104 
105  $this->assertEquals([1, 2], $result->value());
106  }
107 
109  {
110  $transformation = new TupleTransformation(
112  );
113 
114  $result = $transformation->applyTo(new Result\Ok([1, 2]));
115 
116  $this->assertTrue($result->isError());
117  }
118 
119  public function testToManyValuesForApply(): void
120  {
121  $transformation = new TupleTransformation(
123  );
124 
125  $result = $transformation->applyTo(new Result\Ok([1, 2, 3]));
126 
127  $this->assertTrue($result->isError());
128  }
129 
131  {
132  $this->expectNotToPerformAssertions();
133 
134  try {
135  $transformation = new TupleTransformation(
136  [new IntegerTransformation(), 'hello']
137  );
138  } catch (UnexpectedValueException $exception) {
139  return;
140  }
141 
142 
143  $this->fail();
144  }
145 }
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:30