19declare(strict_types=1);
33use PHPUnit\Framework\MockObject\MockObject;
34use PHPUnit\Framework\Attributes\DataProvider;
41 $this->assertInstanceOf(Repository::class, $repository);
44 #[DataProvider('providePassedParticipants')]
50 $actual = $repository->getPassedParticipants($test_obj_id);
51 foreach ($actual as $index => $participant) {
52 $this->assertEquals($participant[
'active_id'], $query_result[$index][
'active_id']);
53 $this->assertEquals($participant[
'user_id'], $query_result[$index][
'user_id']);
57 #[DataProvider('provideTestResultCache')]
63 $actual = $repository->getTestResult($query_result[
'active_fi']);
65 $this->assertNotNull($actual);
66 $this->assertInstanceOf(ParticipantResult::class, $actual);
67 foreach ($expected as $method => $value) {
68 $this->assertEquals($value, $actual->$method());
77 $actual = $repository->getTestResult(1000);
79 $this->assertNull($actual);
82 #[DataProvider('provideFetchedTestAttemptResult')]
87 $repository->updateTestResultCache($query_result[
'active_fi']);
90 $test_obj_id = $query_result[
'test_obj_id'];
92 $this->assertEquals($expected[
'isPassed'], $repository->isPassed(
$user_id, $test_obj_id));
93 $this->assertEquals($expected[
'isFailed'], $repository->isFailed(
$user_id, $test_obj_id));
94 $this->assertEquals($expected[
'hasFinished'], $repository->hasFinished(
$user_id, $test_obj_id));
101 $this->assertFalse($repository->isPassed(100, 200));
102 $this->assertFalse($repository->isFailed(100, 200));
103 $this->assertFalse($repository->hasFinished(100, 200));
106 #[DataProvider('provideCachedStatus')]
111 $test_obj_id = $query[
'test_obj_id'];
116 $this->assertEquals($expected[
'isPassed'], $repository->isPassed(
$user_id, $test_obj_id));
117 $this->assertEquals($expected[
'isFailed'], $repository->isFailed(
$user_id, $test_obj_id));
118 $this->assertEquals($expected[
'hasFinished'], $repository->hasFinished(
$user_id, $test_obj_id));
122 \ilDBInterface::class,
124 $mock->expects($this->exactly(0))->method(
'queryF');
125 $mock->expects($this->exactly(0))->method(
'fetchAssoc');
129 $this->assertEquals($expected[
'isPassed'], $repository->isPassed(
$user_id, $test_obj_id));
130 $this->assertEquals($expected[
'isFailed'], $repository->isFailed(
$user_id, $test_obj_id));
131 $this->assertEquals($expected[
'hasFinished'], $repository->hasFinished(
$user_id, $test_obj_id));
134 #[DataProvider('provideCachedStatus')]
139 $active_id = $query[
'active_id'];
140 $test_obj_id = $query[
'test_obj_id'];
145 $this->assertEquals($expected[
'isPassed'], $repository->isPassed(
$user_id, $test_obj_id));
146 $this->assertEquals($expected[
'isFailed'], $repository->isFailed(
$user_id, $test_obj_id));
147 $this->assertEquals($expected[
'hasFinished'], $repository->hasFinished(
$user_id, $test_obj_id));
150 $repository->removeTestResults([$active_id], $test_obj_id);
155 $this->assertEquals($expected[
'isPassed'], $repository->isPassed(
$user_id, $test_obj_id));
156 $this->assertEquals($expected[
'isFailed'], $repository->isFailed(
$user_id, $test_obj_id));
157 $this->assertEquals($expected[
'hasFinished'], $repository->hasFinished(
$user_id, $test_obj_id));
160 #[DataProvider('provideTestAttemptResult')]
166 $actual = $repository->getTestAttemptResult($query_result[
'active_fi']);
168 $this->assertNotNull($actual);
169 $this->assertInstanceOf(AttemptResult::class, $actual);
170 foreach ($expected as $method => $value) {
171 $this->assertEquals($value, $actual->$method());
180 $actual = $repository->getTestAttemptResult(1000);
182 $this->assertNull($actual);
185 #[DataProvider('provideFetchedTestResult')]
189 array $test_config_result,
190 array $working_time_result,
196 $actual = $repository->updateTestAttemptResult(
197 $parameters[
'active_id'],
200 $parameters[
'test_obj_id'],
204 $this->assertNotNull($actual);
205 $this->assertInstanceOf(AttemptResult::class, $actual);
206 $this->assertEqualsWithDelta(time(), $actual->getTimestamp(), 5);
207 foreach ($expected as $method => $value) {
208 $this->assertEquals($value, $actual->$method());
220 $global_cache = $this->createConfiguredMock(
222 [
'get' => $this->createCacheMock()]
225 $partial_mock = $this->getMockBuilder(Repository::class)
226 ->disableOriginalClone()
227 ->setConstructorArgs([
229 $this->createMock(Refinery::class),
230 $this->createMarksRepositoryMock($mock_data),
233 ->onlyMethods([
'lookupAttempt'])
235 $partial_mock->method(
'lookupAttempt')->willReturn(0);
237 return $partial_mock;
244 $mock_data[
'mark_short'],
245 $mock_data[
'mark_official'],
247 (
bool) $mock_data[
'passed']
249 $mark_schema = $this->createConfiguredMock(
251 [
'getMatchingMark' => $mock]
262 public function getMarkSchemaFor(
int $test_id):
MarkSchema
264 return $this->mark_schema;
267 public function storeMarkSchema(
MarkSchema $mark_schema): array
272 public function getMarkSchemaBySteps(array $step_ids):
MarkSchema
277 public function deleteSteps(array $step_ids):
void
286 return new class () implements
Container {
287 private array $cache = [];
289 public function lock(
float $seconds):
void
294 public function isLocked():
bool
299 public function has(
string $key):
bool
301 return isset($this->cache[$key]);
304 public function get(
string $key,
Transformation $transformation):
string|
int|array|
bool|
null
306 return $this->cache[$key] ??
null;
309 public function set(
string $key,
string|
int|array|
bool|
null $value, ?
int $ttl =
null):
void
311 $this->cache[$key] = $value;
314 public function delete(
string $key):
void
316 unset($this->cache[$key]);
319 public function flush():
void
324 public function getAdaptorName():
string
329 public function getContainerName():
string
346 \ilDBInterface::class,
347 function (\
ilDBInterface|MockObject $mock) use ($fetch_all_return) {
349 ->expects($this->once())
351 ->with($this->stringContains(
"WHERE tst_tests.obj_fi = %s AND tst_result_cache.passed_once = 1"));
354 ->expects($this->once())
356 ->willReturn($fetch_all_return);
366 if ($fetch_assoc_return) {
367 $fetch_assoc_return[
'test_id'] = 0;
369 $this->mockGetResultQuery(
'tst_result_cache', $fetch_assoc_return);
377 $this->mockGetResultQuery(
'tst_pass_result', $fetch_assoc_return);
383 \ilDBInterface::class,
384 function (\
ilDBInterface|MockObject $mock) use ($table, $fetch_assoc_return) {
386 ->expects($this->once())
390 ->expects($this->once())
391 ->method(
'fetchAssoc')
392 ->willReturn($fetch_assoc_return);
403 \ilDBInterface::class,
404 function (\
ilDBInterface|MockObject $mock) use ($fetch_assoc_return) {
405 $mock->expects($this->atLeastOnce())->method(
'queryF');
406 $mock->expects($this->atLeastOnce())->method(
'fetchAssoc')->willReturn($fetch_assoc_return);
417 \ilDBInterface::class,
418 function (\
ilDBInterface|MockObject $mock) use ($fetch_all_return) {
419 $mock->expects($this->once())
421 ->with($this->equalTo(
"SELECT user_fi FROM tst_active WHERE\n"));
422 $mock->expects($this->once())->method(
'fetchAll')->willReturn($fetch_all_return);
433 \ilDBInterface::class,
434 function (\
ilDBInterface|MockObject $mock) use ($test_attempt_result) {
436 $mocked_stmt = $this->createConfiguredMock(\ilDBStatement::class, [
439 $mock->method(
'queryF')->willReturn($mocked_stmt);
442 $mock->expects($this->exactly(1))
443 ->method(
'fetchAssoc')
444 ->willReturn($test_attempt_result);
446 $mock->expects($this->exactly(1))->method(
'replace');
456 $fetch_assoc_mocks = [
465 \ilDBInterface::class,
466 function (\
ilDBInterface|MockObject $mock) use ($fetch_assoc_mocks) {
468 $mocked_stmt = $this->createConfiguredMock(\ilDBStatement::class, [
471 $mock->method(
'queryF')->willReturn($mocked_stmt);
473 $mock->expects($this->exactly(count($fetch_assoc_mocks)))
474 ->method(
'fetchAssoc')
475 ->willReturnOnConsecutiveCalls(...$fetch_assoc_mocks);
477 $mock->expects($this->exactly(1))->method(
'replace');
493 [
'user_id' => 1,
'test_obj_id' => 100,
'active_id' => 1000],
494 [
'passed' =>
true,
'failed' =>
false,
'finished' =>
false],
495 [
'isPassed' =>
true,
'isFailed' =>
false,
'hasFinished' =>
false],
498 [
'user_id' => 10,
'test_obj_id' => 100,
'active_id' => 1000],
499 [
'passed' =>
false,
'failed' =>
true,
'finished' =>
false],
500 [
'isPassed' =>
false,
'isFailed' =>
true,
'hasFinished' =>
false],
503 [
'user_id' => 1,
'test_obj_id' => 250,
'active_id' => 1400],
504 [
'passed' =>
false,
'failed' =>
true,
'finished' =>
true],
505 [
'isPassed' =>
false,
'isFailed' =>
true,
'hasFinished' =>
true],
525 [
'user_id' => 1,
'active_id' => 100],
526 [
'user_id' => 2,
'active_id' => 200],
527 [
'user_id' => 3,
'active_id' => 101],
528 [
'user_id' => 4,
'active_id' => 201],
529 [
'user_id' => 5,
'active_id' => 0],
551 'reached_points' => 0,
552 'mark_short' =>
'failed',
553 'mark_official' =>
'failed',
556 'tstamp' => 1740557748,
562 'isPassedOnce' =>
false,
565 'getMaxPoints' => 25,
566 'getReachedPoints' => 0,
567 'getMarkShort' =>
'failed',
568 'getMarkOfficial' =>
'failed',
569 'getTimestamp' => 1740557748,
594 'questioncount' => 2,
595 'answeredquestions' => 2,
597 'tstamp' => 1740557748,
598 'exam_id' =>
'I0_T334_A41_P0',
599 'finalized_by' =>
null,
600 'last_finished_pass' => 0,
603 'test_obj_id' => 100,
605 'reached_points' => 0,
610 'isPassedOnce' =>
false,
612 'hasFinished' =>
true,
614 'getMaxPoints' => 25,
615 'getReachedPoints' => 0,
616 'getMarkShort' =>
'failed',
617 'getMarkOfficial' =>
'failed',
618 'getTimestamp' => 1740557748,
627 'questioncount' => 2,
628 'answeredquestions' => 2,
630 'tstamp' => 1740557748,
631 'exam_id' =>
'I0_T334_A41_P0',
632 'finalized_by' =>
null,
633 'last_finished_pass' => 1,
636 'test_obj_id' => 100,
638 'reached_points' => 25,
643 'isPassedOnce' =>
true,
645 'hasFinished' =>
true,
647 'getMaxPoints' => 25,
648 'getReachedPoints' => 25,
649 'getMarkShort' =>
'passed',
650 'getMarkOfficial' =>
'passed',
651 'getTimestamp' => 1740557748,
673 'questioncount' => 3,
674 'answeredquestions' => 2,
676 'tstamp' => 1740557748,
677 'exam_id' =>
'I0_T334_A41_P0',
678 'finalized_by' =>
null,
683 'getMaxPoints' => 25,
684 'getReachedPoints' => 0,
685 'getQuestionCount' => 3,
686 'getAnsweredQuestions' => 2,
687 'getWorkingTime' => 12,
688 'getTimestamp' => 1740557748,
689 'getExamId' =>
'I0_T334_A41_P0',
690 'getFinalizedBy' => null
714 'test_obj_id' => 100,
720 'answeredquestions' => 2,
729 'started' =>
'2024-01-01 04:05:05',
730 'finished' =>
'2024-01-01 04:05:17'
736 'getMaxPoints' => 25,
737 'getReachedPoints' => 10,
738 'getQuestionCount' => 3,
739 'getAnsweredQuestions' => 2,
740 'getWorkingTime' => 12,
741 'getExamId' =>
'I_T100_A10_P0',
742 'getFinalizedBy' => null
Class ParticipantResult is a model representation of an entry in the test_result_cache table.
A class defining mark schemas for assessment test objects.
A class defining marks for assessment test objects.
mockGetUserIds(?array $fetch_all_return)
testGetTestAttemptResult(array $query_result, array $expected)
testGetTestResult(array $query_result, array $expected)
testRemoveTestResults(array $query, array $cached_status, array $expected)
mockUpdateTestResultCache(?array $test_attempt_result, bool $passed_once=false)
mockUpdateTestAttemptResult(?array $test_result, ?array $test_config, ?array $working_time)
testReadStatus(array $query_result, array $expected)
testReadFromCache(array $query, array $cached_status, array $expected)
mockReadResultStatusQuery(?array $fetch_assoc_return)
mockGetResultQuery(string $table, ?array $fetch_assoc_return)
testGetTestAttemptResultNotFound()
createMarksRepositoryMock(?array $mock_data)
testGetTestResultNotFound()
testGetPassedParticipants(int $test_obj_id, array $query_result)
static provideFetchedTestResult()
This method returns sample data for these queries:
static provideTestAttemptResult()
This method returns sample data for this query:
static provideFetchedTestAttemptResult()
This method returns sample data for this query:
testUpdateTestAttemptResult(array $parameters, array $test_result, array $test_config_result, array $working_time_result, array $expected)
static provideCachedStatus()
This method returns test parameter, sample data and expected results for testing status cache.
mockGetPassedParticipants(array $fetch_all_return)
mockGetTestPassResultQuery(?array $fetch_assoc_return)
mockGetTestResultQuery(?array $fetch_assoc_return)
static providePassedParticipants()
This method returns sample data for this query:
testFailedPassedNotFound()
createInstance(?array $mock_data=null)
static provideTestResultCache()
This method returns sample data for this query:
__construct()
Constructor setup ILIAS global object @access public.
const QUESTION_SET_TYPE_FIXED
adaptDICServiceMock(string $service_name, callable $adapt)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.