ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ServicesTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use PHPUnit\Framework\TestCase;
25use ILIAS\MetaData\Services\Reader\FactoryInterface as ReaderFactoryInterface;
26use ILIAS\MetaData\Services\Manipulator\FactoryInterface as ManipulatorFactoryInterface;
31use ILIAS\MetaData\Services\Reader\NullFactory as NullReaderFactory;
34use ILIAS\MetaData\Services\Manipulator\NullFactory as NullManipulatorFactory;
38
39class ServicesTest extends TestCase
40{
41 protected function getServices(): Services
42 {
43 return new class () extends Services {
44 public array $repositories = [];
45
46 public function __construct()
47 {
48 }
49
50 protected function repository(): RepositoryInterface
51 {
52 return $this->repositories[] = new class () extends NullRepository {
53 public array $deleted_md = [];
54
55 public function getMD(int $obj_id, int $sub_id, string $type): SetInterface
56 {
57 return new class ($obj_id, $sub_id, $type) extends NullSet {
58 public array $data;
59
60 public function __construct(int $obj_id, int $sub_id, string $type)
61 {
62 $this->data = [
63 'obj_id' => $obj_id,
64 'sub_id' => $sub_id,
65 'type' => $type,
66 ];
67 }
68 };
69 }
70
71 public function getMDOnPath(
73 int $obj_id,
74 int $sub_id,
75 string $type
76 ): SetInterface {
77 return new class ($path, $obj_id, $sub_id, $type) extends NullSet {
78 public array $data;
79
80 public function __construct(PathInterface $path, int $obj_id, int $sub_id, string $type)
81 {
82 $this->data = [
83 'path' => $path,
84 'obj_id' => $obj_id,
85 'sub_id' => $sub_id,
86 'type' => $type,
87 ];
88 }
89 };
90 }
91
92 public function deleteAllMD(int $obj_id, int $sub_id, string $type): void
93 {
94 $this->deleted_md[] = [
95 'obj_id' => $obj_id,
96 'sub_id' => $sub_id,
97 'type' => $type
98 ];
99 }
100 };
101 }
102
103 protected function readerFactory(): ReaderFactoryInterface
104 {
105 return new class () extends NullReaderFactory {
106 public function get(SetInterface $set): ReaderInterface
107 {
108 return new class ($set) extends NullReader {
109 public function __construct(public SetInterface $set)
110 {
111 }
112 };
113 }
114 };
115 }
116
117 protected function manipulatorFactory(): ManipulatorFactoryInterface
118 {
119 return new class () extends NullManipulatorFactory {
120 public function get(SetInterface $set): ManipulatorInterface
121 {
122 return new class ($set) extends NullManipulator {
123 public function __construct(public SetInterface $set)
124 {
125 }
126 };
127 }
128 };
129 }
130 };
131 }
132
133 public function testRead(): void
134 {
135 $services = $this->getServices();
136 $reader = $services->read(5, 17, 'type');
137
138 $this->assertSame(
139 ['obj_id' => 5, 'sub_id' => 17, 'type' => 'type'],
140 $reader->set->data
141 );
142 }
143
144 public function testReadWithPath(): void
145 {
146 $services = $this->getServices();
147 $path = new NullPath();
148 $reader = $services->read(5, 17, 'type', $path);
149
150 $this->assertSame(
151 ['path' => $path, 'obj_id' => 5, 'sub_id' => 17, 'type' => 'type'],
152 $reader->set->data
153 );
154 }
155
156 public function testReadWithSubIDZero(): void
157 {
158 $services = $this->getServices();
159 $reader = $services->read(23, 0, 'type');
160
161 $this->assertSame(
162 ['obj_id' => 23, 'sub_id' => 23, 'type' => 'type'],
163 $reader->set->data
164 );
165 }
166
167 public function testManipulate(): void
168 {
169 $services = $this->getServices();
170 $manipulator = $services->manipulate(5, 17, 'type');
171
172 $this->assertSame(
173 ['obj_id' => 5, 'sub_id' => 17, 'type' => 'type'],
174 $manipulator->set->data
175 );
176 }
177
178 public function testManipulateWithSubIDZero(): void
179 {
180 $services = $this->getServices();
181 $manipulator = $services->manipulate(35, 0, 'type');
182
183 $this->assertSame(
184 ['obj_id' => 35, 'sub_id' => 35, 'type' => 'type'],
185 $manipulator->set->data
186 );
187 }
188
189 public function testDeleteAll(): void
190 {
191 $services = $this->getServices();
192 $services->deleteAll(34, 90, 'type');
193
194 $this->assertCount(1, $services->repositories);
195 $this->assertCount(1, $services->repositories[0]->deleted_md);
196 $this->assertSame(
197 ['obj_id' => 34, 'sub_id' => 90, 'type' => 'type'],
198 $services->repositories[0]->deleted_md[0]
199 );
200 }
201
202 public function testDeleteAllWithSubIDZero(): void
203 {
204 $services = $this->getServices();
205 $services->deleteAll(789, 0, 'type');
206
207 $this->assertCount(1, $services->repositories);
208 $this->assertCount(1, $services->repositories[0]->deleted_md);
209 $this->assertSame(
210 ['obj_id' => 789, 'sub_id' => 789, 'type' => 'type'],
211 $services->repositories[0]->deleted_md[0]
212 );
213 }
214}
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:76
$path
Definition: ltiservices.php:30