ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
NewMethodTransformationTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 use Error;
28 use TypeError;
30 
31 class 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 
116  public function testMethodThrowsExceptionInTransform(): void
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 
131  public function testMethodThrowsExceptionInApplyTo(): void
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: Ok.php:30
ilErrorHandling $error
Definition: class.ilias.php:69