From 6aa2ddfe1c9d4e29bbc3bd2d413cc5b55d17de10 Mon Sep 17 00:00:00 2001 From: fluffycondor <7ionmail@gmail.com> Date: Wed, 31 Jan 2024 15:39:54 +0600 Subject: [PATCH] Fix ownerDocument type --- dictionaries/PropertyMap.php | 3 ++- stubs/extensions/dom.phpstub | 6 ++++-- tests/CoreStubsTest.php | 14 ++++++++++++++ tests/PropertyTypeTest.php | 2 +- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/dictionaries/PropertyMap.php b/dictionaries/PropertyMap.php index c5755235e..521a1e7e3 100644 --- a/dictionaries/PropertyMap.php +++ b/dictionaries/PropertyMap.php @@ -113,6 +113,7 @@ return [ 'formatOutput' => 'bool', 'implementation' => 'DOMImplementation', 'lastElementChild' => 'DOMElement|null', + 'ownerDocument' => 'null', 'preserveWhiteSpace' => 'bool', 'recover' => 'bool', 'resolveExternals' => 'bool', @@ -173,7 +174,7 @@ return [ 'nodeName' => 'string', 'nodeType' => 'int', 'nodeValue' => 'string|null', - 'ownerDocument' => 'DOMDocument|null', + 'ownerDocument' => 'DOMDocument', 'parentNode' => 'DOMNode|null', 'prefix' => 'string', 'previousSibling' => 'DOMNode|null', diff --git a/stubs/extensions/dom.phpstub b/stubs/extensions/dom.phpstub index 2520a4799..b240a8d14 100644 --- a/stubs/extensions/dom.phpstub +++ b/stubs/extensions/dom.phpstub @@ -154,7 +154,7 @@ class DOMNode */ public ?DOMNamedNodeMap $attributes; /** @readonly */ - public ?DOMDocument $ownerDocument; + public DOMDocument $ownerDocument; /** @readonly */ public ?string $namespaceURI; public string $prefix; @@ -242,7 +242,7 @@ class DOMNameSpaceNode /** @readonly */ public ?string $namespaceURI; /** @readonly */ - public ?DOMDocument $ownerDocument; + public DOMDocument $ownerDocument; /** @readonly */ public ?DOMNode $parentNode; } @@ -281,6 +281,8 @@ class DOMDocument extends DOMNode implements DOMParentNode public DOMImplementation $implementation; /** @readonly */ public ?DOMElement $documentElement; + /** @readonly */ + public null $ownerDocument; /** * @deprecated diff --git a/tests/CoreStubsTest.php b/tests/CoreStubsTest.php index b01898970..142be4a3e 100644 --- a/tests/CoreStubsTest.php +++ b/tests/CoreStubsTest.php @@ -424,6 +424,20 @@ class CoreStubsTest extends TestCase $globBrace = glob('abc', GLOB_BRACE); PHP, ]; + yield "ownerDocument's type is non-nullable DOMDocument and always null on DOMDocument itself" => [ + 'code' => 'ownerDocument; + $b = (new DOMNode())->ownerDocument; + $c = (new DOMElement("p"))->ownerDocument; + $d = (new DOMNameSpaceNode())->ownerDocument; + ', + 'assertions' => [ + '$a===' => 'null', + '$b===' => 'DOMDocument', + '$c===' => 'DOMDocument', + '$d===' => 'DOMDocument', + ], + ]; } public function providerInvalidCodeParse(): iterable diff --git a/tests/PropertyTypeTest.php b/tests/PropertyTypeTest.php index bf8e00f4e..3d0662104 100644 --- a/tests/PropertyTypeTest.php +++ b/tests/PropertyTypeTest.php @@ -718,7 +718,7 @@ class PropertyTypeTest extends TestCase $a = new DOMElement("foo"); $owner = $a->ownerDocument;', 'assertions' => [ - '$owner' => 'DOMDocument|null', + '$owner' => 'DOMDocument', ], ], 'propertyMapHydration' => [