ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 27 of file ObjectiveIteratorTest.php.

Member Function Documentation

◆ newObjective()

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

Definition at line 225 of file ObjectiveIteratorTest.php.

225 : MockObject
226 {
227 static $no = 0;
228
229 $objective = $this
230 ->getMockBuilder(Setup\Objective::class)
231 ->onlyMethods(["getHash", "getLabel", "isNotable", "getPreconditions", "achieve", "isApplicable"])
232 ->setMockClassName("Mock_ObjectiveNo" . ($no++))
233 ->getMock();
234
235 $objective
236 ->method("getHash")
237 ->willReturn($hash ?? "" . $no);
238
239 return $objective;
240 }

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 74 of file ObjectiveIteratorTest.php.

74 : void
75 {
76 $environment = $this->createMock(Setup\Environment::class);
77
78 $objective1 = $this->newObjective();
79 $objective11 = $this->newObjective();
80 $objective12 = $this->newObjective();
81 $objective121 = $this->newObjective();
82
83 $objective1
84 ->method("getPreconditions")
85 ->with($environment)
86 ->willReturn([$objective11, $objective12]);
87
88 $objective11
89 ->method("getPreconditions")
90 ->with($environment)
91 ->willReturn([]);
92
93 $objective12
94 ->method("getPreconditions")
95 ->with($environment)
96 ->willReturn([$objective121]);
97
98 $objective121
99 ->method("getPreconditions")
100 ->with($environment)
101 ->willReturn([]);
102
103 $iterator = new Setup\ObjectiveIterator($environment, $objective1);
104
105 $expected = [
106 $objective11->getHash() => $objective11,
107 $objective121->getHash() => $objective121,
108 $objective12->getHash() => $objective12,
109 $objective1->getHash() => $objective1
110 ];
111
112 $this->assertEquals($expected, iterator_to_array($iterator));
113 }

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

+ Here is the call graph for this function:

◆ testAllObjectivesDetectsCycle()

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

Definition at line 141 of file ObjectiveIteratorTest.php.

141 : void
142 {
143 $environment = $this->createMock(Setup\Environment::class);
144
145 $objective1 = $this->newObjective();
146 $objective2 = $this->newObjective();
147
148 $objective1
149 ->method("getPreconditions")
150 ->with($environment)
151 ->willReturn([$objective2]);
152
153 $objective2
154 ->method("getPreconditions")
155 ->with($environment)
156 ->willReturn([$objective1]);
157
158 $this->expectException(Setup\UnachievableException::class);
159
160 $iterator = new Setup\ObjectiveIterator($environment, $objective1);
161 iterator_to_array($iterator);
162 }

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

+ Here is the call graph for this function:

◆ testAllObjectivesOnlyReturnsObjectiveOnce()

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

Definition at line 115 of file ObjectiveIteratorTest.php.

115 : void
116 {
117 $environment = $this->createMock(Setup\Environment::class);
118
119 $objective1 = $this->newObjective();
120 $objective11 = $this->newObjective();
121
122 $objective1
123 ->method("getPreconditions")
124 ->with($environment)
125 ->willReturn([$objective11, $objective11]);
126
127 $objective11
128 ->method("getPreconditions")
129 ->with($environment)
130 ->willReturn([]);
131
132 $iterator = new Setup\ObjectiveIterator($environment, $objective1);
133
134 $expected = [
135 $objective11->getHash() => $objective11,
136 $objective1->getHash() => $objective1
137 ];
138 $this->assertEquals($expected, iterator_to_array($iterator));
139 }

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

+ Here is the call graph for this function:

◆ testBasicAlgorithm()

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

Definition at line 29 of file ObjectiveIteratorTest.php.

29 : void
30 {
31 $hash = "my hash";
32 $objective = $this->newObjective($hash);
33 $environment = $this->createMock(Setup\Environment::class);
34
35 $objective
36 ->expects($this->once())
37 ->method("getPreconditions")
38 ->with($environment)
39 ->willReturn([]);
40
41 $iterator = new Setup\ObjectiveIterator($environment, $objective);
42
43 $this->assertTrue($iterator->valid());
44 $this->assertSame($objective, $iterator->current());
45 $this->assertSame($hash, $iterator->key());
46
47 $iterator->next();
48
49 $this->assertFalse($iterator->valid());
50 }

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

+ Here is the call graph for this function:

◆ testFailedPreconditionLastOnStack()

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

Definition at line 279 of file ObjectiveIteratorTest.php.

