ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
SeriesTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28use PHPUnit\Framework\TestCase;
29use UnexpectedValueException;
30
31class SeriesTest extends TestCase
32{
33 public function testSeriesTransformation(): void
34 {
35 $series = new Series([new StringTransformation()]);
36
37 $result = $series->transform('hello');
38
39 $this->assertEquals('hello', $result);
40 }
41
42 public function testSeriesApplyTo(): void
43 {
44 $series = new Series([
47 ]);
48
49 $result = $series->applyTo(new Ok('hello'));
50
51 $this->assertEquals('hello', $result->value());
52 }
53
54 public function testSeriesTransformationFails(): void
55 {
56 $this->expectNotToPerformAssertions();
57
58 $series = new Series([
61 ]);
62
63 try {
64 $result = $series->transform(42.0);
65 } catch (UnexpectedValueException $exception) {
66 return;
67 }
68
69 $this->fail();
70 }
71
72
76 public function testSeriesApply(): void
77 {
78 $series = new Series([
81 ]);
82
83 $result = $series->applyTo(new Ok(42.0));
84
85 $this->assertTrue($result->isError());
86 }
87
89 {
90 $this->expectNotToPerformAssertions();
91
92 try {
93 $parallel = new Series(
94 [
96 'this is invalid'
97 ]
98 );
99 } catch (ConstraintViolationException $exception) {
100 return;
101 }
102
103 $this->fail();
104 }
105}
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:31