19use PHPUnit\Framework\MockObject\MockObject;
20use PHPUnit\Framework\TestCase;
24 public const CLASS_NAME_200 =
"01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";
25 public const CLASS_NAME_201 =
"012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
32 protected function setUp(): void
34 $this->db = $this->createMock(\ilDBInterface::class);
35 $this->execution_db = new \ilDBStepExecutionDB($this->db, fn(): \DateTime =>
new \DateTime());
40 $this->expectException(\InvalidArgumentException::class);
41 $this->execution_db->started(self::CLASS_NAME_201, 1);
46 $this->expectException(\InvalidArgumentException::class);
47 $this->execution_db->finished(self::CLASS_NAME_201, 1);
52 $this->expectException(\InvalidArgumentException::class);
53 $this->execution_db->getLastStartedStep(self::CLASS_NAME_201);
58 $this->expectException(\InvalidArgumentException::class);
59 $this->execution_db->getLastFinishedStep(self::CLASS_NAME_201);
65 $NOW =
"2021-08-12 13:37:23.111111";
67 $execution_db = $this->getMockBuilder(\ilDBStepExecutionDB::class)
68 ->onlyMethods([
"getLastStartedStep",
"getLastFinishedStep"])
69 ->setConstructorArgs([$this->db, fn(): \DateTime =>
new \DateTime($NOW)])
73 ->method(
"getLastFinishedStep")
74 ->with(self::CLASS_NAME_200)
77 $this->expectException(\RuntimeException::class);
84 $NOW =
"2021-08-12 13:37:23.111111";
86 $execution_db = $this->getMockBuilder(\ilDBStepExecutionDB::class)
87 ->onlyMethods([
"getLastStartedStep",
"getLastFinishedStep"])
88 ->setConstructorArgs([$this->db, fn(): \DateTime =>
new \DateTime($NOW)])
92 ->method(
"getLastFinishedStep")
93 ->with(self::CLASS_NAME_200)
98 ->method(
"getLastStartedStep")
99 ->with(self::CLASS_NAME_200)
102 $this->expectException(\RuntimeException::class);
110 $NOW =
"2021-08-12 13:37:23.111111";
112 $execution_db = $this->getMockBuilder(\ilDBStepExecutionDB::class)
113 ->onlyMethods([
"getLastStartedStep",
"getLastFinishedStep"])
114 ->setConstructorArgs([$this->db, fn(): \DateTime =>
new \DateTime($NOW)])
118 ->method(
"getLastStartedStep")
119 ->with(self::CLASS_NAME_200)
122 $this->expectException(\RuntimeException::class);
129 $result = $this->getMockBuilder(ilDBStatement::class)->getMock();
132 ->willReturn($result);
134 ->method(
"fetchAssoc")
137 $this->assertSame(0, $this->execution_db->getLastStartedStep(self::CLASS_NAME_200));
142 $result = $this->getMockBuilder(ilDBStatement::class)->getMock();
145 ->willReturn($result);
147 ->method(
"fetchAssoc")
150 $this->assertSame(0, $this->execution_db->getLastFinishedStep(self::CLASS_NAME_200));
156 $NOW =
"2021-08-12 13:37:23.111111";
158 $execution_db = $this->getMockBuilder(\ilDBStepExecutionDB::class)
159 ->onlyMethods([
"getLastStartedStep",
"getLastFinishedStep"])
160 ->setConstructorArgs([$this->db, fn(): \DateTime =>
new \DateTime($NOW)])
164 ->method(
"getLastStartedStep")
165 ->with(self::CLASS_NAME_200)
169 ->method(
"getLastFinishedStep")
170 ->with(self::CLASS_NAME_200)
173 $this->db->expects($this->once())
190 $NOW =
"2021-08-12 13:37:23.222222";
192 $execution_db = $this->getMockBuilder(\ilDBStepExecutionDB::class)
193 ->onlyMethods([
"getLastStartedStep",
"getLastFinishedStep"])
194 ->setConstructorArgs([$this->db, fn(): \DateTime =>
new \DateTime($NOW)])
198 ->method(
"getLastStartedStep")
199 ->with(self::CLASS_NAME_200)
202 $this->db->expects($this->once())
222 $this->db->expects($this->once())
224 ->willReturnCallback(
225 function ($field, $type):
string {
226 $this->assertEquals(self::CLASS_NAME_200, $field);
227 $this->assertEquals(
'text', $type);
232 $result = $this->getMockBuilder(ilDBStatement::class)->getMock();
233 $this->db->expects($this->once())
240 ->willReturn($result);
241 $this->db->expects($this->once())
242 ->method(
"fetchAssoc")
245 $this->assertSame($STEP, $this->execution_db->getLastStartedStep(self::CLASS_NAME_200));
252 $this->db->expects($this->once())
254 ->willReturnCallback(
255 function ($field, $type):
string {
256 $this->assertEquals(self::CLASS_NAME_200, $field);
257 $this->assertEquals(
'text', $type);
263 $result = $this->getMockBuilder(ilDBStatement::class)->getMock();
264 $this->db->expects($this->once())
272 ->willReturn($result);
273 $this->db->expects($this->once())
274 ->method(
"fetchAssoc")
277 $this->assertSame($STEP, $this->execution_db->getLastFinishedStep(self::CLASS_NAME_200));
testGetLastFinishedStepThrowsOnLongClassName()
testGetLastStartedStepThrowsOnLongClassName()
testFinishedThrowsWhenOtherStepThenLastIsFinished()
testStartedThrowsOnLongClassName()
ilDBStepExecutionDB $execution_db
testStartedThrowsWhenLastStepNotFinished()
testGetLastStartedStepQueriesDB()
testGetLastFinishedStepStartsWithZero()
testStartedThrowsOnStartStepNotLargerThenLastFinishedStep()
ilDBInterface MockObject $db
testGetLastStartedStepStartsWithZero()
testGetLastFinishedStepQueriesDB()
testFinishedThrowsOnLongClassName()
This logs the execution of database update steps.
started(string $class, int $step)
finished(string $class, int $step)