ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilDatabaseUpdateStepsExecutedObjectiveTest Class Reference
+ Inheritance diagram for ilDatabaseUpdateStepsExecutedObjectiveTest:
+ Collaboration diagram for ilDatabaseUpdateStepsExecutedObjectiveTest:

Public Member Functions

 testCorrectExecutionOrder ()
 
 testUsesExecutionLock ()
 
 testOnlyExecuteNonExecutedSteps ()
 
 testExceptionOnNonMatchingStartAndFinished ()
 

Data Fields

Test_ilDatabaseUpdateSteps $steps
 
ilDatabaseUpdateStepsExecutedObjective $objective
 

Protected Member Functions

 setUp ()
 

Detailed Description

Member Function Documentation

◆ setUp()

ilDatabaseUpdateStepsExecutedObjectiveTest::setUp ( )
protected

Definition at line 66 of file ilDatabaseUpdateStepsExecutedObjectiveTest.php.

66 : void
67 {
68 $this->steps = new Test_ilDatabaseUpdateSteps();
69 $this->objective = new ilDatabaseUpdateStepsExecutedObjective($this->steps);
70 }
This class attempt to achieve a set of database update steps.

◆ testCorrectExecutionOrder()

ilDatabaseUpdateStepsExecutedObjectiveTest::testCorrectExecutionOrder ( )

Definition at line 72 of file ilDatabaseUpdateStepsExecutedObjectiveTest.php.

72 : void
73 {
74 $execution_log = new class () implements ilDatabaseUpdateStepExecutionLog {
75 public function started(string $class, int $step): void
76 {
77 }
78 public function finished(string $class, int $step): void
79 {
80 }
81 public function getLastStartedStep(string $class): int
82 {
83 return 0;
84 }
85 public function getLastFinishedStep(string $class): int
86 {
87 return 0;
88 }
89 };
90 $steps_reader = new class () extends ilDBStepReader {
91 };
92 $db = $this->createMock(ilDBInterface::class);
93 $env = new ArrayEnvironment([
94 ilDBStepReader::class => $steps_reader,
95 ilDatabaseUpdateStepExecutionLog::class => $execution_log,
96 Environment::RESOURCE_DATABASE => $db
97 ]);
98
99 $db->expects($this->exactly(3))
100 ->method("connect");
101
102 $this->objective->achieve($env);
103
104 $this->assertSame([1,2,4], $this->steps->called);
105 }
This logs the execution of database update steps.

◆ testExceptionOnNonMatchingStartAndFinished()

ilDatabaseUpdateStepsExecutedObjectiveTest::testExceptionOnNonMatchingStartAndFinished ( )

Definition at line 191 of file ilDatabaseUpdateStepsExecutedObjectiveTest.php.

191 : void
192 {
193 $this->expectException(RuntimeException::class);
194
195 $execution_log = new class () implements ilDatabaseUpdateStepExecutionLog {
196 public function started(string $class, int $step): void
197 {
198 }
199 public function finished(string $class, int $step): void
200 {
201 }
202 public function getLastStartedStep(string $class): int
203 {
204 return 2;
205 }
206 public function getLastFinishedStep(string $class): int
207 {
208 return 1;
209 }
210 };
211 $db = $this->createMock(ilDBInterface::class);
212 $env = new ArrayEnvironment([
213 ilDatabaseUpdateStepExecutionLog::class => $execution_log,
214 Environment::RESOURCE_DATABASE => $db
215 ]);
216 $this->objective->achieve($env);
217 }

◆ testOnlyExecuteNonExecutedSteps()

ilDatabaseUpdateStepsExecutedObjectiveTest::testOnlyExecuteNonExecutedSteps ( )

Definition at line 156 of file ilDatabaseUpdateStepsExecutedObjectiveTest.php.

156 : void
157 {
158 $execution_log = new class () implements ilDatabaseUpdateStepExecutionLog {
159 public function started(string $class, int $step): void
160 {
161 }
162 public function finished(string $class, int $step): void
163 {
164 }
165 public function getLastStartedStep(string $class): int
166 {
167 return 1;
168 }
169 public function getLastFinishedStep(string $class): int
170 {
171 return 1;
172 }
173 };
174 $steps_reader = new class () extends ilDBStepReader {
175 };
176 $db = $this->createMock(ilDBInterface::class);
177 $env = new ArrayEnvironment([
178 ilDBStepReader::class => $steps_reader,
179 ilDatabaseUpdateStepExecutionLog::class => $execution_log,
180 Environment::RESOURCE_DATABASE => $db
181 ]);
182
183 $db->expects($this->exactly(2))
184 ->method("connect");
185
186 $this->objective->achieve($env);
187
188 $this->assertSame([2,4], $this->steps->called);
189 }

◆ testUsesExecutionLock()

ilDatabaseUpdateStepsExecutedObjectiveTest::testUsesExecutionLock ( )

Definition at line 107 of file ilDatabaseUpdateStepsExecutedObjectiveTest.php.

107 : void
108 {
109 $execution_log = new class ($this) implements ilDatabaseUpdateStepExecutionLog {
110 public function __construct(protected ilDatabaseUpdateStepsExecutedObjectiveTest $test)
111 {
112 }
113 public function started(string $class, int $step): void
114 {
115 $this->test->steps->called[] = ["started", $class, $step];
116 }
117 public function finished(string $class, int $step): void
118 {
119 $this->test->steps->called[] = ["finished", $class, $step];
120 }
121 public function getLastStartedStep(string $class): int
122 {
123 return 0;
124 }
125 public function getLastFinishedStep(string $class): int
126 {
127 return 0;
128 }
129 };
130 $steps_reader = new class () extends ilDBStepReader {
131 };
132 $db = $this->createMock(ilDBInterface::class);
133 $env = new ArrayEnvironment([
134 ilDBStepReader::class => $steps_reader,
135 ilDatabaseUpdateStepExecutionLog::class => $execution_log,
136 Environment::RESOURCE_DATABASE => $db
137 ]);
138
139 $this->objective->achieve($env);
140
141 $expected = [
142 ["started", Test_ilDatabaseUpdateSteps::class, 1],
143 1,
144 ["finished", Test_ilDatabaseUpdateSteps::class, 1],
145 ["started", Test_ilDatabaseUpdateSteps::class, 2],
146 2,
147 ["finished", Test_ilDatabaseUpdateSteps::class, 2],
148 ["started", Test_ilDatabaseUpdateSteps::class, 4],
149 4,
150 ["finished", Test_ilDatabaseUpdateSteps::class, 4]
151 ];
152
153 $this->assertSame($expected, $this->steps->called);
154 }
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References ILIAS\GlobalScreen\Provider\__construct().

+ Here is the call graph for this function:

Field Documentation

◆ $objective

ilDatabaseUpdateStepsExecutedObjective ilDatabaseUpdateStepsExecutedObjectiveTest::$objective

◆ $steps

Test_ilDatabaseUpdateSteps ilDatabaseUpdateStepsExecutedObjectiveTest::$steps

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