ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ResultTest Class Reference

Tests working with result object. More...

+ Inheritance diagram for ResultTest:
+ Collaboration diagram for ResultTest:

Public Member Functions

 testValue ()
 
 testNoValue ()
 
 testIsOk ()
 
 testError ()
 
 testNoError ()
 
 testIsError ()
 
 testValueOr ()
 
 testValueOrDefault ()
 
 testMapOk ()
 
 testMapError ()
 
 testThenOk ()
 
 testThenCallableNull ()
 
 testThenError ()
 
 testThenNoResult ()
 
 testExceptError ()
 
 testExceptCallableNull ()
 
 testExceptOk ()
 
 testExceptNoResult ()
 

Protected Member Functions

 setUp ()
 
 tearDown ()
 

Detailed Description

Tests working with result object.

Author
Stefan Hecken stefa.nosp@m.n.he.nosp@m.cken@.nosp@m.conc.nosp@m.epts-.nosp@m.and-.nosp@m.train.nosp@m.ing..nosp@m.de

Definition at line 13 of file ResultTest.php.

Member Function Documentation

◆ setUp()

ResultTest::setUp ( )
protected

Definition at line 15 of file ResultTest.php.

16  {
17  $this->f = new Data\Factory();
18  }

◆ tearDown()

ResultTest::tearDown ( )
protected

Definition at line 20 of file ResultTest.php.

21  {
22  $this->f = null;
23  }

◆ testError()

ResultTest::testError ( )

Definition at line 52 of file ResultTest.php.

References $result.

53  {
54  $result = $this->f->error("Something went wrong");
55  $this->assertEquals("Something went wrong", $result->error());
56  }
$result

◆ testExceptCallableNull()

ResultTest::testExceptCallableNull ( )

Definition at line 185 of file ResultTest.php.

References $result.

186  {
187  $result = $this->f->error("Something went wrong");
188  $exception = "Something else went wrong";
189 
190  $new_result = $result->except(function ($v) {
191  return null;
192  });
193 
194  $this->assertInstanceOf(Data\Result::class, $new_result);
195  $this->assertEquals($result, $new_result);
196  }
$result

◆ testExceptError()

ResultTest::testExceptError ( )

Definition at line 170 of file ResultTest.php.

References $result, and $ret.

171  {
172  $result = $this->f->error("Something went wrong");
173  $exception = "Something else went wrong";
174 
175  $new_result = $result->except(function ($v) use ($exception) {
176  $ret = $this->f->error($exception);
177  return $ret;
178  });
179 
180  $this->assertInstanceOf(Data\Result::class, $new_result);
181  $this->assertNotEquals($result, $new_result);
182  $this->assertEquals("Something else went wrong", $new_result->error());
183  }
$result
$ret
Definition: parser.php:6

◆ testExceptNoResult()

ResultTest::testExceptNoResult ( )

Definition at line 212 of file ResultTest.php.

References $result.

213  {
214  $result = $this->f->error("Something went wrong");
215 
216  try {
217  $new_result = $result->except(function ($v) {
218  return "New error text";
219  });
220 
221  $raised = false;
222  } catch (\UnexpectedValueException $e) {
223  $raised = true;
224  }
225 
226  $this->assertTrue($raised);
227  }
$result

◆ testExceptOk()

ResultTest::testExceptOk ( )

Definition at line 198 of file ResultTest.php.

References $result, and $ret.

199  {
200  $result = $this->f->ok(3);
201  $exception = "Something else went wrong";
202 
203  $new_result = $result->except(function ($v) use ($exception) {
204  $ret = $this->f->error($exception);
205  return $ret;
206  });
207 
208  $this->assertInstanceOf(Data\Result::class, $new_result);
209  $this->assertEquals($result, $new_result);
210  }
$result
$ret
Definition: parser.php:6

◆ testIsError()

ResultTest::testIsError ( )

Definition at line 72 of file ResultTest.php.

References $result.

73  {
74  $result = $this->f->error("Something went wrong");
75  $this->assertTrue($result->isError());
76  $this->assertFalse($result->isOk());
77  }
$result

◆ testIsOk()

ResultTest::testIsOk ( )

Definition at line 45 of file ResultTest.php.

References $result.

46  {
47  $result = $this->f->ok(3.154);
48  $this->assertTrue($result->isOk());
49  $this->assertFalse($result->isError());
50  }
$result

◆ testMapError()

ResultTest::testMapError ( )

Definition at line 104 of file ResultTest.php.