279 : void
280 {
281 $this->expectException(Setup\UnachievableException::class);
282
283 $env = new Setup\ArrayEnvironment([]);
284
285 $objective_fail = $this->newObjective();
286 $objective_1 = $this->newObjective();
287 $objective_2 = $this->newObjective();
288
289 $objective_1
290 ->method("getPreconditions")
291 ->willReturn([$objective_fail]);
292 $objective_2
293 ->method("getPreconditions")
294 ->willReturn([$objective_1]);
295
296 $iterator = new class ($env, $objective_2, $objective_fail) extends Setup\ObjectiveIterator {
297 public function __construct(
298 Setup\Environment $environment,
299 Setup\Objective $objective,
300 MockObject $objective_fail
301 ) {
302 parent::__construct($environment, $objective);
303 $this->failed[$objective_fail->getHash()] = true;
304 }
305 };
306
307 $this->assertEquals($objective_fail, $iterator->current());
308 $iterator->next();
309 }
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:76
__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 242 of file ObjectiveIteratorTest.php.

242 : void
243 {
244 $this->expectException(Setup\UnachievableException::class);
245
246 $env = new Setup\ArrayEnvironment([]);
247
248 $objective_fail = $this->newObjective();
249 $objective_1 = $this->newObjective();
250 $objective_2 = $this->newObjective();
251 $objective_3 = $this->newObjective();
252
253 $objective_1
254 ->method("getPreconditions")
255 ->willReturn([$objective_fail]);
256 $objective_2
257 ->method("getPreconditions")
258 ->willReturn([]);
259 $objective_3
260 ->method("getPreconditions")
261 ->willReturn([$objective_1, $objective_2]);
262
263 $iterator = new class ($env, $objective_3, $objective_fail) extends Setup\ObjectiveIterator {
264 public function __construct(
265 Setup\Environment $environment,
266 Setup\Objective $objective,
267 MockObject $objective_fail
268 ) {
269 parent::__construct($environment, $objective);
270 $this->failed[$objective_fail->getHash()] = true;
271 }
272 };
273
274 $this->assertEquals($objective_fail, $iterator->current());
275 $iterator->next();
276 $iterator->next();
277 }

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 190 of file ObjectiveIteratorTest.php.

190 : void
191 {
192 $this->expectException(Setup\UnachievableException::class);
193
194 $env = new Setup\ArrayEnvironment([]);
195
196 $objective_fail = $this->newObjective();
197 $objective_1 = $this->newObjective();
198 $objective_2 = $this->newObjective();
199 $objective_3 = $this->newObjective();
200
201 $objective_1
202 ->method("getPreconditions")
203 ->willReturn([]);
204
205 $objective_2
206 ->method("getPreconditions")
207 ->willReturn([]);
208
209 $objective_3
210 ->method("getPreconditions")
211 ->willReturn([$objective_1, $objective_fail, $objective_2]);
212
213 $iterator = new Setup\ObjectiveIterator($env, $objective_3);
214
215
216 $this->assertEquals($objective_1, $iterator->current());
217 $iterator->next();
218 $this->assertEquals($objective_fail, $iterator->current());
219 $iterator->markAsFailed($objective_fail);
220 $iterator->next();
221 $this->assertEquals($objective_2, $iterator->current());
222 $iterator->next();
223 }

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

+ Here is the call graph for this function:

◆ testRewind()

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

Definition at line 52 of file ObjectiveIteratorTest.php.

52 : void
53 {
54 $hash = "my hash";
55 $objective = $this->newObjective($hash);
56 $environment = $this->createMock(Setup\Environment::class);
57
58 $iterator = new Setup\ObjectiveIterator($environment, $objective);
59
60 $objective
61 ->expects($this->once())
62 ->method("getPreconditions")
63 ->with($environment)
64 ->willReturn([]);
65
66 $iterator->next();
67 $iterator->rewind();
68
69 $this->assertTrue($iterator->valid());
70 $this->assertSame($objective, $iterator->current());
71 $this->assertSame($hash, $iterator->key());
72 }

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

+ Here is the call graph for this function:

◆ testSetEnvironment()

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

Definition at line 164 of file ObjectiveIteratorTest.php.

164 : void
165 {
166 $env1 = new Setup\ArrayEnvironment([]);
167 $env2 = new Setup\ArrayEnvironment([]);
168
169 $objective1 = $this->newObjective();
170 $objective2 = $this->newObjective();
171
172 $objective1
173 ->expects($this->atLeastOnce())
174 ->method("getPreconditions")
175 ->with($env1)
176 ->willReturn([$objective2]);
177
178 $objective2
179 ->expects($this->atLeastOnce())
180 ->method("getPreconditions")
181 ->with($env2)
182 ->willReturn([]);
183
184 $iterator = new Setup\ObjectiveIterator($env1, $objective1);
185
186 $iterator->setEnvironment($env2);
187 $iterator->next();
188 }

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: