Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Imangazaliev authored and Imangazaliev committed Oct 16, 2016
1 parent 6d125ba commit 2157726
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/DiDom/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,11 @@ public function getElement()
*/
public function toElement()
{
return new Element($this->getElement());
if ($this->document->documentElement === null) {
throw new RuntimeException('Cannot convert empty document to Element');
}

return new Element($this->document->documentElement);
}

/**
Expand Down
10 changes: 10 additions & 0 deletions tests/DiDom/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,16 @@ public function testGetElement()
$this->assertInstanceOf('DOMElement', $document->getElement());
}

/**
* @expectedException RuntimeException
*/
public function testEmptyDocumentToElement()
{
$document = new Document();

$document->toElement();
}

public function testToElement()
{
$html = $this->loadFixture('posts.html');
Expand Down

0 comments on commit 2157726

Please sign in to comment.