ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
AddLabelTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\Refinery\Factory as Refinery;
23use PHPUnit\Framework\TestCase;
24use ILIAS\Data\Factory as DataFactory;
25
26class AddLabelTest extends TestCase
27{
29 private static array $labels = ["A", "B", "C"];
31 private static array $test_array = [1, 2, 3];
33 private static array $result_array = ["A" => 1, "B" => 2, "C" => 3];
34
35 private ?Refinery $f;
37
38 protected function setUp(): void
39 {
40 $dataFactory = new DataFactory();
41 $language = $this->createMock(ILIAS\Language\Language::class);
42
43 $this->f = new Refinery($dataFactory, $language);
44 $this->add_label = $this->f->container()->addLabels(self::$labels);
45 }
46
47 protected function tearDown(): void
48 {
49 $this->f = null;
50 $this->add_label = null;
51 }
52
53 public function testTransform(): void
54 {
55 $with = $this->add_label->transform(self::$test_array);
56 $this->assertEquals(self::$result_array, $with);
57 }
58
59 public function testTransformFails(): void
60 {
61 $raised = false;
62 try {
63 $with = null;
64 $next_with = $this->add_label->transform($with);
65 } catch (InvalidArgumentException $e) {
66 $raised = true;
67 }
68 $this->assertTrue($raised);
69
70 $raised = false;
71 try {
72 $without = [1, 2, 3, 4];
73 $with = $this->add_label->transform($without);
74 } catch (InvalidArgumentException $e) {
75 $raised = true;
76 }
77 $this->assertTrue($raised);
78
79 $raised = false;
80 try {
81 $without = "1, 2, 3";
82 $with = $this->add_label->transform($without);
83 } catch (InvalidArgumentException $e) {
84 $raised = true;
85 }
86 $this->assertTrue($raised);
87
88 $raised = false;
89 try {
90 $std_class = new stdClass();
91 $with = $this->add_label->transform($std_class);
92 } catch (InvalidArgumentException $e) {
93 $raised = true;
94 }
95 $this->assertTrue($raised);
96 }
97
98 public function testInvoke(): void
99 {
100 $add_label = $this->f->container()->addLabels(self::$labels);
101 $with = $add_label(self::$test_array);
102 $this->assertEquals(self::$result_array, $with);
103 }
104
105 public function testInvokeFails(): void
106 {
107 $add_label = $this->f->container()->addLabels(self::$labels);
108
109 $raised = false;
110 try {
111 $with = null;
112 $next_with = $add_label($with);
113 } catch (InvalidArgumentException $e) {
114 $raised = true;
115 }
116 $this->assertTrue($raised);
117
118 $raised = false;
119 try {
120 $without = [1, 2, 3, 4];
121 $with = $add_label($without);
122 } catch (InvalidArgumentException $e) {
123 $raised = true;
124 }
125 $this->assertTrue($raised);
126
127 $raised = false;
128 try {
129 $without = "1, 2, 3";
130 $with = $add_label($without);
131 } catch (InvalidArgumentException $e) {
132 $raised = true;
133 }
134 $this->assertTrue($raised);
135
136 $raised = false;
137 try {
138 $std_class = new stdClass();
139 $with = $add_label($std_class);
140 } catch (InvalidArgumentException $e) {
141 $raised = true;
142 }
143 $this->assertTrue($raised);
144 }
145}
static array $result_array
Refinery $f
static array $test_array
static array $labels
Transformation $add_label
Builds data types.
Definition: Factory.php:36
A transformation is a function from one datatype to another.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.