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