ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
StringTransformationTest.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 StringTransformationTest extends TestCase
29{
31
32 protected function setUp(): void
33 {
34 $this->transformation = new StringTransformation();
35 }
36
37 public function testStringToStringTransformation(): void
38 {
39 $transformedValue = $this->transformation->transform('hello');
40
41 $this->assertEquals('hello', $transformedValue);
42 }
43
44 public function testIntegerToStringTransformation(): void
45 {
46 $this->expectNotToPerformAssertions();
47
48 try {
49 $transformedValue = $this->transformation->transform(200);
50 } catch (UnexpectedValueException $exception) {
51 return;
52 }
53
54 $this->fail();
55 }
56
58 {
59 $this->expectNotToPerformAssertions();
60
61 try {
62 $transformedValue = $this->transformation->transform(-200);
63 } catch (UnexpectedValueException $exception) {
64 return;
65 }
66
67 $this->assertEquals('-200', $transformedValue);
68 }
69
71 {
72 $this->expectNotToPerformAssertions();
73
74 try {
75 $transformedValue = $this->transformation->transform(0);
76 } catch (UnexpectedValueException $exception) {
77 return;
78 }
79
80 $this->fail();
81 }
82
83 public function testFloatToStringTransformation(): void
84 {
85 $this->expectNotToPerformAssertions();
86
87 $this->expectNotToPerformAssertions();
88
89 try {
90 $transformedValue = $this->transformation->transform(10.5);
91 } catch (UnexpectedValueException $exception) {
92 return;
93 }
94
95 $this->fail();
96 }
97
99 {
100 $this->expectNotToPerformAssertions();
101
102 try {
103 $transformedValue = $this->transformation->transform(true);
104 } catch (UnexpectedValueException $exception) {
105 return;
106 }
107
108 $this->fail();
109 }
110
112 {
113 $this->expectNotToPerformAssertions();
114
115 try {
116 $transformedValue = $this->transformation->transform(false);
117 } catch (UnexpectedValueException $exception) {
118 return;
119 }
120
121 $this->fail();
122 }
123
124 public function testStringToStringApply(): void
125 {
126 $resultObject = new Result\Ok('hello');
127
128 $transformedObject = $this->transformation->applyTo($resultObject);
129
130 $this->assertEquals('hello', $transformedObject->value());
131 }
132
133 public function testPositiveIntegerToIntegerApply(): void
134 {
135 $resultObject = new Result\Ok(200);
136
137 $transformedObject = $this->transformation->applyTo($resultObject);
138
139 $this->assertTrue($transformedObject->isError());
140 }
141
142 public function testNegativeIntegerToIntegerApply(): 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 testZeroIntegerToIntegerApply(): void
152 {
153 $resultObject = new Result\Ok(0);
154
155 $transformedObject = $this->transformation->applyTo($resultObject);
156
157 $this->assertTrue($transformedObject->isError());
158 }
159
160 public function testFloatToStringApply(): void
161 {
162 $resultObject = new Result\Ok(10.5);
163
164 $transformedObject = $this->transformation->applyTo($resultObject);
165
166 $this->assertTrue($transformedObject->isError());
167 }
168
169 public function testBooleanToStringApply(): void
170 {
171 $resultObject = new Result\Ok(true);
172
173 $transformedObject = $this->transformation->applyTo($resultObject);
174
175 $this->assertTrue($transformedObject->isError());
176 }
177}