ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
FloatTransformationTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25use PHPUnit\Framework\TestCase;
26use UnexpectedValueException;
27
28class FloatTransformationTest extends TestCase
29{
31
32 protected function setUp(): void
33 {
34 $this->transformation = new FloatTransformation();
35 }
36
37 public function testIntegerToFloatTransformation(): void
38 {
39 $this->expectNotToPerformAssertions();
40
41 try {
42 $transformedValue = $this->transformation->transform(200);
43 } catch (UnexpectedValueException $exception) {
44 return;
45 }
46
47 $this->fail();
48 }
49
50 public function testStringToFloatTransformation(): void
51 {
52 $this->expectNotToPerformAssertions();
53
54 try {
55 $transformedValue = $this->transformation->transform('hello');
56 } catch (UnexpectedValueException $exception) {
57 return;
58 }
59
60 $this->fail();
61 }
62
63 public function testFloatToFloatTransformation(): void
64 {
65 $transformedValue = $this->transformation->transform(10.5);
66
67 $this->assertEquals(10.5, $transformedValue);
68 }
69
71 {
72 $this->expectNotToPerformAssertions();
73
74 try {
75 $transformedValue = $this->transformation->transform(-200);
76 } catch (UnexpectedValueException $exception) {
77 return;
78 }
79
80 $this->fail();
81 }
82
84 {
85 $this->expectNotToPerformAssertions();
86
87 try {
88 $transformedValue = $this->transformation->transform(0);
89 } catch (UnexpectedValueException $exception) {
90 return;
91 }
92
93 $this->fail();
94 }
95
96 public function testZeroFloatToFloatTransformation(): void
97 {
98 $transformedValue = $this->transformation->transform(0.0);
99
100 $this->assertEquals(0.0, $transformedValue);
101 }
102
103 public function testPositiveIntegerToFloatApply(): void
104 {
105 $resultObject = new Result\Ok(200);
106
107 $transformedObject = $this->transformation->applyTo($resultObject);
108
109 $this->assertTrue($transformedObject->isError());
110 }
111
112 public function testNegativeIntegerToFloatApply(): void
113 {
114 $resultObject = new Result\Ok(-200);
115
116 $transformedObject = $this->transformation->applyTo($resultObject);
117
118 $this->assertTrue($transformedObject->isError());
119 }
120
121 public function testZeroIntegerToFloatApply(): void
122 {
123 $resultObject = new Result\Ok(0);
124
125 $transformedObject = $this->transformation->applyTo($resultObject);
126
127 $this->assertTrue($transformedObject->isError());
128 }
129
130 public function testStringToFloatApply(): void
131 {
132 $resultObject = new Result\Ok('hello');
133
134 $transformedObject = $this->transformation->applyTo($resultObject);
135
136 $this->assertTrue($transformedObject->isError());
137 }
138
139 public function testIntegerToFloatApply(): void
140 {
141 $resultObject = new Result\Ok(200);
142
143 $transformedObject = $this->transformation->applyTo($resultObject);
144
145 $this->assertTrue($transformedObject->isError());
146 }
147
148 public function testFloatToFloatApply(): void
149 {
150 $resultObject = new Result\Ok(10.5);
151
152 $transformedObject = $this->transformation->applyTo($resultObject);
153
154 $this->assertEquals(10.5, $transformedObject->value());
155 }
156
157 public function testBooleanToFloatApply(): void
158 {
159 $resultObject = new Result\Ok(true);
160
161 $transformedObject = $this->transformation->applyTo($resultObject);
162
163 $this->assertTrue($transformedObject->isError());
164 }
165}