ILIAS  release_7 Revision v7.30-3-g800a261c036
NewObjectTransformationTest.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
13
14require_once('./libs/composer/vendor/autoload.php');
15
17{
22 {
23 $transformation = new NewObjectTransformation(MyClass::class);
24
25 $object = $transformation->transform(array('hello', 42));
26
27 $result = $object->myMethod();
28
29 $this->assertEquals(array('hello', 42), $result);
30 }
31
33 {
34 $this->expectNotToPerformAssertions();
35
36 $transformation = new NewObjectTransformation(MyClass::class);
37
38 try {
39 $object = $transformation->transform(array('hello', 'world'));
40 } catch (\TypeError $exception) {
41 return;
42 }
43
44 $this->fail();
45 }
46
50 public function testNewObjectApply()
51 {
52 $transformation = new NewObjectTransformation(MyClass::class);
53
54 $resultObject = $transformation->applyTo(new Ok(array('hello', 42)));
55
56 $object = $resultObject->value();
57
58 $result = $object->myMethod();
59
60 $this->assertEquals(array('hello', 42), $result);
61 }
62
64 {
65 $this->expectNotToPerformAssertions();
66
67 $transformation = new NewObjectTransformation(MyClass::class);
68
69 try {
70 $resultObject = $transformation->applyTo(new Ok(array('hello', 'world')));
71 } catch (\Error $error) {
72 return;
73 }
74
75 $this->fail();
76 }
77
79 {
80 $transformation = new NewObjectTransformation(MyClassThrowsException::class);
81
82 $resultObject = $transformation->applyTo(new Ok(array('hello', 100)));
83
84 $this->assertTrue($resultObject->isError());
85 }
86
88 {
89 $this->expectNotToPerformAssertions();
90
91 $transformation = new NewObjectTransformation(MyClassThrowsException::class);
92
93 try {
94 $resultObject = $transformation->transform(array('hello', 100));
95 } catch (\Exception $exception) {
96 return;
97 }
98
99 $this->fail();
100 }
101}
102
104{
105 private $string;
106
107 private $integer;
108
109 public function __construct(string $string, int $integer)
110 {
111 $this->string = $string;
112 $this->integer = $integer;
113 }
114
115 public function myMethod()
116 {
117 return array($this->string, $this->integer);
118 }
119}
120
122{
123 public function __construct(string $string, int $integer)
124 {
125 throw new \Exception();
126 }
127}
$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: Error.php:14
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:14