19declare(strict_types=1);
24use PHPUnit\Framework\TestCase;
31 $this->assertSame(0, $list->count());
32 $this->assertSame(
'', $list->toString());
33 $this->assertSame([], $list->getInvalidParts());
39 $this->assertSame(0, $list->count());
40 $this->assertSame(
'', $list->toString());
41 $this->assertSame([], $list->getInvalidParts());
47 $this->assertSame(1, $list->count());
48 $this->assertSame(
'ldap://host.example.com:389', $list->getConnectionStringAtIndex(0));
49 $this->assertSame(
'', $list->getConnectionStringAtIndex(1));
50 $this->assertSame([], $list->getInvalidParts());
51 $this->assertSame(
'ldap://host.example.com:389', $list->toString());
56 $input =
'host.example.com:389';
58 $this->assertSame(1, $list->count());
59 $this->assertSame($input, $list->getConnectionStringAtIndex(0));
60 $this->assertSame([$input], $list->getInvalidParts());
61 $this->assertSame($input, $list->toString());
67 $this->assertSame(1, $list->count());
68 $this->assertSame(
'ldaps://secure.example.com:636', $list->getConnectionStringAtIndex(0));
73 $stored =
'ldap://a.example:389,ldaps://b.example:636';
75 $this->assertSame(2, $list->count());
76 $this->assertSame(
'ldap://a.example:389', $list->getConnectionStringAtIndex(0));
77 $this->assertSame(
'ldaps://b.example:636', $list->getConnectionStringAtIndex(1));
78 $this->assertSame([], $list->getInvalidParts());
79 $this->assertSame($stored, $list->toString());
86 $this->assertSame(1, $list->count());
87 $this->assertSame($invalid, $list->getConnectionStringAtIndex(0));
88 $this->assertSame([$invalid], $list->getInvalidParts());
89 $this->assertSame($invalid, $list->toString());
95 $stored =
'ldap://ok:389,' . $invalid .
',ldaps://also:636';
97 $this->assertSame(3, $list->count());
98 $this->assertSame(
'ldap://ok:389', $list->getConnectionStringAtIndex(0));
99 $this->assertSame($invalid, $list->getConnectionStringAtIndex(1));
100 $this->assertSame(
'ldaps://also:636', $list->getConnectionStringAtIndex(2));
101 $this->assertSame([$invalid], $list->getInvalidParts());
102 $this->assertSame($stored, $list->toString(),
'toString() must preserve order and use comma delimiter');
108 $this->assertSame(
'', $list->getConnectionStringAtIndex(-1));
114 $this->assertSame(
'', $list->getConnectionStringAtIndex(1));
115 $this->assertSame(
'', $list->getConnectionStringAtIndex(99));
121 $rotated = $list->rotate();
122 $this->assertNotSame($list, $rotated,
'rotate() must return new instance when count >= 2');
123 $this->assertSame(2, $rotated->count());
124 $this->assertSame(
'ldap://second:389', $rotated->getConnectionStringAtIndex(0));
125 $this->assertSame(
'ldap://first:389', $rotated->getConnectionStringAtIndex(1));
126 $this->assertSame(
'ldap://second:389,ldap://first:389', $rotated->toString());
132 $rotated = $list->rotate();
133 $this->assertSame($list, $rotated,
'rotate() must return this when count < 2');
134 $this->assertSame(1, $rotated->count());
135 $this->assertSame(
'ldap://only:389', $rotated->getConnectionStringAtIndex(0));
141 $rotated = $list->rotate();
142 $this->assertSame($list, $rotated,
'rotate() must return this when count < 2');
143 $this->assertSame(0, $rotated->count());
144 $this->assertSame(
'', $rotated->toString());
150 $reordered = $list->withPrimaryAt(0);
151 $this->assertSame(
'ldap://a:389', $reordered->getConnectionStringAtIndex(0));
152 $this->assertSame(
'ldap://b:389', $reordered->getConnectionStringAtIndex(1));
153 $this->assertSame(
'ldap://a:389,ldap://b:389', $reordered->toString());
159 $reordered = $list->withPrimaryAt(1);
160 $this->assertNotSame($list, $reordered,
'withPrimaryAt() must return new instance when index valid');
161 $this->assertSame(2, $reordered->count());
162 $this->assertSame(
'ldap://b:389', $reordered->getConnectionStringAtIndex(0));
163 $this->assertSame(
'ldap://a:389', $reordered->getConnectionStringAtIndex(1));
164 $this->assertSame(
'ldap://b:389,ldap://a:389', $reordered->toString());
170 $reordered = $list->withPrimaryAt(5);
171 $this->assertSame($list, $reordered,
'withPrimaryAt() must return this when index out of range');
172 $this->assertSame(
'ldap://a:389', $reordered->getConnectionStringAtIndex(0));
178 $reordered = $list->withPrimaryAt(-1);
179 $this->assertSame($list, $reordered,
'withPrimaryAt() must return this when index negative');
180 $this->assertSame(
'ldap://a:389', $reordered->getConnectionStringAtIndex(0));
181 $this->assertSame(
'ldap://b:389', $reordered->getConnectionStringAtIndex(1));
188 foreach ($list->validUrls() as $index => $uri) {
189 $collected[$index] = $uri;
191 $this->assertCount(2, $collected);
192 $this->assertInstanceOf(\
ILIAS\
Data\URI::class, $collected[0]);
193 $this->assertInstanceOf(\
ILIAS\
Data\URI::class, $collected[1]);
194 $this->assertSame(
'ldap://a:389', (
string) $collected[0]);
195 $this->assertSame(
'ldap://b:389', (
string) $collected[1]);
202 foreach ($list->validUrls() as $index => $uri) {
203 $collected[$index] = $uri;
205 $this->assertCount(1, $collected);
206 $this->assertArrayHasKey(0, $collected);
207 $this->assertInstanceOf(\
ILIAS\
Data\URI::class, $collected[0]);
208 $this->assertSame(
'ldap://ok:389', (
string) $collected[0]);
215 foreach ($list->validUrls() as $index => $uri) {
216 $collected[$index] = $uri;
218 $this->assertCount(0, $collected);
223 $invalid =
'ldap://';
225 $this->assertSame(3, $list->count());
228 foreach ($list->validUrls() as $index => $uri) {
231 $this->assertSame([0, 2], $indices);
233 $reordered = $list->withPrimaryAt(2);
234 $this->assertSame(3, $reordered->count());
235 $this->assertSame(
'ldap://third:389', $reordered->getConnectionStringAtIndex(0));
236 $this->assertSame(
'ldap://first:389', $reordered->getConnectionStringAtIndex(1));
237 $this->assertSame($invalid, $reordered->getConnectionStringAtIndex(2));
238 $this->assertSame(
'ldap://third:389,ldap://first:389,' . $invalid, $reordered->toString());
240 $reorderedInvalid = $list->withPrimaryAt(1);
241 $this->assertSame($invalid, $reorderedInvalid->getConnectionStringAtIndex(0));
242 $this->assertSame(
'ldap://first:389', $reorderedInvalid->getConnectionStringAtIndex(1));
243 $this->assertSame(
'ldap://third:389', $reorderedInvalid->getConnectionStringAtIndex(2));
249 $this->assertSame($list->toString(), (
string) $list);
255 $this->assertSame(0, $list->count());
256 $this->assertSame(
'', $list->toString());
257 $this->assertSame([], $list->getInvalidParts());
266 $this->assertSame(2, $list->count());
267 $this->assertSame(
'ldap://first:389', $list->getConnectionStringAtIndex(0));
268 $this->assertSame(
'ldap://second:389', $list->getConnectionStringAtIndex(1));
280 $this->assertSame(2, $list->count());
281 $this->assertSame(
'ldap://first:389', $list->getConnectionStringAtIndex(0));
282 $this->assertSame(
'ldap://second:389', $list->getConnectionStringAtIndex(1));
283 $this->assertSame(
'', $list->getConnectionStringAtIndex(2));
292 $this->assertSame(1, $list->count());
293 $this->assertSame(
'ldap://only:389', $list->getConnectionStringAtIndex(0));
294 $this->assertSame(
'ldap://only:389', $list->toString());
302 $raw =
'not-a-valid-uri';
304 $this->assertSame(1, $list->count());
305 $this->assertSame($raw, $list->getConnectionStringAtIndex(0));
306 $this->assertSame([$raw], $list->getInvalidParts());
The scope of this class is split ilias-conform URI's into components.
Value object representing a list of LDAP server URLs (primary plus fallbacks).
static fromString(string $stored)
Create from string representation (comma-separated, as stored in DB or form).
testRotateWithOneEntryReturnsSameInstance()
testFromStringInvalidPartStoredAsRawAndReportedInGetInvalidParts()
testFromStringLdapsPreserved()
testRotateEmptyListReturnsSameInstance()
testFromStringMixedValidAndInvalid()
testFromStringEmptyYieldsEmptyList()
testFromStringOnlyWhitespaceAndCommasYieldsEmptyList()
testWithPrimaryAtNegativeIndexReturnsSameInstance()
testFromStringMultipleValidUris()
testValidUrlsSkipsInvalidParts()
testGetConnectionStringAtIndexNegativeIndexReturnsEmptyString()
testWithPrimaryAtZeroReturnsSameOrder()
testFromStringSkipsEmptyPartsAfterTrim()
fromString must skip empty parts after trim (mutant that removes "continue" would add empty entries).
testConstructorWithEmptyArray()
testWithPrimaryAtOutOfRangeReturnsSameInstance()
testToStringDelegatesToMagicToString()
testGetConnectionStringAtIndexOutOfRangePositiveReturnsEmptyString()
testFromStringHostWithoutSchemeStoredAsInvalid()
testWithPrimaryAtOneMovesSecondToFirst()
testRotateWithTwoEntriesMovesFirstToEnd()
testValidUrlsYieldsOnlyUriInstances()
testConstructorPreservesOrderWithArrayValues()
testValidUrlsYieldsNothingWhenAllInvalid()
testConstructorWithNonSequentialKeysRebasesToZeroBasedIndices()
Constructor must reindex with array_values() so indices are 0-based (mutant that removes array_values...
testGetConnectionStringAtIndexReturnsRawStringForInvalidEntry()
getConnectionStringAtIndex must return string for raw (non-URI) entry.
testValidUrlsYieldsOriginalIndicesWithPrimaryAtCorrectWithMixedValidAndInvalid()
testFromStringSingleValidUri()
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.