ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
NewMethodTransformationTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use Error;
27use PHPUnit\Framework\TestCase;
28use TypeError;
29use InvalidArgumentException;
30
31class NewMethodTransformationTest extends TestCase
32{
37 public function testNewObjectTransformation(): void
38 {
39 $transformation = new NewMethodTransformation(new NewMethodTransformationTestClass(), 'myMethod');
40
41 $result = $transformation->transform(['hello', 42]);
42
43 $this->assertEquals(['hello', 42], $result);
44 }
45
47 {
48 $this->expectNotToPerformAssertions();
49
50 $transformation = new NewMethodTransformation(new NewMethodTransformationTestClass(), 'myMethod');
51
52 try {
53 $object = $transformation->transform(['hello', 'world']);
54 } catch (TypeError $exception) {
55 return;
56 }
57
58 $this->fail();
59 }
60
62 {
63 $this->expectNotToPerformAssertions();
64
65 try {
66 $transformation = new NewMethodTransformation('BreakdanceMcFunkyPants', 'myMethod');
67 } catch (Error $exception) {
68 return;
69 }
70
71 $this->fail();
72 }
73
75 {
76 $this->expectNotToPerformAssertions();
77
78 try {
79 $transformation = new NewMethodTransformation(new NewMethodTransformationTestClass(), 'someMethod');
80 } catch (InvalidArgumentException $exception) {
81 return;
82 }
83
84 $this->fail();
85 }
86
88 {
89 $this->expectNotToPerformAssertions();
90
91 $transformation = new NewMethodTransformation(new NewMethodTransformationTestClass(), 'myPrivateMethod');
92
93 try {
94 $object = $transformation->transform(['hello', 10]);
95 } catch (Error $error) {
96 return;
97 }
98
99 $this->fail();
100 }
101
103 {
104 $this->expectNotToPerformAssertions();
105
106 $transformation = new NewMethodTransformation(new NewMethodTransformationTestClass(), 'myPrivateMethod');
107 try {
108 $object = $transformation->applyTo(new Ok(['hello', 10]));
109 } catch (Error $error) {
110 return;
111 }
112
113 $this->fail();
114 }
115
117 {
118 $this->expectNotToPerformAssertions();
119
120 $transformation = new NewMethodTransformation(new NewMethodTransformationTestClass(), 'methodThrowsException');
121
122 try {
123 $object = $transformation->transform(['hello', 10]);
124 } catch (Exception $exception) {
125 return;
126 }
127
128 $this->fail();
129 }
130
132 {
133 $transformation = new NewMethodTransformation(new NewMethodTransformationTestClass(), 'methodThrowsException');
134
135 $object = $transformation->applyTo(new Ok(['hello', 10]));
136
137 $this->assertTrue($object->isError());
138 }
139}
140
142{
143 public function myMethod(string $string, int $integer): array
144 {
145 return [$string, $integer];
146 }
147
148 private function myPrivateMethod(string $string, int $integer): array
149 {
150 return [$string, $integer];
151 }
152
153 public function methodThrowsException(string $string, int $integer): void
154 {
155 throw new Exception('SomeException');
156 }
157}
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Error.php:32
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:31
ilErrorHandling $error
Definition: class.ilias.php:69