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

Public Member Functions

 testStartedThrowsOnLongClassName ()
 
 testFinishedThrowsOnLongClassName ()
 
 testGetLastStartedStepThrowsOnLongClassName ()
 
 testGetLastFinishedStepThrowsOnLongClassName ()
 
 testStartedThrowsOnStartStepNotLargerThenLastFinishedStep ()
 
 testStartedThrowsWhenLastStepNotFinished ()
 
 testFinishedThrowsWhenOtherStepThenLastIsFinished ()
 
 testGetLastStartedStepStartsWithZero ()
 
 testGetLastFinishedStepStartsWithZero ()
 
 testStartedWritesToDB ()
 
 testFinishedWritesToDB ()
 
 testGetLastStartedStepQueriesDB ()
 
 testGetLastFinishedStepQueriesDB ()
 

Data Fields

const CLASS_NAME_200 = "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
 
const CLASS_NAME_201 = "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
 

Protected Member Functions

 setUp ()
 

Private Attributes

ilDBInterface MockObject $db
 
ilDBStepExecutionDB $execution_db
 

Detailed Description

Definition at line 22 of file ilDBStepExecutionDBTest.php.

Member Function Documentation

◆ setUp()

ilDBStepExecutionDBTest::setUp ( )
protected

Definition at line 32 of file ilDBStepExecutionDBTest.php.

32 : void
33 {
34 $this->db = $this->createMock(\ilDBInterface::class);
35 $this->execution_db = new \ilDBStepExecutionDB($this->db, fn(): \DateTime => new \DateTime());
36 }

◆ testFinishedThrowsOnLongClassName()

ilDBStepExecutionDBTest::testFinishedThrowsOnLongClassName ( )

Definition at line 44 of file ilDBStepExecutionDBTest.php.

44 : void
45 {
46 $this->expectException(\InvalidArgumentException::class);
47 $this->execution_db->finished(self::CLASS_NAME_201, 1);
48 }

◆ testFinishedThrowsWhenOtherStepThenLastIsFinished()

ilDBStepExecutionDBTest::testFinishedThrowsWhenOtherStepThenLastIsFinished ( )

Definition at line 107 of file ilDBStepExecutionDBTest.php.

107 : void
108 {
109 $STEP = 1;
110 $NOW = "2021-08-12 13:37:23.111111";
111
112 $execution_db = $this->getMockBuilder(\ilDBStepExecutionDB::class)
113 ->onlyMethods(["getLastStartedStep", "getLastFinishedStep"])
114 ->setConstructorArgs([$this->db, fn(): \DateTime => new \DateTime($NOW)])
115 ->getMock();
116
117 $execution_db->expects($this->once())
118 ->method("getLastStartedStep")
119 ->with(self::CLASS_NAME_200)
120 ->willReturn(2);
121
122 $this->expectException(\RuntimeException::class);
123
124 $execution_db->finished(self::CLASS_NAME_200, $STEP);
125 }
ilDBStepExecutionDB $execution_db
finished(string $class, int $step)

References $execution_db, and ilDBStepExecutionDB\finished().

+ Here is the call graph for this function:

◆ testFinishedWritesToDB()

ilDBStepExecutionDBTest::testFinishedWritesToDB ( )

Definition at line 187 of file ilDBStepExecutionDBTest.php.

187 : void
188 {
189 $STEP = 2;
190 $NOW = "2021-08-12 13:37:23.222222";
191
192 $execution_db = $this->getMockBuilder(\ilDBStepExecutionDB::class)
193 ->onlyMethods(["getLastStartedStep", "getLastFinishedStep"])
194 ->setConstructorArgs([$this->db, fn(): \DateTime => new \DateTime($NOW)])
195 ->getMock();
196
197 $execution_db->expects($this->once())
198 ->method("getLastStartedStep")
199 ->with(self::CLASS_NAME_200)
200 ->willReturn(2);
201
202 $this->db->expects($this->once())
203 ->method("update")
204 ->with(
206 [
208 ],
209 [
210 ilDBStepExecutionDB::FIELD_CLASS => ["text", self::CLASS_NAME_200],
211 ilDBStepExecutionDB::FIELD_STEP => ["integer", $STEP]
212 ]
213 );
214
215 $execution_db->finished(self::CLASS_NAME_200, $STEP);
216 }

References $execution_db, ilDBStepExecutionDB\FIELD_CLASS, ilDBStepExecutionDB\FIELD_FINISHED, ilDBStepExecutionDB\FIELD_STEP, ilDBStepExecutionDB\finished(), and ilDBStepExecutionDB\TABLE_NAME.

+ Here is the call graph for this function:

◆ testGetLastFinishedStepQueriesDB()

ilDBStepExecutionDBTest::testGetLastFinishedStepQueriesDB ( )

Definition at line 248 of file ilDBStepExecutionDBTest.php.

