Skip to content

Commit f0a03aa

Browse files
[FEATURE] KeyValueStorage: Add missing test classes
1 parent af97ce6 commit f0a03aa

2 files changed

Lines changed: 133 additions & 0 deletions

File tree

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
/**
4+
* This file is part of ILIAS, a powerful learning management system
5+
* published by ILIAS open source e-Learning e.V.
6+
*
7+
* ILIAS is licensed with the GPL-3.0,
8+
* see https://www.gnu.org/licenses/gpl-3.0.en.html
9+
* You should have received a copy of said license along with the
10+
* source code, too.
11+
*
12+
* If this is not the case or you just want to try ILIAS, you'll find
13+
* us at:
14+
* https://www.ilias.de
15+
* https://github.com/ILIAS-eLearning
16+
*
17+
*********************************************************************/
18+
19+
declare(strict_types=1);
20+
21+
namespace ILIAS\Tests\KeyValueStorage\Internal;
22+
23+
use ILIAS\KeyValueStorage\Internal\StorageNamespace;
24+
use PHPUnit\Framework\Attributes\DataProvider;
25+
use PHPUnit\Framework\TestCase;
26+
27+
class StorageNamespaceTest extends TestCase
28+
{
29+
/**
30+
* @param list<string> $segments
31+
*/
32+
#[DataProvider('validNamespaces')]
33+
public function testValidNamespacesAreAccepted(array $segments, string $value): void
34+
{
35+
$namespace = new StorageNamespace($segments);
36+
37+
$this->assertSame($value, $namespace->value());
38+
$this->assertSame($value, (string) $namespace);
39+
}
40+
41+
/**
42+
* @return array<string, array{list<string>, string}>
43+
*/
44+
public static function validNamespaces(): array
45+
{
46+
return [
47+
'single segment' => [['ui'], 'ui'],
48+
'two segments' => [['ui', 'storage'], 'ui.storage'],
49+
'many segments' => [['my_component', 'view_state', 'table'], 'my_component.view_state.table'],
50+
'uppercase' => [['Ui', 'Storage'], 'Ui.Storage'],
51+
'leading digit' => [['1ui'], '1ui'],
52+
'hyphen' => [['ui-storage'], 'ui-storage'],
53+
'backslash' => [['ILIAS\\UI'], 'ILIAS\\UI'],
54+
'maximum length' => [[str_repeat('a', StorageNamespace::MAX_LENGTH)], str_repeat('a', StorageNamespace::MAX_LENGTH)],
55+
];
56+
}
57+
58+
/**
59+
* @param list<mixed> $segments
60+
*/
61+
#[DataProvider('invalidNamespaces')]
62+
public function testInvalidNamespacesAreRejected(array $segments): void
63+
{
64+
$this->expectException(\InvalidArgumentException::class);
65+
66+
new StorageNamespace($segments);
67+
}
68+
69+
/**
70+
* @return array<string, array{list<mixed>}>
71+
*/
72+
public static function invalidNamespaces(): array
73+
{
74+
return [
75+
'empty list' => [[]],
76+
'empty segment' => [['ui', '']],
77+
'dot in segment' => [['ui.storage']],
78+
'colon in segment' => [['ui:storage']],
79+
'control character' => [["ui\nstorage"]],
80+
'non-string segment' => [['ui', 1]],
81+
'too long' => [[str_repeat('a', StorageNamespace::MAX_LENGTH + 1)]],
82+
];
83+
}
84+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
/**
4+
* This file is part of ILIAS, a powerful learning management system
5+
* published by ILIAS open source e-Learning e.V.
6+
*
7+
* ILIAS is licensed with the GPL-3.0,
8+
* see https://www.gnu.org/licenses/gpl-3.0.en.html
9+
* You should have received a copy of said license along with the
10+
* source code, too.
11+
*
12+
* If this is not the case or you just want to try ILIAS, you'll find
13+
* us at:
14+
* https://www.ilias.de
15+
* https://github.com/ILIAS-eLearning
16+
*
17+
*********************************************************************/
18+
19+
declare(strict_types=1);
20+
21+
namespace ILIAS\Tests\KeyValueStorage;
22+
23+
use ILIAS\Data\Factory as DataFactory;
24+
use ILIAS\Refinery\Factory as Refinery;
25+
use ILIAS\Refinery\Transformation;
26+
27+
trait RefineryHelper
28+
{
29+
private function refinery(): Refinery
30+
{
31+
$language = $this->getMockBuilder(\ilLanguage::class)
32+
->disableOriginalConstructor()
33+
->getMock();
34+
35+
return new Refinery(new DataFactory(), $language);
36+
}
37+
38+
private function asStored(): Transformation
39+
{
40+
return $this->refinery()->identity();
41+
}
42+
43+
private function withDefault(mixed $default): Transformation
44+
{
45+
return $this->refinery()->custom()->transformation(
46+
static fn(mixed $value): mixed => $value ?? $default
47+
);
48+
}
49+
}

0 commit comments

Comments
 (0)