ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
BooleanTransformationTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 
28 class BooleanTransformationTest extends TestCase
29 {
31 
32  protected function setUp(): void
33  {
34  $this->transformation = new BooleanTransformation();
35  }
36 
37  public function testIntegerToBooleanTransformation(): void
38  {
39  $this->expectNotToPerformAssertions();
40 
41  try {
42  $transformedValue = $this->transformation->transform(200);
43  } catch (UnexpectedValueException $exception) {
44  return;
45  }
46  $this->fail();
47  }
48 
50  {
51  $this->expectNotToPerformAssertions();
52 
53  try {
54  $transformedValue = $this->transformation->transform(-200);
55  } catch (UnexpectedValueException $exception) {
56  return;
57  }
58  $this->fail();
59  }
60 
62  {
63  $this->expectNotToPerformAssertions();
64 
65  try {
66  $transformedValue = $this->transformation->transform(0);
67  } catch (UnexpectedValueException $exception) {
68  return;
69  }
70  $this->fail();
71  }
72 
73  public function testStringToBooleanTransformation(): void
74  {
75  $this->expectNotToPerformAssertions();
76 
77  try {
78  $transformedValue = $this->transformation->transform('hello');
79  } catch (UnexpectedValueException $exception) {
80  return;
81  }
82  $this->fail();
83  }
84 
85  public function testFloatToBooleanTransformation(): void
86  {
87  $this->expectNotToPerformAssertions();
88 
89  try {
90  $transformedValue = $this->transformation->transform(10.5);
91  } catch (UnexpectedValueException $exception) {
92  return;
93  }
94  $this->fail();
95  }
96 
98  {
99  $this->expectNotToPerformAssertions();
100 
101  try {
102  $transformedValue = $this->transformation->transform(-10.5);
103  } catch (UnexpectedValueException $exception) {
104  return;
105  }
106  $this->fail();
107  }
108 
109  public function testZeroFloatToBooleanTransformation(): void
110  {
111  $this->expectNotToPerformAssertions();
112 
113  try {
114  $transformedValue = $this->transformation->transform(0.0);
115  } catch (UnexpectedValueException $exception) {
116  return;
117  }
118  $this->fail();
119  }
120 
122  {
123  $transformedValue = $this->transformation->transform(true);
124  $this->assertTrue($transformedValue);
125  }
126 
128  {
129  $transformedValue = $this->transformation->transform(false);
130  $this->assertFalse($transformedValue);
131  }
132 
133  public function testStringToBooleanApply(): void
134  {
135  $resultObject = new Result\Ok('hello');
136 
137  $transformedObject = $this->transformation->applyTo($resultObject);
138 
139  $this->assertTrue($transformedObject->isError());
140  }
141 
142  public function testPositiveIntegerToBooleanApply(): void
143  {
144  $resultObject = new Result\Ok(200);
145 
146  $transformedObject = $this->transformation->applyTo($resultObject);
147 
148  $this->assertTrue($transformedObject->isError());
149  }
150 
151  public function testNegativeIntegerToBooleanApply(): void
152  {
153  $resultObject = new Result\Ok(-200);
154 
155  $transformedObject = $this->transformation->applyTo($resultObject);
156 
157  $this->assertTrue($transformedObject->isError());
158  }
159 
160  public function testZeroIntegerToBooleanApply(): void
161  {
162  $resultObject = new Result\Ok(0);
163 
164  $transformedObject = $this->transformation->applyTo($resultObject);
165 
166  $this->assertTrue($transformedObject->isError());
167  }
168 
169  public function testFloatToBooleanApply(): void
170  {
171  $resultObject = new Result\Ok(10.5);
172 
173  $transformedObject = $this->transformation->applyTo($resultObject);
174 
175  $this->assertTrue($transformedObject->isError());
176  }
177 
178  public function testBooleanToBooleanApply(): void
179  {
180  $resultObject = new Result\Ok(true);
181 
182  $transformedObject = $this->transformation->applyTo($resultObject);
183 
184  $this->assertTrue($transformedObject->value());
185  }
186 }