ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
IntegerTransformationTest.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 IntegerTransformationTest extends TestCase
29{
31
32 protected function setUp(): void
33 {
34 $this->transformation = new IntegerTransformation();
35 }
36
37 public function testIntegerToIntegerTransformation(): void
38 {
39 $transformedValue = $this->transformation->transform(200);
40
41 $this->assertEquals(200, $transformedValue);
42 }
43
45 {
46 $transformedValue = $this->transformation->transform(-200);
47
48 $this->assertEquals(-200, $transformedValue);
49 }
50
52 {
53 $transformedValue = $this->transformation->transform(0);
54
55 $this->assertEquals(0, $transformedValue);
56 }
57
58 public function testStringToIntegerTransformation(): void
59 {
60 $this->expectNotToPerformAssertions();
61
62 try {
63 $transformedValue = $this->transformation->transform('hello');
64 } catch (UnexpectedValueException $exception) {
65 return;
66 }
67
68 $this->fail();
69 }
70
71 public function testFloatToIntegerTransformation(): void
72 {
73 $this->expectNotToPerformAssertions();
74
75 try {
76 $transformedValue = $this->transformation->transform(10.5);
77 } catch (UnexpectedValueException $exception) {
78 return;
79 }
80
81 $this->fail();
82 }
83
85 {
86 $this->expectNotToPerformAssertions();
87
88 try {
89 $transformedValue = $this->transformation->transform(true);
90 } catch (UnexpectedValueException $exception) {
91 return;
92 }
93
94 $this->fail();
95 }
96
98 {
99 $this->expectNotToPerformAssertions();
100
101 try {
102 $transformedValue = $this->transformation->transform(false);
103 } catch (UnexpectedValueException $exception) {
104 return;
105 }
106
107 $this->fail();
108 }
109
110 public function testStringToIntegerApply(): void
111 {
112 $resultObject = new Result\Ok('hello');
113
114 $transformedObject = $this->transformation->applyTo($resultObject);
115
116 $this->assertTrue($transformedObject->isError());
117 }
118
119 public function testPositiveIntegerToIntegerApply(): void
120 {
121 $resultObject = new Result\Ok(200);
122
123 $transformedObject = $this->transformation->applyTo($resultObject);
124
125 $this->assertEquals(200, $transformedObject->value());
126 }
127
128 public function testNegativeIntegerToIntegerApply(): void
129 {
130 $resultObject = new Result\Ok(-200);
131
132 $transformedObject = $this->transformation->applyTo($resultObject);
133
134 $this->assertEquals(-200, $transformedObject->value());
135 }
136
137 public function testZeroIntegerToIntegerApply(): void
138 {
139 $resultObject = new Result\Ok(0);
140
141 $transformedObject = $this->transformation->applyTo($resultObject);
142
143 $this->assertEquals(0, $transformedObject->value());
144 }
145
146 public function testFloatToIntegerApply(): void
147 {
148 $resultObject = new Result\Ok(10.5);
149
150 $transformedObject = $this->transformation->applyTo($resultObject);
151
152 $this->assertTrue($transformedObject->isError());
153 }
154
155 public function testBooleanToIntegerApply(): void
156 {
157 $resultObject = new Result\Ok(true);
158
159 $transformedObject = $this->transformation->applyTo($resultObject);
160
161 $this->assertTrue($transformedObject->isError());
162 }
163}