ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
TupleTransformationTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
30 
32 {
36  public function testTupleTransformationsAreCorrect(): void
37  {
38  $transformation = new TupleTransformation(
40  );
41 
42  $result = $transformation->transform([1, 2]);
43 
44  $this->assertEquals([1, 2], $result);
45  }
46 
48  {
49  $this->expectNotToPerformAssertions();
50 
51  $transformation = new TupleTransformation(
53  );
54 
55  try {
56  $result = $transformation->transform([1, 2]);
57  } catch (UnexpectedValueException $exception) {
58  return;
59  }
60 
61  $this->fail();
62  }
63 
65  {
66  $this->expectNotToPerformAssertions();
67 
68  $transformation = new TupleTransformation(
69  [new IntegerTransformation(), 'hello' => new IntegerTransformation()]
70  );
71 
72  try {
73  $result = $transformation->transform([1, 2]);
74  } catch (UnexpectedValueException $exception) {
75  return;
76  }
77 
78  $this->fail();
79  }
80 
81 
82  public function testToManyValuesForTransformation(): void
83  {
84  $this->expectNotToPerformAssertions();
85 
86  $transformation = new TupleTransformation(
88  );
89 
90  try {
91  $result = $transformation->transform([1, 2, 3]);
92  } catch (UnexpectedValueException $exception) {
93  return;
94  }
95  $this->fail();
96  }
97 
98  public function testTupleAppliesAreCorrect(): void
99  {
100  $transformation = new TupleTransformation(
102  );
103 
104  $result = $transformation->applyTo(new Result\Ok([1, 2]));
105 
106  $this->assertEquals([1, 2], $result->value());
107  }
108 
110  {
111  $transformation = new TupleTransformation(
113  );
114 
115  $result = $transformation->applyTo(new Result\Ok([1, 2]));
116 
117  $this->assertTrue($result->isError());
118  }
119 
120  public function testToManyValuesForApply(): void
121  {
122  $transformation = new TupleTransformation(
124  );
125 
126  $result = $transformation->applyTo(new Result\Ok([1, 2, 3]));
127 
128  $this->assertTrue($result->isError());
129  }
130 
132  {
133  $this->expectNotToPerformAssertions();
134 
135  try {
136  $transformation = new TupleTransformation(
137  [new IntegerTransformation(), 'hello']
138  );
139  } catch (UnexpectedValueException $exception) {
140  return;
141  }
142 
143 
144  $this->fail();
145  }
146 }
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: Result.php:14
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