ILIAS  release_7 Revision v7.30-3-g800a261c036
StringTransformationTest.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 StringTransformation();
27 }
28
30 {
31 $transformedValue = $this->transformation->transform('hello');
32
33 $this->assertEquals('hello', $transformedValue);
34 }
35
37 {
38 $this->expectNotToPerformAssertions();
39
40 try {
41 $transformedValue = $this->transformation->transform(200);
42 } catch (ConstraintViolationException $exception) {
43 return;
44 }
45
46 $this->fail();
47 }
48
50 {
51 $this->expectNotToPerformAssertions();
52
53 try {
54 $transformedValue = $this->transformation->transform(-200);
55 } catch (ConstraintViolationException $exception) {
56 return;
57 }
58
59 $this->assertEquals('-200', $transformedValue);
60 }
61
63 {
64 $this->expectNotToPerformAssertions();
65
66 try {
67 $transformedValue = $this->transformation->transform(0);
68 } catch (ConstraintViolationException $exception) {
69 return;
70 }
71
72 $this->fail();
73 }
74
76 {
77 $this->expectNotToPerformAssertions();
78
79 $this->expectNotToPerformAssertions();
80
81 try {
82 $transformedValue = $this->transformation->transform(10.5);
83 } catch (ConstraintViolationException $exception) {
84 return;
85 }
86
87 $this->fail();
88 }
89
91 {
92 $this->expectNotToPerformAssertions();
93
94 try {
95 $transformedValue = $this->transformation->transform(true);
96 } catch (ConstraintViolationException $exception) {
97 return;
98 }
99
100 $this->fail();
101 }
102
104 {
105 $this->expectNotToPerformAssertions();
106
107 try {
108 $transformedValue = $this->transformation->transform(false);
109 } catch (ConstraintViolationException $exception) {
110 return;
111 }
112
113 $this->fail();
114 }
115
116 public function testStringToStringApply()
117 {
118 $resultObject = new Result\Ok('hello');
119
120 $transformedObject = $this->transformation->applyTo($resultObject);
121
122 $this->assertEquals('hello', $transformedObject->value());
123 }
124
126 {
127 $resultObject = new Result\Ok(200);
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(0);
146
147 $transformedObject = $this->transformation->applyTo($resultObject);
148
149 $this->assertTrue($transformedObject->isError());
150 }
151
152 public function testFloatToStringApply()
153 {
154 $resultObject = new Result\Ok(10.5);
155
156 $transformedObject = $this->transformation->applyTo($resultObject);
157
158 $this->assertTrue($transformedObject->isError());
159 }
160
161 public function testBooleanToStringApply()
162 {
163 $resultObject = new Result\Ok(true);
164
165 $transformedObject = $this->transformation->applyTo($resultObject);
166
167 $this->assertTrue($transformedObject->isError());
168 }
169}
An exception for terminatinating execution or to throw for unit testing.