ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
IntegerTransformationTest.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 IntegerTransformation();
27 }
28
30 {
31 $transformedValue = $this->transformation->transform(200);
32
33 $this->assertEquals(200, $transformedValue);
34 }
35
37 {
38 $transformedValue = $this->transformation->transform(-200);
39
40 $this->assertEquals(-200, $transformedValue);
41 }
42
44 {
45 $transformedValue = $this->transformation->transform(0);
46
47 $this->assertEquals(0, $transformedValue);
48 }
49
51 {
52 $this->expectNotToPerformAssertions();
53
54 try {
55 $transformedValue = $this->transformation->transform('hello');
56 } catch (ConstraintViolationException $exception) {
57 return;
58 }
59
60 $this->fail();
61 }
62
64 {
65 $this->expectNotToPerformAssertions();
66
67 try {
68 $transformedValue = $this->transformation->transform(10.5);
69 } catch (ConstraintViolationException $exception) {
70 return;
71 }
72
73 $this->fail();
74 }
75
77 {
78 $this->expectNotToPerformAssertions();
79
80 try {
81 $transformedValue = $this->transformation->transform(true);
82 } catch (ConstraintViolationException $exception) {
83 return;
84 }
85
86 $this->fail();
87 }
88
90 {
91 $this->expectNotToPerformAssertions();
92
93 try {
94 $transformedValue = $this->transformation->transform(false);
95 } catch (ConstraintViolationException $exception) {
96 return;
97 }
98
99 $this->fail();
100 }
101
102 public function testStringToIntegerApply()
103 {
104 $resultObject = new Result\Ok('hello');
105
106 $transformedObject = $this->transformation->applyTo($resultObject);
107
108 $this->assertTrue($transformedObject->isError());
109 }
110
112 {
113 $resultObject = new Result\Ok(200);
114
115 $transformedObject = $this->transformation->applyTo($resultObject);
116
117 $this->assertEquals(200, $transformedObject->value());
118 }
119
121 {
122 $resultObject = new Result\Ok(-200);
123
124 $transformedObject = $this->transformation->applyTo($resultObject);
125
126 $this->assertEquals(-200, $transformedObject->value());
127 }
128
130 {
131 $resultObject = new Result\Ok(0);
132
133 $transformedObject = $this->transformation->applyTo($resultObject);
134
135 $this->assertEquals(0, $transformedObject->value());
136 }
137
138 public function testFloatToIntegerApply()
139 {
140 $resultObject = new Result\Ok(10.5);
141
142 $transformedObject = $this->transformation->applyTo($resultObject);
143
144 $this->assertTrue($transformedObject->isError());
145 }
146
148 {
149 $resultObject = new Result\Ok(true);
150
151 $transformedObject = $this->transformation->applyTo($resultObject);
152
153 $this->assertTrue($transformedObject->isError());
154 }
155}
An exception for terminatinating execution or to throw for unit testing.