248 : void
249 {
250 $STEP = 23;
251
252 $this->db->expects($this->once())
253 ->method("quote")
254 ->willReturnCallback(
255 function ($field, $type): string {
256 $this->assertEquals(self::CLASS_NAME_200, $field);
257 $this->assertEquals('text', $type);
258 return 'CLASS';
259 }
260 );
261
262
263 $result = $this->getMockBuilder(ilDBStatement::class)->getMock();
264 $this->db->expects($this->once())
265 ->method("query")
266 ->with(
269 " WHERE " . ilDBStepExecutionDB::FIELD_CLASS . " = CLASS" .
270 " AND " . ilDBStepExecutionDB::FIELD_FINISHED . " IS NOT NULL"
271 )
272 ->willReturn($result);
273 $this->db->expects($this->once())
274 ->method("fetchAssoc")
275 ->willReturn([ilDBStepExecutionDB::FIELD_STEP => $STEP]);
276
277 $this->assertSame($STEP, $this->execution_db->getLastFinishedStep(self::CLASS_NAME_200));
278 }

References ilDBStepExecutionDB\FIELD_CLASS, ilDBStepExecutionDB\FIELD_FINISHED, ilDBStepExecutionDB\FIELD_STEP, and ilDBStepExecutionDB\TABLE_NAME.

◆ testGetLastFinishedStepStartsWithZero()

ilDBStepExecutionDBTest::testGetLastFinishedStepStartsWithZero ( )

Definition at line 140 of file ilDBStepExecutionDBTest.php.

140 : void
141 {
142 $result = $this->getMockBuilder(ilDBStatement::class)->getMock();
143 $this->db
144 ->method("query")
145 ->willReturn($result);
146 $this->db
147 ->method("fetchAssoc")
148 ->willReturn([ilDBStepExecutionDB::FIELD_STEP => null]);
149
150 $this->assertSame(0, $this->execution_db->getLastFinishedStep(self::CLASS_NAME_200));
151 }

References ilDBStepExecutionDB\FIELD_STEP.

◆ testGetLastFinishedStepThrowsOnLongClassName()

ilDBStepExecutionDBTest::testGetLastFinishedStepThrowsOnLongClassName ( )

Definition at line 56 of file ilDBStepExecutionDBTest.php.

56 : void
57 {
58 $this->expectException(\InvalidArgumentException::class);
59 $this->execution_db->getLastFinishedStep(self::CLASS_NAME_201);
60 }

◆ testGetLastStartedStepQueriesDB()

ilDBStepExecutionDBTest::testGetLastStartedStepQueriesDB ( )

Definition at line 218 of file ilDBStepExecutionDBTest.php.

218 : void
219 {
220 $STEP = 23;
221
222 $this->db->expects($this->once())
223 ->method("quote")
224 ->willReturnCallback(
225 function ($field, $type): string {
226 $this->assertEquals(self::CLASS_NAME_200, $field);
227 $this->assertEquals('text', $type);
228 return 'CLASS';
229 }
230 );
231
232 $result = $this->getMockBuilder(ilDBStatement::class)->getMock();
233 $this->db->expects($this->once())
234 ->method("query")
235 ->with(
238 " WHERE " . ilDBStepExecutionDB::FIELD_CLASS . " = CLASS"
239 )
240 ->willReturn($result);
241 $this->db->expects($this->once())
242 ->method("fetchAssoc")
243 ->willReturn([ilDBStepExecutionDB::FIELD_STEP => $STEP]);
244
245 $this->assertSame($STEP, $this->execution_db->getLastStartedStep(self::CLASS_NAME_200));
246 }

References ilDBStepExecutionDB\FIELD_CLASS, ilDBStepExecutionDB\FIELD_STEP, and ilDBStepExecutionDB\TABLE_NAME.

◆ testGetLastStartedStepStartsWithZero()

ilDBStepExecutionDBTest::testGetLastStartedStepStartsWithZero ( )

Definition at line 127 of file ilDBStepExecutionDBTest.php.

127 : void
128 {
129 $result = $this->getMockBuilder(ilDBStatement::class)->getMock();
130 $this->db
131 ->method("query")
132 ->willReturn($result);
133 $this->db
134 ->method("fetchAssoc")
135 ->willReturn([ilDBStepExecutionDB::FIELD_STEP => null]);
136
137 $this->assertSame(0, $this->execution_db->getLastStartedStep(self::CLASS_NAME_200));
138 }

References ilDBStepExecutionDB\FIELD_STEP.

◆ testGetLastStartedStepThrowsOnLongClassName()

ilDBStepExecutionDBTest::testGetLastStartedStepThrowsOnLongClassName ( )

Definition at line 50 of file ilDBStepExecutionDBTest.php.

50 : void
51 {
52 $this->expectException(\InvalidArgumentException::class);
53 $this->execution_db->getLastStartedStep(self::CLASS_NAME_201);
54 }

◆ testStartedThrowsOnLongClassName()

