ILIAS  release_7 Revision v7.30-3-g800a261c036
ILIAS\Tests\Setup\ObjectiveIteratorTest Class Reference
+ Inheritance diagram for ILIAS\Tests\Setup\ObjectiveIteratorTest:
+ Collaboration diagram for ILIAS\Tests\Setup\ObjectiveIteratorTest:

Public Member Functions

 testBasicAlgorithm ()
 
 testRewind ()
 
 testAllObjectives ()
 
 testAllObjectivesOnlyReturnsObjectiveOnce ()
 
 testAllObjectivesDetectsCycle ()
 
 testSetEnvironment ()
 
 testMarkFailed ()
 
 testFailedPreconditionWithOtherOnStack ()
 
 testFailedPreconditionLastOnStack ()
 

Protected Member Functions

 newObjective ($hash=null)
 

Detailed Description

Definition at line 11 of file ObjectiveIteratorTest.php.

Member Function Documentation

◆ newObjective()

ILIAS\Tests\Setup\ObjectiveIteratorTest::newObjective (   $hash = null)
protected

Definition at line 209 of file ObjectiveIteratorTest.php.

209 : MockObject
210 {
211 static $no = 0;
212
213 $objective = $this
214 ->getMockBuilder(Setup\Objective::class)
215 ->setMethods(["getHash", "getLabel", "isNotable", "withResourcesFrom", "getPreconditions", "achieve", "isApplicable"])
216 ->setMockClassName("Mock_ObjectiveNo" . ($no++))
217 ->getMock();
218
219 $objective
220 ->method("getHash")
221 ->willReturn($hash ?? "" . $no);
222
223 return $objective;
224 }

Referenced by ILIAS\Tests\Setup\ObjectiveIteratorTest\testAllObjectives(), ILIAS\Tests\Setup\ObjectiveIteratorTest\testAllObjectivesDetectsCycle(), ILIAS\Tests\Setup\ObjectiveIteratorTest\testAllObjectivesOnlyReturnsObjectiveOnce(), ILIAS\Tests\Setup\ObjectiveIteratorTest\testBasicAlgorithm(), ILIAS\Tests\Setup\ObjectiveIteratorTest\testFailedPreconditionLastOnStack(), ILIAS\Tests\Setup\ObjectiveIteratorTest\testFailedPreconditionWithOtherOnStack(), ILIAS\Tests\Setup\ObjectiveIteratorTest\testMarkFailed(), ILIAS\Tests\Setup\ObjectiveIteratorTest\testRewind(), and ILIAS\Tests\Setup\ObjectiveIteratorTest\testSetEnvironment().

+ Here is the caller graph for this function:

◆ testAllObjectives()

ILIAS\Tests\Setup\ObjectiveIteratorTest::testAllObjectives ( )

Definition at line 58 of file ObjectiveIteratorTest.php.

58 : void
59 {
60 $environment = $this->createMock(Setup\Environment::class);
61
62 $objective1 = $this->newObjective();
63 $objective11 = $this->newObjective();
64 $objective12 = $this->newObjective();
65 $objective121 = $this->newObjective();
66
67 $objective1
68 ->method("getPreconditions")
69 ->with($environment)
70 ->willReturn([$objective11, $objective12]);
71
72 $objective11
73 ->method("getPreconditions")
74 ->with($environment)
75 ->willReturn([]);
76
77 $objective12
78 ->method("getPreconditions")
79 ->with($environment)
80 ->willReturn([$objective121]);
81
82 $objective121
83 ->method("getPreconditions")
84 ->with($environment)
85 ->willReturn([]);
86
87 $iterator = new Setup\ObjectiveIterator($environment, $objective1);
88
89 $expected = [
90 $objective11->getHash() => $objective11,
91 $objective121->getHash() => $objective121,
92 $objective12->getHash() => $objective12,
93 $objective1->getHash() => $objective1
94 ];
95
96 $this->assertEquals($expected, iterator_to_array($iterator));
97 }

References ILIAS\Tests\Setup\ObjectiveIteratorTest\newObjective().

+ Here is the call graph for this function:

◆ testAllObjectivesDetectsCycle()

ILIAS\Tests\Setup\ObjectiveIteratorTest::testAllObjectivesDetectsCycle ( )

Definition at line 125 of file ObjectiveIteratorTest.php.