References $result.

105  {
106  $result = $this->f->error("Something went wrong");
107  $multiplicator = 3;
108  $new_result = $result->map(function ($v) use ($multiplicator) {
109  return $v * $multiplicator;
110  });
111 
112  $this->assertEquals($result, $new_result);
113  }
$result

◆ testMapOk()

ResultTest::testMapOk ( )

Definition at line 91 of file ResultTest.php.

References $result.

92  {
93  $result = $this->f->ok(3);
94  $multiplicator = 3;
95  $new_result = $result->map(function ($v) use ($multiplicator) {
96  return $v * $multiplicator;
97  });
98 
99  $this->assertInstanceOf(Data\Result::class, $new_result);
100  $this->assertNotEquals($result, $new_result);
101  $this->assertEquals(9, $new_result->value());
102  }
$result

◆ testNoError()

ResultTest::testNoError ( )

Definition at line 58 of file ResultTest.php.

References $result.

59  {
60  $result = $this->f->ok(3.154);
61 
62  try {
63  $result->error();
64  $raised = false;
65  } catch (\LogicException $e) {
66  $raised = true;
67  }
68 
69  $this->assertTrue($raised);
70  }
$result

◆ testNoValue()

ResultTest::testNoValue ( )

Definition at line 31 of file ResultTest.php.

References $result.

32  {
33  $result = $this->f->error("Something went wrong");
34 
35  try {
36  $result->value();
37  $raised = false;
38  } catch (\Exception $e) {
39  $raised = true;
40  }
41 
42  $this->assertTrue($raised);
43  }
$result

◆ testThenCallableNull()

ResultTest::testThenCallableNull ( )

Definition at line 129 of file ResultTest.php.

References $result.

130  {
131  $result = $this->f->ok(3);
132  $new_result = $result->then(function ($v) {
133  return null;
134  });
135 
136  $this->assertInstanceOf(Data\Result::class, $new_result);
137  $this->assertEquals($result, $new_result);
138  }
$result

◆ testThenError()

ResultTest::testThenError ( )

Definition at line 140 of file ResultTest.php.

References $result, and $ret.

141  {
142  $result = $this->f->error("Something went wrong");
143  $multiplicator = 3;
144  $new_result = $result->then(function ($v) use ($multiplicator) {
145  $ret = $this->f->ok(($v * $multiplicator));
146  return $ret;
147  });
148 
149  $this->assertInstanceOf(Data\Result::class, $new_result);
150  $this->assertEquals($result, $new_result);
151  }
$result
$ret
Definition: parser.php:6

◆ testThenNoResult()

ResultTest::testThenNoResult ( )

Definition at line 153 of file ResultTest.php.

References $result.

154  {
155  $result = $this->f->ok(3);
156 
157  try {
158  $new_result = $result->then(function ($v) {
159  return 4;
160  });
161 
162  $raised = false;
163  } catch (\UnexpectedValueException $e) {
164  $raised = true;
165  }
166 
167  $this->assertTrue($raised);
168  }
$result

◆ testThenOk()

ResultTest::testThenOk ( )

Definition at line 115 of file ResultTest.php.

References $result, and $ret.

116  {
117  $result = $this->f->ok(3);
118  $multiplicator = 3;
119  $new_result = $result->then(function ($v) use ($multiplicator) {
120  $ret = $this->f->ok(($v * $multiplicator));
121  return $ret;
122  });
123 
124  $this->assertInstanceOf(Data\Result::class, $new_result);
125  $this->assertNotEquals($result, $new_result);
126  $this->assertEquals(9, $new_result->value());
127  }
$result
$ret
Definition: parser.php:6

◆ testValue()

ResultTest::testValue ( )

Definition at line 25 of file ResultTest.php.

References $result.

26  {
27  $result = $this->f->ok(3.154);
28  $this->assertEquals(3.154, $result->value());
29  }
$result

◆ testValueOr()

ResultTest::testValueOr ( )

Definition at line 79 of file ResultTest.php.

References $result.

80  {
81  $result = $this->f->ok(3.154);
82  $this->assertEquals(3.154, $result->valueOr(5));
83  }
$result

◆ testValueOrDefault()

ResultTest::testValueOrDefault ( )

Definition at line 85 of file ResultTest.php.

References $result.

86  {
87  $result = $this->f->error("Something went wrong");
88  $this->assertEquals(5, $result->valueOr(5));
89  }
$result

The documentation for this class was generated from the following file: