ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
FloatTransformationTest.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
10require_once('./libs/composer/vendor/autoload.php');
11
16
18{
23
24 public function setUp() : void
25 {
26 $this->transformation = new FloatTransformation();
27 }
28
30 {
31 $this->expectNotToPerformAssertions();
32
33 try {
34 $transformedValue = $this->transformation->transform(200);
35 } catch (ConstraintViolationException $exception) {
36 return;
37 }
38
39 $this->fail();
40 }
41
43 {
44 $this->expectNotToPerformAssertions();
45
46 try {
47 $transformedValue = $this->transformation->transform('hello');
48 } catch (ConstraintViolationException $exception) {
49 return;
50 }
51
52 $this->fail();
53 }
54
56 {
57 $transformedValue = $this->transformation->transform(10.5);
58
59 $this->assertEquals(10.5, $transformedValue);
60 }
61
63 {
64 $this->expectNotToPerformAssertions();
65
66 try {
67 $transformedValue = $this->transformation->transform(-200);
68 } catch (ConstraintViolationException $exception) {
69 return;
70 }
71
72 $this->fail();
73 }
74
76 {
77 $this->expectNotToPerformAssertions();
78
79 try {
80 $transformedValue = $this->transformation->transform(0);
81 } catch (ConstraintViolationException $exception) {
82 return;
83 }
84
85 $this->fail();
86 }
87
89 {
90 $transformedValue = $this->transformation->transform(0.0);
91
92 $this->assertEquals(0.0, $transformedValue);
93 }
94
96 {
97 $resultObject = new Result\Ok(200);
98
99 $transformedObject = $this->transformation->applyTo($resultObject);
100
101 $this->assertTrue($transformedObject->isError());
102 }
103
105 {
106 $resultObject = new Result\Ok(-200);
107
108 $transformedObject = $this->transformation->applyTo($resultObject);
109
110 $this->assertTrue($transformedObject->isError());
111 }
112
114 {
115 $resultObject = new Result\Ok(0);
116
117 $transformedObject = $this->transformation->applyTo($resultObject);
118
119 $this->assertTrue($transformedObject->isError());
120 }
121
122 public function testStringToFloatApply()
123 {
124 $resultObject = new Result\Ok('hello');
125
126 $transformedObject = $this->transformation->applyTo($resultObject);
127
128 $this->assertTrue($transformedObject->isError());
129 }
130
131 public function testIntegerToFloatApply()
132 {
133 $resultObject = new Result\Ok(200);
134
135 $transformedObject = $this->transformation->applyTo($resultObject);
136
137 $this->assertTrue($transformedObject->isError());
138 }
139
140 public function testFloatToFloatApply()
141 {
142 $resultObject = new Result\Ok(10.5);
143
144 $transformedObject = $this->transformation->applyTo($resultObject);
145
146 $this->assertEquals(10.5, $transformedObject->value());
147 }
148
149 public function testBooleanToFloatApply()
150 {
151 $resultObject = new Result\Ok(true);
152
153 $transformedObject = $this->transformation->applyTo($resultObject);
154
155 $this->assertTrue($transformedObject->isError());
156 }
157}
An exception for terminatinating execution or to throw for unit testing.