ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
NewMethodTransformationTest.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 
16 
17 require_once('./libs/composer/vendor/autoload.php');
18 
20 {
21  private $instance;
22 
23  public function setUp() : void
24  {
25  $this->instance = new NewMethodTransformationTestClass();
26  }
27 
32  public function testNewObjectTransformation()
33  {
34  $transformation = new NewMethodTransformation(new NewMethodTransformationTestClass(), 'myMethod');
35 
36  $result = $transformation->transform(array('hello', 42));
37 
38  $this->assertEquals(array('hello', 42), $result);
39  }
40 
42  {
43  $this->expectNotToPerformAssertions();
44 
45  $transformation = new NewMethodTransformation(new NewMethodTransformationTestClass(), 'myMethod');
46 
47  try {
48  $object = $transformation->transform(array('hello', 'world'));
49  } catch (\TypeError $exception) {
50  return;
51  }
52 
53  $this->fail();
54  }
55 
57  {
58  $this->expectNotToPerformAssertions();
59 
60  try {
61  $transformation = new NewMethodTransformation('BreakdanceMcFunkyPants', 'myMethod');
62  } catch (\Error $exception) {
63  return;
64  }
65 
66  $this->fail();
67  }
68 
70  {
71  $this->expectNotToPerformAssertions();
72 
73  try {
74  $transformation = new NewMethodTransformation(new NewMethodTransformationTestClass(), 'someMethod');
75  } catch (\InvalidArgumentException $exception) {
76  return;
77  }
78 
79  $this->fail();
80  }
81 
83  {
84  $this->expectNotToPerformAssertions();
85 
86  $transformation = new NewMethodTransformation(new NewMethodTransformationTestClass(), 'myPrivateMethod');
87 
88  try {
89  $object = $transformation->transform(array('hello', 10));
90  } catch (\Error $error) {
91  return;
92  }
93 
94  $this->fail();
95  }
96 
98  {
99  $this->expectNotToPerformAssertions();
100 
101  $transformation = new NewMethodTransformation(new NewMethodTransformationTestClass(), 'myPrivateMethod');
102  try {
103  $object = $transformation->applyTo(new Ok(array('hello', 10)));
104  } catch (\Error $error) {
105  return;
106  }
107 
108  $this->fail();
109  }
110 
112  {
113  $this->expectNotToPerformAssertions();
114 
115  $transformation = new NewMethodTransformation(new NewMethodTransformationTestClass(), 'methodThrowsException');
116 
117  try {
118  $object = $transformation->transform(array('hello', 10));
119  } catch (\Exception $exception) {
120  return;
121  }
122 
123  $this->fail();
124  }
125 
127  {
128  $transformation = new NewMethodTransformation(new NewMethodTransformationTestClass(), 'methodThrowsException');
129 
130  $object = $transformation->applyTo(new Ok(array('hello', 10)));
131 
132  $this->assertTrue($object->isError());
133  }
134 }
135 
137 {
138  public function myMethod(string $string, int $integer)
139  {
140  return array($string, $integer);
141  }
142 
143  private function myPrivateMethod(string $string, int $integer)
144  {
145  return array($string, $integer);
146  }
147 
148  public function methodThrowsException(string $string, int $integer)
149  {
150  throw new \Exception('SomeException');
151  }
152 }
$result
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:13
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Error.php:13