Skip to content

Commit d21ed68

Browse files
committed
Fix tests
1 parent 9e6c9d6 commit d21ed68

4 files changed

Lines changed: 23 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88

99
## [Unreleased](https://github.com/inspirum/xml-php/compare/v3.1.2...master)
10+
### Changed
11+
- Skip `\DOMNameSpaceNode` in `Node::xpath` method
1012

1113

1214
## [v3.1.2 (2025-03-24)](https://github.com/inspirum/xml-php/compare/v3.1.1...v3.1.2)

src/Builder/BaseNode.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use DOMDocumentFragment;
99
use DOMElement;
1010
use DOMException;
11+
use DOMNameSpaceNode;
1112
use DOMNode;
1213
use DOMText;
1314
use DOMXPath;
@@ -310,6 +311,10 @@ public function xpath(string $expression): ?array
310311

311312
$results = [];
312313
foreach ($nodes as $node) {
314+
if ($node instanceof DOMNameSpaceNode) {
315+
continue;
316+
}
317+
313318
$results[] = $this->createElementFromNode($node);
314319
}
315320

src/Reader/Reader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface Reader
1111
/**
1212
* Parse file by node name or node xpath and yield next node
1313
*
14-
* @return iterable<\Inspirum\XML\Builder\Node>
14+
* @return iterable<int,\Inspirum\XML\Builder\Node>
1515
*
1616
* @throws \Exception
1717
*/

tests/Reader/DefaultReaderTest.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,8 @@ public function testIteratePathMultipleNamespaces(): void
372372
}
373373

374374
/**
375-
* @param array<list<string>|string> $expected
376-
* @param array<list<string>|string>|null $expectedOverride
375+
* @param list<list<string>|string> $expected
376+
* @param list<list<string>|string>|null $expectedOverride
377377
*/
378378
#[DataProvider('provideIterateXpath')]
379379
public function testIterateWithSimpleLoadString(string $file, bool $withNamespaces, string $path, array $expected, ?array $expectedOverride = null): void
@@ -412,8 +412,8 @@ public function testIterateWithSimpleLoadString(string $file, bool $withNamespac
412412
}
413413

414414
/**
415-
* @param array<list<string>|string> $expected
416-
* @param array<list<string>|string>|null $expectedOverride
415+
* @param list<list<string>|string> $expected
416+
* @param list<list<string>|string>|null $expectedOverride
417417
*/
418418
#[DataProvider('provideIterateXpath')]
419419
public function testIterateWithXpath(string $file, bool $withNamespaces, string $path, array $expected, ?array $expectedOverride = null): void
@@ -562,6 +562,17 @@ public static function provideIterateXpath(): iterable
562562
[],
563563
],
564564
];
565+
566+
yield [
567+
'file' => 'sample_08.xml',
568+
'withNamespaces' => true,
569+
'path' => 'namespace::*',
570+
'expected' => [
571+
[],
572+
[],
573+
[],
574+
],
575+
];
565576
}
566577

567578
public function testRealUsage(): void

0 commit comments

Comments
 (0)