ILIAS  trunk Revision v11.0_alpha-1846-g895b5f47236
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
GroupTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
25 use ILIAS\Refinery\To\Group as ToGroup;
39 
40 class GroupTest extends TestCase
41 {
42  private ToGroup $basicGroup;
43 
44  protected function setUp(): void
45  {
46  $language = $this->getMockBuilder(Language::class)->disableOriginalConstructor()->getMock();
47  $this->basicGroup = new ToGroup(new DataFactory(), $language);
48  }
49 
50  public function testIsIntegerTransformationInstance(): void
51  {
52  $transformation = $this->basicGroup->int();
53 
54  $this->assertInstanceOf(IntegerTransformation::class, $transformation);
55  }
56 
57  public function testIsStringTransformationInstance(): void
58  {
59  $transformation = $this->basicGroup->string();
60 
61  $this->assertInstanceOf(StringTransformation::class, $transformation);
62  }
63 
64  public function testIsFloatTransformationInstance(): void
65  {
66  $transformation = $this->basicGroup->float();
67 
68  $this->assertInstanceOf(FloatTransformation::class, $transformation);
69  }
70 
71  public function testIsBooleanTransformationInstance(): void
72  {
73  $transformation = $this->basicGroup->bool();
74 
75  $this->assertInstanceOf(BooleanTransformation::class, $transformation);
76  }
77 
78  public function testListOfTransformation(): void
79  {
80  $transformation = $this->basicGroup->listOf(new StringTransformation());
81 
82  $this->assertInstanceOf(ListTransformation::class, $transformation);
83  }
84 
85  public function testTupleOfTransformation(): void
86  {
87  $transformation = $this->basicGroup->tupleOf([new StringTransformation()]);
88 
89  $this->assertInstanceOf(TupleTransformation::class, $transformation);
90  }
91 
95  public function testRecordOfTransformation(): void
96  {
97  $transformation = $this->basicGroup->recordOf(['toString' => new StringTransformation()]);
98 
99  $this->assertInstanceOf(RecordTransformation::class, $transformation);
100  }
101 
102  public function testDictionaryOfTransformation(): void
103  {
104  $transformation = $this->basicGroup->dictOf(new StringTransformation());
105 
106  $this->assertInstanceOf(DictionaryTransformation::class, $transformation);
107  }
108 
112  public function testNewObjectTransformation(): void
113  {
114  $transformation = $this->basicGroup->toNew(MyClass::class);
115 
116  $this->assertInstanceOf(NewObjectTransformation::class, $transformation);
117  }
118 
122  public function testNewMethodTransformation(): void
123  {
124  $transformation = $this->basicGroup->toNew([new MyClass(), 'myMethod']);
125 
126  $this->assertInstanceOf(NewMethodTransformation::class, $transformation);
127  }
128 
130  {
131  $this->expectNotToPerformAssertions();
132 
133  try {
134  $transformation = $this->basicGroup->toNew([new MyClass(), 'myMethod', 'hello']);
135  } catch (InvalidArgumentException $exception) {
136  return;
137  }
138 
139  $this->fail();
140  }
141 
143  {
144  $this->expectNotToPerformAssertions();
145 
146  try {
147  $transformation = $this->basicGroup->toNew([new MyClass()]);
148  } catch (InvalidArgumentException $exception) {
149  return;
150  }
151 
152  $this->fail();
153  }
154 
158  public function testCreateDataTransformation(): void
159  {
160  $transformation = $this->basicGroup->data('alphanumeric');
161 
162  $this->assertInstanceOf(NewMethodTransformation::class, $transformation);
163 
164  $result = $transformation->transform(['hello']);
165 
166  $this->assertInstanceOf(Alphanumeric::class, $result);
167  }
168 }
169 
170 class MyClass
171 {
172  public function myMethod(): array
173  {
174  return [$this->string, $this->integer];
175  }
176 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
testNewMethodTransformationThrowsExceptionBecauseToManyParametersAreGiven()
Definition: GroupTest.php:129
testNewMethodTransformationThrowsExceptionBecauseToFewParametersAreGiven()
Definition: GroupTest.php:142