ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilAssQuestionSkillAssignmentRegistryTest.php
Go to the documentation of this file.
1<?php
2
23{
24 public const TEST_KEY = 'phpunit_tst';
25
29 protected array $storage = [];
30
31 public function setUp(): void
32 {
33 parent::setUp();
34
35 $this->storage = [];
36 }
37
44 #[\PHPUnit\Framework\Attributes\DataProvider('serializedData')]
45 public function testSkillAssignmentsCanBetStoredAndFetchedBySerializationStrategy($value, $chunkSize, callable $preCallback, callable $postCallback): void
46 {
47 $this->markTestSkipped('Data Provider needs to be revisited.');
48
49 $settingsMock = $this->getMockBuilder('ilSetting')->disableOriginalConstructor()->onlyMethods(['set', 'get', 'delete'])->getMock();
50
51 $settingsMock->expects($this->any())->method('set')->willReturnCallback(
52 function ($key, $value) {
53 $this->storage[$key] = $value;
54 }
55 );
56
57 $settingsMock->expects($this->any())->method('get')->willReturnCallback(
58 function ($key, $value) {
59 return $this->storage[$key] ?? $value;
60 }
61 );
62
63 $settingsMock->expects($this->any())->method('delete')->willReturnCallback(
64 function ($key) {
65 if (isset($this->storage[$key])) {
66 unset($this->storage[$key]);
67 }
68 }
69 );
70
71 $valueToTest = $preCallback($value);
72
73 $registry = new ilAssQuestionSkillAssignmentRegistry($settingsMock);
74 $registry->setChunkSize($chunkSize);
75 $registry->setStringifiedImports(self::TEST_KEY, $valueToTest);
76 $actual = $registry->getStringifiedImports(self::TEST_KEY);
77
78 $this->assertEquals($valueToTest, $actual);
79 $this->assertEquals($value, $postCallback($actual));
80 }
81
82 #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions]
84 {
85 $settingsMock = $this->getMockBuilder('ilSetting')->disableOriginalConstructor()->onlyMethods(['set', 'get', 'delete'])->getMock();
86
87 try {
88 $registry = new ilAssQuestionSkillAssignmentRegistry($settingsMock);
89 $registry->setChunkSize('a');
90 $this->fail('Failed asserting that exception of type "InvalidArgumentException" is thrown.');
91 } catch (InvalidArgumentException $e) {
92 }
93
94 try {
95 $registry = new ilAssQuestionSkillAssignmentRegistry($settingsMock);
96 $registry->setChunkSize(-5);
97 $this->fail('Failed asserting that exception of type "InvalidArgumentException" is thrown.');
98 } catch (InvalidArgumentException $e) {
99 }
100 }
101
107 protected static function getTestData(callable $pre, callable $post): array
108 {
109 $data = [];
110
111 $assignmentList = new ilAssQuestionSkillAssignmentImportList();
112
113 for ($i = 0; $i < 5; $i++) {
114 $assignment = new ilAssQuestionSkillAssignmentImport();
116 $assignment->setImportSkillTitle('phpunit' . $i);
117 $assignment->setImportSkillPath('phpunit' . $i);
118 $random = new \Random\Randomizer();
119 $assignment->setSkillPoints($random->getInt(0, PHP_INT_MAX));
120 $assignment->setImportQuestionId($random->getInt(0, PHP_INT_MAX));
121 $assignment->setImportSkillBaseId($random->getInt(0, PHP_INT_MAX));
122 $assignment->setImportSkillTrefId($random->getInt(0, PHP_INT_MAX));
123
124 $assignmentList->addAssignment($assignment);
125 }
126
127 $rawData = [
128 ['This is a Test', 2],
129 [['üäöÖÜÄÖß'], 2],
130 ['This is a Test with a huge chunk size', 10000],
131 [$assignmentList, 7],
132 ];
133
134 foreach ($rawData as $rawItem) {
135 $data[] = [$rawItem[0], $rawItem[1], $pre, $post];
136 }
137
138 return $data;
139 }
140
144 public static function serializedData(): array
145 {
146 $pre = function ($value) {
147 return serialize($value);
148 };
149
150 $post = function ($value) {
151 return unserialize($value);
152 };
153
154 return self::getTestData($pre, $post);
155 }
156}
Class assBaseTestCase.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
testSkillAssignmentsCanBetStoredAndFetchedBySerializationStrategy($value, $chunkSize, callable $preCallback, callable $postCallback)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$post
Definition: ltitoken.php:46