ilDBStepExecutionDBTest::testStartedThrowsOnLongClassName ( )

Definition at line 38 of file ilDBStepExecutionDBTest.php.

38 : void
39 {
40 $this->expectException(\InvalidArgumentException::class);
41 $this->execution_db->started(self::CLASS_NAME_201, 1);
42 }

◆ testStartedThrowsOnStartStepNotLargerThenLastFinishedStep()

ilDBStepExecutionDBTest::testStartedThrowsOnStartStepNotLargerThenLastFinishedStep ( )

Definition at line 62 of file ilDBStepExecutionDBTest.php.

62 : void
63 {
64 $STEP = 1;
65 $NOW = "2021-08-12 13:37:23.111111";
66
67 $execution_db = $this->getMockBuilder(\ilDBStepExecutionDB::class)
68 ->onlyMethods(["getLastStartedStep", "getLastFinishedStep"])
69 ->setConstructorArgs([$this->db, fn(): \DateTime => new \DateTime($NOW)])
70 ->getMock();
71
72 $execution_db->expects($this->once())
73 ->method("getLastFinishedStep")
74 ->with(self::CLASS_NAME_200)
75 ->willReturn(2);
76
77 $this->expectException(\RuntimeException::class);
78
79 $execution_db->started(self::CLASS_NAME_200, $STEP);
80 }
started(string $class, int $step)

References $execution_db, and ilDBStepExecutionDB\started().

+ Here is the call graph for this function:

◆ testStartedThrowsWhenLastStepNotFinished()

ilDBStepExecutionDBTest::testStartedThrowsWhenLastStepNotFinished ( )

Definition at line 82 of file ilDBStepExecutionDBTest.php.

82 : void
83 {
84 $NOW = "2021-08-12 13:37:23.111111";
85
86 $execution_db = $this->getMockBuilder(\ilDBStepExecutionDB::class)
87 ->onlyMethods(["getLastStartedStep", "getLastFinishedStep"])
88 ->setConstructorArgs([$this->db, fn(): \DateTime => new \DateTime($NOW)])
89 ->getMock();
90
91 $execution_db->expects($this->once())
92 ->method("getLastFinishedStep")
93 ->with(self::CLASS_NAME_200)
94 ->willReturn(1);
95
96
97 $execution_db->expects($this->once())
98 ->method("getLastStartedStep")
99 ->with(self::CLASS_NAME_200)
100 ->willReturn(2);
101
102 $this->expectException(\RuntimeException::class);
103
104 $execution_db->started(self::CLASS_NAME_200, 3);
105 }

References $execution_db, and ilDBStepExecutionDB\started().

+ Here is the call graph for this function:

◆ testStartedWritesToDB()

ilDBStepExecutionDBTest::testStartedWritesToDB ( )

Definition at line 153 of file ilDBStepExecutionDBTest.php.

153 : void
154 {
155 $STEP = 2;
156 $NOW = "2021-08-12 13:37:23.111111";
157
158 $execution_db = $this->getMockBuilder(\ilDBStepExecutionDB::class)
159 ->onlyMethods(["getLastStartedStep", "getLastFinishedStep"])
160 ->setConstructorArgs([$this->db, fn(): \DateTime => new \DateTime($NOW)])
161 ->getMock();
162
163 $execution_db->expects($this->once())
164 ->method("getLastStartedStep")
165 ->with(self::CLASS_NAME_200)
166 ->willReturn(1);
167
168 $execution_db->expects($this->once())
169 ->method("getLastFinishedStep")
170 ->with(self::CLASS_NAME_200)
171 ->willReturn(1);
172
173 $this->db->expects($this->once())
174 ->method("insert")
175 ->with(
177 [
178 ilDBStepExecutionDB::FIELD_CLASS => ["text", self::CLASS_NAME_200],
179 ilDBStepExecutionDB::FIELD_STEP => ["integer", $STEP],
180 ilDBStepExecutionDB::FIELD_STARTED => ["text", $NOW]
181 ]
182 );
183
184 $execution_db->started(self::CLASS_NAME_200, $STEP);
185 }

References $execution_db, ilDBStepExecutionDB\FIELD_CLASS, ilDBStepExecutionDB\FIELD_STARTED, ilDBStepExecutionDB\FIELD_STEP, ilDBStepExecutionDB\started(), and ilDBStepExecutionDB\TABLE_NAME.

+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface MockObject ilDBStepExecutionDBTest::$db
private

Definition at line 29 of file ilDBStepExecutionDBTest.php.

◆ $execution_db

◆ CLASS_NAME_200

const ilDBStepExecutionDBTest::CLASS_NAME_200 = "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"

Definition at line 24 of file ilDBStepExecutionDBTest.php.

◆ CLASS_NAME_201

const ilDBStepExecutionDBTest::CLASS_NAME_201 = "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"

Definition at line 25 of file ilDBStepExecutionDBTest.php.


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