ILIAS  release_7 Revision v7.30-3-g800a261c036
DictionaryTransformationTest.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
16require_once('./libs/composer/vendor/autoload.php');
17
19{
24 {
25 $transformation = new DictionaryTransformation(new StringTransformation());
26
27 $result = $transformation->transform(array('hello' => 'world'));
28
29 $this->assertEquals(array('hello' => 'world'), $result);
30 }
31
33 {
34 $this->expectNotToPerformAssertions();
35
36 $transformation = new DictionaryTransformation(new StringTransformation());
37
38 try {
39 $result = $transformation->transform(array('world'));
40 } catch (ConstraintViolationException $exception) {
41 return;
42 }
43
44 $this->fail();
45 }
46
48 {
49 $this->expectNotToPerformAssertions();
50
51 $transformation = new DictionaryTransformation(new StringTransformation());
52
53 try {
54 $result = $transformation->transform(array('hello' => 1));
55 } catch (ConstraintViolationException $exception) {
56 return;
57 }
58
59 $this->fail();
60 }
61
63 {
64 $this->expectNotToPerformAssertions();
65
66 $transformation = new DictionaryTransformation(new StringTransformation());
67
68 try {
69 $result = $transformation->transform(1);
70 } catch (ConstraintViolationException $exception) {
71 return;
72 }
73
74 $this->fail();
75 }
76
77 public function testDictionaryApplyValid()
78 {
79 $transformation = new DictionaryTransformation(new StringTransformation());
80
81 $result = $transformation->applyTo(new Ok(array('hello' => 'world')));
82
83 $this->assertEquals(array('hello' => 'world'), $result->value());
84 }
85
87 {
88 $transformation = new DictionaryTransformation(new StringTransformation());
89
90 $result = $transformation->applyTo(new Ok(array('world')));
91
92 $this->assertTrue($result->isError());
93 }
94
96 {
97 $transformation = new DictionaryTransformation(new StringTransformation());
98
99 $result = $transformation->applyTo(new Ok(array('hello' => 1)));
100
101 $this->assertTrue($result->isError());
102 }
103
105 {
106 $transformation = new DictionaryTransformation(new StringTransformation());
107
108 $result = $transformation->applyTo(new Ok(1));
109
110 $this->assertTrue($result->isError());
111 }
112}
$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