Skip to content

Commit 2157726

Browse files
ImangazalievImangazaliev
Imangazaliev
authored and
Imangazaliev
committed
More tests
1 parent 6d125ba commit 2157726

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/DiDom/Document.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,11 @@ public function getElement()
489489
*/
490490
public function toElement()
491491
{
492-
return new Element($this->getElement());
492+
if ($this->document->documentElement === null) {
493+
throw new RuntimeException('Cannot convert empty document to Element');
494+
}
495+
496+
return new Element($this->document->documentElement);
493497
}
494498

495499
/**

tests/DiDom/DocumentTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,16 @@ public function testGetElement()
477477
$this->assertInstanceOf('DOMElement', $document->getElement());
478478
}
479479

480+
/**
481+
* @expectedException RuntimeException
482+
*/
483+
public function testEmptyDocumentToElement()
484+
{
485+
$document = new Document();
486+
487+
$document->toElement();
488+
}
489+
480490
public function testToElement()
481491
{
482492
$html = $this->loadFixture('posts.html');

0 commit comments

Comments
 (0)