5use PHPUnit\Framework\TestCase;
45 if ($this->step_2_precondition && $num === 2) {
59 protected function setUp() : void
61 $this->
base = $this->createMock(Objective::class);
68 $env = $this->createMock(Environment::class);
70 $step1 = $this->test1->getStep(1);
72 $this->assertInstanceOf(ilDatabaseUpdateStep::class, $step1);
74 hash(
"sha256", Test_ilDatabaseUpdateSteps::class .
"::step_1"),
78 $preconditions = $step1->getPreconditions($env);
80 $this->assertCount(1, $preconditions);
81 $this->assertSame($this->
base, $preconditions[0]);
86 $env = $this->createMock(Environment::class);
88 $step1 = $this->test1->getStep(1);
89 $step2 = $this->test1->getStep(2);
91 $this->assertInstanceOf(ilDatabaseUpdateStep::class, $step2);
93 hash(
"sha256", Test_ilDatabaseUpdateSteps::class .
"::step_2"),
97 $preconditions = $step2->getPreconditions($env);
99 $this->assertCount(1, $preconditions);
100 $this->assertEquals($step1->getHash(), $preconditions[0]->getHash());
105 $env = $this->createMock(Environment::class);
109 $step1 = $this->test1->getStep(1);
110 $step2 = $this->test1->getStep(2);
114 $this->assertCount(2, $preconditions);
115 $this->assertEquals($step1->getHash(), $preconditions[0]->getHash());
116 $this->assertEquals($this->test1->step_2_precondition, $preconditions[1]);
121 $env = $this->createMock(Environment::class);
123 $step4 = $this->test1->getStep(4, 2);
125 $this->assertInstanceOf(ilDatabaseUpdateStep::class, $step4);
127 hash(
"sha256", Test_ilDatabaseUpdateSteps::class .
"::step_4"),
131 $preconditions = $step4->getPreconditions($env);
133 $this->assertCount(1, $preconditions);
134 $this->assertEquals($this->
base, $preconditions[0]);
139 $env = $this->createMock(Environment::class);
141 $step4 = $this->test1->getStep(4, 1);
142 $step2 = $this->test1->getStep(2, 1);
144 $this->assertInstanceOf(ilDatabaseUpdateStep::class, $step4);
146 hash(
"sha256", Test_ilDatabaseUpdateSteps::class .
"::step_4"),
150 $preconditions = $step4->getPreconditions($env);
152 $this->assertCount(1, $preconditions);
153 $this->assertEquals($step2->getHash(), $preconditions[0]->getHash());
158 $steps = $this->test1->_getSteps();
162 $this->assertEquals($expected, array_values(
$steps));
167 $env = $this->createMock(Environment::class);
168 $db = $this->createMock(\ilDBInterface::class);
171 ->method(
"getResource")
172 ->will($this->returnValueMap([
173 [Environment::RESOURCE_DATABASE, $db],
174 [\ilDatabaseUpdateStepExecutionLog::class,
null]
178 ->expects($this->exactly(3))
182 ->method(
"getPreconditions")
186 ->expects($this->once())
192 while (
$i->valid()) {
193 $current =
$i->current();
194 $env = $current->achieve($env);
195 $i->setEnvironment($env);
199 $this->assertEquals([1,2,4], $this->test1->called);
204 $env = $this->createMock(Environment::class);
205 $log = $this->createMock(\ilDatabaseUpdateStepExecutionLog::class);
206 $db = $this->createMock(\ilDBInterface::class);
209 ->method(
"getResource")
210 ->will($this->returnValueMap([
211 [Environment::RESOURCE_DATABASE, $db],
212 [\ilDatabaseUpdateStepExecutionLog::class,
$log]
216 ->expects($this->atLeastOnce())
217 ->method(
"getLastFinishedStep")
218 ->with(Test_ilDatabaseUpdateSteps::class)
222 ->expects($this->exactly(2))
226 ->method(
"getPreconditions")
230 ->expects($this->once())
236 while (
$i->valid()) {
237 $current =
$i->current();
238 $env = $current->achieve($env);
239 $i->setEnvironment($env);
243 $this->assertEquals([2,4], $this->test1->called);
An exception for terminatinating execution or to throw for unit testing.
A non-objective, nothing to do to achieve it...
getPreconditions(Environment $environment)
Objectives might depend on other objectives.
Tries to enumerate all preconditions for the given objective, where the ones that can be achieved (i....
step_2(\ilDBInterface $db)
getAdditionalPreconditionsForStep(int $num)
Get preconditions for steps.
step_1(\ilDBInterface $db)
step_4(\ilDBInterface $db)
testGetStep2WithAdditionalPrecondition()
This base-class simplifies the creation of (consecutive) database updates.
getSteps()
Get the numbers of the steps in this class.
An environment holds resources to be used in the setup process.
An objective is a desired state of the system that is supposed to be created by the setup.
connect($return_false_on_error=false)