ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ParallelTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29use PHPUnit\Framework\TestCase;
30use UnexpectedValueException;
31
32class ParallelTest extends TestCase
33{
34 public function testParallelTransformation(): void
35 {
36 $parallel = new Parallel(
37 [
40 ]
41 );
42
43 $result = $parallel->transform('hello');
44
45 $this->assertEquals(['hello', 'hello'], $result);
46 }
47
48
50 {
51 $parallel = new Parallel(
52 [
55 ]
56 );
57
58 $result = $parallel->applyTo(new Ok('hello'));
59
60 $this->assertEquals(['hello', 'hello'], $result->value());
61 }
62
64 {
65 $this->expectNotToPerformAssertions();
66 $parallel = new Parallel([new StringTransformation()]);
67
68 try {
69 $result = $parallel->transform(42.0);
70 } catch (UnexpectedValueException $exception) {
71 return;
72 }
73
74 $this->fail();
75 }
76
77 public function testParallelApply(): void
78 {
79 $parallel = new Parallel(
80 [
84 ]
85 );
86
87 $result = $parallel->applyTo(new Ok(42));
88
89 $this->assertTrue($result->isError());
90 }
91
93 {
94 $this->expectNotToPerformAssertions();
95
96 try {
97 $parallel = new Parallel(
98 [
100 'this is invalid'
101 ]
102 );
103 } catch (ConstraintViolationException $exception) {
104 return;
105 }
106
107 $this->fail();
108 }
109}
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:31