ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
GroupTest.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 
24 
25 require_once('./libs/composer/vendor/autoload.php');
26 
27 class GroupTest extends TestCase
28 {
32  private $basicGroup;
33 
34  public function setUp() : void
35  {
36  $this->basicGroup = new Group(new \ILIAS\Data\Factory());
37  }
38 
40  {
41  $transformation = $this->basicGroup->int();
42 
43  $this->assertInstanceOf(IntegerTransformation::class, $transformation);
44  }
45 
47  {
48  $transformation = $this->basicGroup->string();
49 
50  $this->assertInstanceOf(StringTransformation::class, $transformation);
51  }
52 
54  {
55  $transformation = $this->basicGroup->float();
56 
57  $this->assertInstanceOf(FloatTransformation::class, $transformation);
58  }
59 
61  {
62  $transformation = $this->basicGroup->bool();
63 
64  $this->assertInstanceOf(BooleanTransformation::class, $transformation);
65  }
66 
67  public function testListOfTransformation()
68  {
69  $transformation = $this->basicGroup->listOf(new StringTransformation());
70 
71  $this->assertInstanceOf(ListTransformation::class, $transformation);
72  }
73 
74  public function testTupleOfTransformation()
75  {
76  $transformation = $this->basicGroup->tupleOf(array(new StringTransformation()));
77 
78  $this->assertInstanceOf(TupleTransformation::class, $transformation);
79  }
80 
84  public function testRecordOfTransformation()
85  {
86  $transformation = $this->basicGroup->recordOf(array('toString' => new StringTransformation()));
87 
88  $this->assertInstanceOf(RecordTransformation::class, $transformation);
89  }
90 
92  {
93  $transformation = $this->basicGroup->dictOf(new StringTransformation());
94 
95  $this->assertInstanceOf(DictionaryTransformation::class, $transformation);
96  }
97 
101  public function testNewObjectTransformation()
102  {
103  $transformation = $this->basicGroup->toNew((string) MyClass::class);
104 
105  $this->assertInstanceOf(NewObjectTransformation::class, $transformation);
106  }
107 
111  public function testNewMethodTransformation()
112  {
113  $transformation = $this->basicGroup->toNew(array(new MyClass(), 'myMethod'));
114 
115  $this->assertInstanceOf(NewMethodTransformation::class, $transformation);
116  }
117 
119  {
120  $this->expectNotToPerformAssertions();
121 
122  try {
123  $transformation = $this->basicGroup->toNew(array(new MyClass(), 'myMethod', 'hello'));
124  } catch (\InvalidArgumentException $exception) {
125  return;
126  }
127 
128  $this->fail();
129  }
130 
132  {
133  $this->expectNotToPerformAssertions();
134 
135  try {
136  $transformation = $this->basicGroup->toNew(array(new MyClass()));
137  } catch (\InvalidArgumentException $exception) {
138  return;
139  }
140 
141  $this->fail();
142  }
143 
148  {
149  $transformation = $this->basicGroup->data('alphanumeric');
150 
151  $this->assertInstanceOf(NewMethodTransformation::class, $transformation);
152 
153  $result = $transformation->transform(array('hello'));
154 
155  $this->assertInstanceOf(Alphanumeric::class, $result);
156  }
157 }
158 
159 class MyClass
160 {
161  public function myMethod()
162  {
163  return array($this->string, $this->integer);
164  }
165 }
$result
Class ChatMainBarProvider .
testNewMethodTransformationThrowsExceptionBecauseToManyParametersAreGiven()
Definition: GroupTest.php:118
testNewMethodTransformationThrowsExceptionBecauseToFewParametersAreGiven()
Definition: GroupTest.php:131