ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
ListTransformationTest.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 
15 
16 require_once('./libs/composer/vendor/autoload.php');
17 
19 {
24  {
25  $listTransformation = new ListTransformation(new StringTransformation());
26 
27  $result = $listTransformation->transform(array('hello', 'world'));
28 
29  $this->assertEquals(array('hello', 'world'), $result);
30  }
31 
33  {
34  $listTransformation = new ListTransformation(new StringTransformation());
35  $this->assertSame([], $listTransformation->transform([]));
36  }
37 
39  {
40  $listTransformation = new ListTransformation(new StringTransformation());
41  $result = $listTransformation->applyTo(new Ok(array()));
42  $this->assertFalse($result->isError());
43  }
44 
45  public function testTransformOnNullFails()
46  {
47  $this->expectNotToPerformAssertions();
48 
49  $listTransformation = new ListTransformation(new StringTransformation());
50  try {
51  $result = $listTransformation->transform(null);
52  } catch (ConstraintViolationException $exception) {
53  return;
54  }
55 
56  $this->fail();
57  }
58 
59  public function testApplyToOnNullFails()
60  {
61  $listTransformation = new ListTransformation(new StringTransformation());
62  $result = $listTransformation->applyTo(new Ok(null));
63  $this->assertTrue($result->isError());
64  }
65 
66 
68  {
69  $this->expectNotToPerformAssertions();
70 
71  $listTransformation = new ListTransformation(new StringTransformation());
72 
73  try {
74  $result = $listTransformation->transform(array('hello', 2));
75  } catch (ConstraintViolationException $exception) {
76  return;
77  }
78 
79  $this->fail();
80  }
81 
82  public function testListApplyIsValid()
83  {
84  $listTransformation = new ListTransformation(new StringTransformation());
85 
86  $result = $listTransformation->applyTo(new Ok(array('hello', 'world')));
87 
88  $this->assertEquals(array('hello', 'world'), $result->value());
89  $this->assertTrue($result->isOK());
90  }
91 
92  public function testListApplyIsInvalid()
93  {
94  $listTransformation = new ListTransformation(new StringTransformation());
95 
96  $result = $listTransformation->applyTo(new Ok(array('hello', 2)));
97 
98  $this->assertTrue($result->isError());
99  }
100 }
$result
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:13