125 : void
126 {
127 $environment = $this->createMock(Setup\Environment::class);
128
129 $objective1 = $this->newObjective();
130 $objective2 = $this->newObjective();
131
132 $objective1
133 ->method("getPreconditions")
134 ->with($environment)
135 ->willReturn([$objective2]);
136
137 $objective2
138 ->method("getPreconditions")
139 ->with($environment)
140 ->willReturn([$objective1]);
141
142 $this->expectException(Setup\UnachievableException::class);
143
144 $iterator = new Setup\ObjectiveIterator($environment, $objective1);
145 iterator_to_array($iterator);
146 }

References ILIAS\Tests\Setup\ObjectiveIteratorTest\newObjective().

+ Here is the call graph for this function:

◆ testAllObjectivesOnlyReturnsObjectiveOnce()

ILIAS\Tests\Setup\ObjectiveIteratorTest::testAllObjectivesOnlyReturnsObjectiveOnce ( )

Definition at line 99 of file ObjectiveIteratorTest.php.

99 : void
100 {
101 $environment = $this->createMock(Setup\Environment::class);
102
103 $objective1 = $this->newObjective();
104 $objective11 = $this->newObjective();
105
106 $objective1
107 ->method("getPreconditions")
108 ->with($environment)
109 ->willReturn([$objective11, $objective11]);
110
111 $objective11
112 ->method("getPreconditions")
113 ->with($environment)
114 ->willReturn([]);
115
116 $iterator = new Setup\ObjectiveIterator($environment, $objective1);
117
118 $expected = [
119 $objective11->getHash() => $objective11,
120 $objective1->getHash() => $objective1
121 ];
122 $this->assertEquals($expected, iterator_to_array($iterator));
123 }

References ILIAS\Tests\Setup\ObjectiveIteratorTest\newObjective().

+ Here is the call graph for this function:

◆ testBasicAlgorithm()

ILIAS\Tests\Setup\ObjectiveIteratorTest::testBasicAlgorithm ( )

Definition at line 13 of file ObjectiveIteratorTest.php.

13 : void
14 {
15 $hash = "my hash";
16 $objective = $this->newObjective($hash);
17 $environment = $this->createMock(Setup\Environment::class);
18
19 $objective
20 ->expects($this->once())
21 ->method("getPreconditions")
22 ->with($environment)
23 ->willReturn([]);
24
25 $iterator = new Setup\ObjectiveIterator($environment, $objective);
26
27 $this->assertTrue($iterator->valid());
28 $this->assertSame($objective, $iterator->current());
29 $this->assertSame($hash, $iterator->key());
30
31 $iterator->next();
32
33 $this->assertFalse($iterator->valid());
34 }

References ILIAS\Tests\Setup\ObjectiveIteratorTest\newObjective().

+ Here is the call graph for this function:

◆ testFailedPreconditionLastOnStack()

ILIAS\Tests\Setup\ObjectiveIteratorTest::testFailedPreconditionLastOnStack ( )

Definition at line 263 of file ObjectiveIteratorTest.php.

263 : void
264 {
265 $this->expectException(Setup\UnachievableException::class);
266
267 $env = new Setup\ArrayEnvironment([]);
268
269 $objective_fail = $this->newObjective();
270 $objective_1 = $this->newObjective();
271 $objective_2 = $this->newObjective();
272
273 $objective_1
274 ->method("getPreconditions")
275 ->willReturn([$objective_fail]);
276 $objective_2
277 ->method("getPreconditions")
278 ->willReturn([$objective_1]);
279
280 $iterator = new class($env, $objective_2, $objective_fail) extends Setup\ObjectiveIterator {
281 public function __construct(
282 Setup\Environment $environment,
283 Setup\Objective $objective,
284 MockObject $objective_fail
285 ) {
286 parent::__construct($environment, $objective);
287 $this->failed[$objective_fail->getHash()] = true;
288 }
289 };
290
291 $this->assertEquals($objective_fail, $iterator->current());
292 $iterator->next();
293 }
__construct($a_client_id=0)
Constructor setup ILIAS global object @access public.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References ILIAS\__construct(), ILIAS\GlobalScreen\Provider\__construct(), and ILIAS\Tests\Setup\ObjectiveIteratorTest\newObjective().

+ Here is the call graph for this function:

◆ testFailedPreconditionWithOtherOnStack()

ILIAS\Tests\Setup\ObjectiveIteratorTest::testFailedPreconditionWithOtherOnStack ( )

Definition at line 226 of file ObjectiveIteratorTest.php.

