ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ParallelTest.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 
18 
19 require_once('./libs/composer/vendor/autoload.php');
20 
21 
22 class ParallelTest extends TestCase
23 {
24  public function testParallelTransformation()
25  {
26  $parallel = new Parallel(
27  array(
30  )
31  );
32 
33  $result = $parallel->transform('hello');
34 
35  $this->assertEquals(array('hello', 'hello'), $result);
36  }
37 
38 
40  {
41  $parallel = new Parallel(
42  array(
45  )
46  );
47 
48  $result = $parallel->applyTo(new Ok('hello'));
49 
50  $this->assertEquals(array('hello', 'hello'), $result->value());
51  }
52 
54  {
55  $this->expectNotToPerformAssertions();
56  $parallel = new Parallel(array(new StringTransformation()));
57 
58  try {
59  $result = $parallel->transform(42.0);
60  } catch (ConstraintViolationException $exception) {
61  return;
62  }
63 
64  $this->fail();
65  }
66 
67  public function testParallelApply()
68  {
69  $parallel = new Parallel(
70  array(
74  )
75  );
76 
77  $result = $parallel->applyTo(new Ok(42));
78 
79  $this->assertTrue($result->isError());
80  }
81 
83  {
84  $this->expectNotToPerformAssertions();
85 
86  try {
87  $parallel = new Parallel(
88  array(
90  'this is invalid'
91  )
92  );
93  } catch (ConstraintViolationException $exception) {
94  return;
95  }
96 
97  $this->fail();
98  }
99 }
$result
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:13