ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
TupleTransformationTest.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
15use ILIAS\Refinery\IsArrayOfSameType;
17
18require_once('./libs/composer/vendor/autoload.php');
19
21{
26 {
27 $transformation = new TupleTransformation(
29 );
30
31 $result = $transformation->transform(array(1, 2));
32
33 $this->assertEquals(array(1, 2), $result);
34 }
35
37 {
38 $this->expectNotToPerformAssertions();
39
40 $transformation = new TupleTransformation(
42 );
43
44 try {
45 $result = $transformation->transform(array(1, 2));
46 } catch (ConstraintViolationException $exception) {
47 return;
48 }
49
50 $this->fail();
51 }
52
54 {
55 $this->expectNotToPerformAssertions();
56
57 $transformation = new TupleTransformation(
58 array(new IntegerTransformation(), 'hello' => new IntegerTransformation())
59 );
60
61 try {
62 $result = $transformation->transform(array(1, 2));
63 } catch (ConstraintViolationException $exception) {
64 return;
65 }
66
67 $this->fail();
68 }
69
70
72 {
73 $this->expectNotToPerformAssertions();
74
75 $transformation = new TupleTransformation(
77 );
78
79 try {
80 $result = $transformation->transform(array(1, 2, 3));
81 } catch (ConstraintViolationException $exception) {
82 return;
83 }
84 $this->fail();
85 }
86
88 {
89 $transformation = new TupleTransformation(
91 );
92
93 $result = $transformation->applyTo(new Result\Ok(array(1, 2)));
94
95 $this->assertEquals(array(1, 2), $result->value());
96 }
97
99 {
100 $transformation = new TupleTransformation(
102 );
103
104 $result = $transformation->applyTo(new Result\Ok(array(1, 2)));
105
106 $this->assertTrue($result->isError());
107 }
108
109 public function testToManyValuesForApply()
110 {
111 $transformation = new TupleTransformation(
113 );
114
115 $result = $transformation->applyTo(new Result\Ok(array(1, 2, 3)));
116
117 $this->assertTrue($result->isError());
118 }
119
121 {
122 $this->expectNotToPerformAssertions();
123
124 try {
125 $transformation = new TupleTransformation(
126 array(new IntegerTransformation(), 'hello')
127 );
128 } catch (ConstraintViolationException $exception) {
129 return;
130 }
131
132
133 $this->fail();
134 }
135}
$result
An exception for terminatinating execution or to throw for unit testing.
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:14
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:12