ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
BooleanTransformationTest.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
9 
10 require_once('./libs/composer/vendor/autoload.php');
11 
16 
18 {
22  private $transformation;
23 
24  public function setUp() : void
25  {
26  $this->transformation = new BooleanTransformation();
27  }
28 
30  {
31  $this->expectNotToPerformAssertions();
32 
33  try {
34  $transformedValue = $this->transformation->transform(200);
35  } catch (ConstraintViolationException $exception) {
36  return;
37  }
38  $this->fail();
39  }
40 
42  {
43  $this->expectNotToPerformAssertions();
44 
45  try {
46  $transformedValue = $this->transformation->transform(-200);
47  } catch (ConstraintViolationException $exception) {
48  return;
49  }
50  $this->fail();
51  }
52 
54  {
55  $this->expectNotToPerformAssertions();
56 
57  try {
58  $transformedValue = $this->transformation->transform(0);
59  } catch (ConstraintViolationException $exception) {
60  return;
61  }
62  $this->fail();
63  }
64 
66  {
67  $this->expectNotToPerformAssertions();
68 
69  try {
70  $transformedValue = $this->transformation->transform('hello');
71  } catch (ConstraintViolationException $exception) {
72  return;
73  }
74  $this->fail();
75  }
76 
78  {
79  $this->expectNotToPerformAssertions();
80 
81  try {
82  $transformedValue = $this->transformation->transform(10.5);
83  } catch (ConstraintViolationException $exception) {
84  return;
85  }
86  $this->fail();
87  }
88 
90  {
91  $this->expectNotToPerformAssertions();
92 
93  try {
94  $transformedValue = $this->transformation->transform(-10.5);
95  } catch (ConstraintViolationException $exception) {
96  return;
97  }
98  $this->fail();
99  }
100 
102  {
103  $this->expectNotToPerformAssertions();
104 
105  try {
106  $transformedValue = $this->transformation->transform(0.0);
107  } catch (ConstraintViolationException $exception) {
108  return;
109  }
110  $this->fail();
111  }
112 
114  {
115  $transformedValue = $this->transformation->transform(true);
116  $this->assertTrue($transformedValue);
117  }
118 
120  {
121  $transformedValue = $this->transformation->transform(false);
122  $this->assertFalse($transformedValue);
123  }
124 
125  public function testStringToBooleanApply()
126  {
127  $resultObject = new Result\Ok('hello');
128 
129  $transformedObject = $this->transformation->applyTo($resultObject);
130 
131  $this->assertTrue($transformedObject->isError());
132  }
133 
135  {
136  $resultObject = new Result\Ok(200);
137 
138  $transformedObject = $this->transformation->applyTo($resultObject);
139 
140  $this->assertTrue($transformedObject->isError());
141  }
142 
144  {
145  $resultObject = new Result\Ok(-200);
146 
147  $transformedObject = $this->transformation->applyTo($resultObject);
148 
149  $this->assertTrue($transformedObject->isError());
150  }
151 
153  {
154  $resultObject = new Result\Ok(0);
155 
156  $transformedObject = $this->transformation->applyTo($resultObject);
157 
158  $this->assertTrue($transformedObject->isError());
159  }
160 
161  public function testFloatToBooleanApply()
162  {
163  $resultObject = new Result\Ok(10.5);
164 
165  $transformedObject = $this->transformation->applyTo($resultObject);
166 
167  $this->assertTrue($transformedObject->isError());
168  }
169 
170  public function testBooleanToBooleanApply()
171  {
172  $resultObject = new Result\Ok(true);
173 
174  $transformedObject = $this->transformation->applyTo($resultObject);
175 
176  $this->assertTrue($transformedObject->value());
177  }
178 }