Skip to content

Commit efbd444

Browse files
authored
Merge pull request #277 from phil-davis/precise-clark-notation-v3
More precise parseClarkNotation return type (v3)
2 parents 489c8d6 + 604e540 commit efbd444

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

lib/Service.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public function writeValueObject(object $object, ?string $contextUri = null): st
281281
*
282282
* If the string was invalid, it will throw an InvalidArgumentException.
283283
*
284-
* @return array{string|null, string}
284+
* @return array{string, string}
285285
*
286286
* @throws \InvalidArgumentException
287287
*/

lib/Writer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function startElement($name): bool
134134
} else {
135135
// An empty namespace means it's the global namespace. This is
136136
// allowed, but it mustn't get a prefix.
137-
if ('' === $namespace || null === $namespace) {
137+
if ('' === $namespace) {
138138
$result = $this->startElement($localName);
139139
$this->writeAttribute('xmlns', '');
140140
} else {

tests/Sabre/Xml/ServiceTest.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,14 @@ public function testWriteVoNotFound(): void
346346
$service->writeValueObject(new \stdClass());
347347
}
348348

349-
public function testParseClarkNotation(): void
349+
/**
350+
* @param array<string> $expected
351+
*
352+
* @dataProvider provideParseClarkNotationInput
353+
*/
354+
public function testParseClarkNotation(string $clark, array $expected): void
350355
{
351-
self::assertEquals([
352-
'http://sabredav.org/ns',
353-
'elem',
354-
], Service::parseClarkNotation('{http://sabredav.org/ns}elem'));
356+
self::assertEquals($expected, Service::parseClarkNotation($clark));
355357
}
356358

357359
public function testParseClarkNotationFail(): void
@@ -360,6 +362,17 @@ public function testParseClarkNotationFail(): void
360362
Service::parseClarkNotation('http://sabredav.org/ns}elem');
361363
}
362364

365+
/**
366+
* @return array<int, list{string, array<string>}>
367+
*/
368+
public function provideParseClarkNotationInput(): iterable
369+
{
370+
return [
371+
['{http://sabredav.org/ns}elem', ['http://sabredav.org/ns', 'elem']],
372+
['{}elem', ['', 'elem']],
373+
];
374+
}
375+
363376
/**
364377
* @return array<int, array<int, string|resource|false>>
365378
*/

0 commit comments

Comments
 (0)