226 : void
227 {
228 $this->expectException(Setup\UnachievableException::class);
229
230 $env = new Setup\ArrayEnvironment([]);
231
232 $objective_fail = $this->newObjective();
233 $objective_1 = $this->newObjective();
234 $objective_2 = $this->newObjective();
235 $objective_3 = $this->newObjective();
236
237 $objective_1
238 ->method("getPreconditions")
239 ->willReturn([$objective_fail]);
240 $objective_2
241 ->method("getPreconditions")
242 ->willReturn([]);
243 $objective_3
244 ->method("getPreconditions")
245 ->willReturn([$objective_1, $objective_2]);
246
247 $iterator = new class($env, $objective_3, $objective_fail) extends Setup\ObjectiveIterator {
248 public function __construct(
249 Setup\Environment $environment,
250 Setup\Objective $objective,
251 MockObject $objective_fail
252 ) {
253 parent::__construct($environment, $objective);
254 $this->failed[$objective_fail->getHash()] = true;
255 }
256 };
257
258 $this->assertEquals($objective_fail, $iterator->current());
259 $iterator->next();
260 $iterator->next();
261 }

References ILIAS\__construct(), ILIAS\GlobalScreen\Provider\__construct(), and ILIAS\Tests\Setup\ObjectiveIteratorTest\newObjective().

+ Here is the call graph for this function:

◆ testMarkFailed()

ILIAS\Tests\Setup\ObjectiveIteratorTest::testMarkFailed ( )

Definition at line 174 of file ObjectiveIteratorTest.php.

174 : void
175 {
176 $this->expectException(Setup\UnachievableException::class);
177
178 $env = new Setup\ArrayEnvironment([]);
179
180 $objective_fail = $this->newObjective();
181 $objective_1 = $this->newObjective();
182 $objective_2 = $this->newObjective();
183 $objective_3 = $this->newObjective();
184
185 $objective_1
186 ->method("getPreconditions")
187 ->willReturn([]);
188
189 $objective_2
190 ->method("getPreconditions")
191 ->willReturn([]);
192
193 $objective_3
194 ->method("getPreconditions")
195 ->willReturn([$objective_1, $objective_fail, $objective_2]);
196
197 $iterator = new Setup\ObjectiveIterator($env, $objective_3);
198
199
200 $this->assertEquals($objective_1, $iterator->current());
201 $iterator->next();
202 $this->assertEquals($objective_fail, $iterator->current());
203 $iterator->markAsFailed($objective_fail);
204 $iterator->next();
205 $this->assertEquals($objective_2, $iterator->current());
206 $iterator->next();
207 }

References ILIAS\Tests\Setup\ObjectiveIteratorTest\newObjective().

+ Here is the call graph for this function:

◆ testRewind()

ILIAS\Tests\Setup\ObjectiveIteratorTest::testRewind ( )

Definition at line 36 of file ObjectiveIteratorTest.php.

36 : void
37 {
38 $hash = "my hash";
39 $objective = $this->newObjective($hash);
40 $environment = $this->createMock(Setup\Environment::class);
41
42 $iterator = new Setup\ObjectiveIterator($environment, $objective);
43
44 $objective
45 ->expects($this->once())
46 ->method("getPreconditions")
47 ->with($environment)
48 ->willReturn([]);
49
50 $iterator->next();
51 $iterator->rewind();
52
53 $this->assertTrue($iterator->valid());
54 $this->assertSame($objective, $iterator->current());
55 $this->assertSame($hash, $iterator->key());
56 }

References ILIAS\Tests\Setup\ObjectiveIteratorTest\newObjective().

+ Here is the call graph for this function:

◆ testSetEnvironment()

ILIAS\Tests\Setup\ObjectiveIteratorTest::testSetEnvironment ( )

Definition at line 148 of file ObjectiveIteratorTest.php.

148 : void
149 {
150 $env1 = new Setup\ArrayEnvironment([]);
151 $env2 = new Setup\ArrayEnvironment([]);
152
153 $objective1 = $this->newObjective();
154 $objective2 = $this->newObjective();
155
156 $objective1
157 ->expects($this->atLeastOnce())
158 ->method("getPreconditions")
159 ->with($env1)
160 ->willReturn([$objective2]);
161
162 $objective2
163 ->expects($this->atLeastOnce())
164 ->method("getPreconditions")
165 ->with($env2)
166 ->willReturn([]);
167
168 $iterator = new Setup\ObjectiveIterator($env1, $objective1);
169
170 $iterator->setEnvironment($env2);
171 $iterator->next();
172 }

References ILIAS\Tests\Setup\ObjectiveIteratorTest\newObjective().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: