ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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 PHPUnit Framework MockObject MockObject $db
 
ilDBStepExecutionDB $execution_db
 

Detailed Description

Definition at line 21 of file ilDBStepExecutionDBTest.php.

Member Function Documentation

◆ setUp()

ilDBStepExecutionDBTest::setUp ( )
protected

Definition at line 31 of file ilDBStepExecutionDBTest.php.

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

◆ testFinishedThrowsOnLongClassName()

ilDBStepExecutionDBTest::testFinishedThrowsOnLongClassName ( )

Definition at line 43 of file ilDBStepExecutionDBTest.php.

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

◆ testFinishedThrowsWhenOtherStepThenLastIsFinished()

ilDBStepExecutionDBTest::testFinishedThrowsWhenOtherStepThenLastIsFinished ( )

Definition at line 106 of file ilDBStepExecutionDBTest.php.

References ilDBStepExecutionDB\finished().

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

◆ testFinishedWritesToDB()

ilDBStepExecutionDBTest::testFinishedWritesToDB ( )

Definition at line 186 of file ilDBStepExecutionDBTest.php.

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

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

◆ testGetLastFinishedStepQueriesDB()

ilDBStepExecutionDBTest::testGetLastFinishedStepQueriesDB ( )

Definition at line 247 of file ilDBStepExecutionDBTest.php.

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

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

◆ testGetLastFinishedStepStartsWithZero()

ilDBStepExecutionDBTest::testGetLastFinishedStepStartsWithZero ( )

Definition at line 139 of file ilDBStepExecutionDBTest.php.

References ilDBStepExecutionDB\FIELD_STEP.

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

◆ testGetLastFinishedStepThrowsOnLongClassName()

ilDBStepExecutionDBTest::testGetLastFinishedStepThrowsOnLongClassName ( )

Definition at line 55 of file ilDBStepExecutionDBTest.php.

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

◆ testGetLastStartedStepQueriesDB()

ilDBStepExecutionDBTest::testGetLastStartedStepQueriesDB ( )

Definition at line 217 of file ilDBStepExecutionDBTest.php.

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

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

◆ testGetLastStartedStepStartsWithZero()

ilDBStepExecutionDBTest::testGetLastStartedStepStartsWithZero ( )

Definition at line 126 of file ilDBStepExecutionDBTest.php.

References ilDBStepExecutionDB\FIELD_STEP.

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

◆ testGetLastStartedStepThrowsOnLongClassName()

ilDBStepExecutionDBTest::testGetLastStartedStepThrowsOnLongClassName ( )

Definition at line 49 of file ilDBStepExecutionDBTest.php.

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

◆ testStartedThrowsOnLongClassName()

ilDBStepExecutionDBTest::testStartedThrowsOnLongClassName ( )

Definition at line 37 of file ilDBStepExecutionDBTest.php.

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

◆ testStartedThrowsOnStartStepNotLargerThenLastFinishedStep()

ilDBStepExecutionDBTest::testStartedThrowsOnStartStepNotLargerThenLastFinishedStep ( )

Definition at line 61 of file ilDBStepExecutionDBTest.php.

References ilDBStepExecutionDB\started().

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

◆ testStartedThrowsWhenLastStepNotFinished()

ilDBStepExecutionDBTest::testStartedThrowsWhenLastStepNotFinished ( )

Definition at line 81 of file ilDBStepExecutionDBTest.php.

References ilDBStepExecutionDB\started().

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

◆ testStartedWritesToDB()

ilDBStepExecutionDBTest::testStartedWritesToDB ( )

Definition at line 152 of file ilDBStepExecutionDBTest.php.

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

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

Field Documentation

◆ $db

ilDBInterface PHPUnit Framework MockObject MockObject ilDBStepExecutionDBTest::$db
private

Definition at line 28 of file ilDBStepExecutionDBTest.php.

◆ $execution_db

ilDBStepExecutionDB ilDBStepExecutionDBTest::$execution_db
private

Definition at line 29 of file ilDBStepExecutionDBTest.php.

◆ CLASS_NAME_200

const ilDBStepExecutionDBTest::CLASS_NAME_200 = "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"

Definition at line 23 of file ilDBStepExecutionDBTest.php.

◆ CLASS_NAME_201

const ilDBStepExecutionDBTest::CLASS_NAME_201 = "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"

Definition at line 24 of file ilDBStepExecutionDBTest.php.


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