44
55namespace SimpleSAML \Test \XPath ;
66
7+ use DOMDocument ;
8+ use DOMElement ;
79use PHPUnit \Framework \Attributes \CoversClass ;
810use PHPUnit \Framework \TestCase ;
911use SimpleSAML \XPath \XPath ;
12+ use Throwable ;
13+
14+ use function libxml_clear_errors ;
15+ use function libxml_use_internal_errors ;
1016
1117/**
1218 * Tests for the SimpleSAML\XPath\XPath helper.
@@ -17,7 +23,7 @@ final class XPathTest extends TestCase
1723 public function testGetXPathCachesPerDocumentAndRegistersCoreNamespaces (): void
1824 {
1925 // Doc A with an xml:space attribute to validate 'xml' prefix usage works
20- $ docA = new \ DOMDocument ();
26+ $ docA = new DOMDocument ();
2127 $ docA ->loadXML (<<<'XML'
2228<?xml version="1.0" encoding="UTF-8"?>
2329<root xml:space="preserve" xmlns:xml="http://www.w3.org/XML/1998/namespace">
@@ -26,7 +32,7 @@ public function testGetXPathCachesPerDocumentAndRegistersCoreNamespaces(): void
2632XML);
2733
2834 // Doc B is different
29- $ docB = new \ DOMDocument ();
35+ $ docB = new DOMDocument ();
3036 $ docB ->loadXML (<<<'XML'
3137<?xml version="1.0" encoding="UTF-8"?>
3238<another><node/></another>
@@ -43,7 +49,7 @@ public function testGetXPathCachesPerDocumentAndRegistersCoreNamespaces(): void
4349
4450 // 'xml' prefix registered: query should be valid and return xml:space attribute
4551 $ rootA = $ docA ->documentElement ;
46- $ this ->assertInstanceOf (\ DOMElement::class, $ rootA );
52+ $ this ->assertInstanceOf (DOMElement::class, $ rootA );
4753 $ attrs = XPath::xpQuery ($ rootA , '@xml:space ' , $ xpA1 );
4854 $ this ->assertCount (1 , $ attrs );
4955 $ this ->assertSame ('preserve ' , $ attrs [0 ]->nodeValue );
@@ -63,7 +69,7 @@ public function testAncestorNamespaceRegistrationAllowsCustomPrefixes(): void
6369 </a>
6470</r>
6571XML;
66- $ doc = new \ DOMDocument ();
72+ $ doc = new DOMDocument ();
6773 $ doc ->loadXML ($ xml );
6874
6975 // Use a deep context node to ensure ancestor-walk picks up xmlns:foo from root
@@ -80,29 +86,29 @@ public function testAncestorNamespaceRegistrationAllowsCustomPrefixes(): void
8086
8187 public function testXpQueryThrowsOnMalformedExpression (): void
8288 {
83- $ doc = new \ DOMDocument ();
89+ $ doc = new DOMDocument ();
8490 $ doc ->loadXML ('<root><x/></root> ' );
8591 $ xp = XPath::getXPath ($ doc );
8692
87- // If xpQuery throws a specific exception, put that class here instead of \ Throwable.
88- $ this ->expectException (\ Throwable::class);
93+ // If xpQuery throws a specific exception, put that class here instead of Throwable.
94+ $ this ->expectException (Throwable::class);
8995 // Keep message assertion resilient to libxml version differences.
9096 $ this ->expectExceptionMessageMatches ('/(XPath|expression).*invalid|malformed|error/i ' );
9197
9298 // Malformed XPath: missing closing bracket
9399 $ root = $ doc ->documentElement ;
94- $ this ->assertInstanceOf (\ DOMElement::class, $ root );
100+ $ this ->assertInstanceOf (DOMElement::class, $ root );
95101
96102 // Avoid emitting a PHP warning; let xpQuery surface it as an exception.
97- \ libxml_use_internal_errors (true );
103+ libxml_use_internal_errors (true );
98104 try {
99105 XPath::xpQuery ($ root , '//*[ ' , $ xp );
100106 } finally {
101- $ errors = \ libxml_get_errors ();
107+ $ errors = libxml_get_errors ();
102108 self ::assertCount (1 , $ errors );
103109 self ::assertEquals ("Invalid expression \n" , $ errors [0 ]->message );
104- \ libxml_clear_errors ();
105- \ libxml_use_internal_errors (false );
110+ libxml_clear_errors ();
111+ libxml_use_internal_errors (false );
106112 }
107113 }
108114}
0 commit comments