Skip to content

Commit 6b04553

Browse files
author
Harrison Ifeanyichukwu
committed
test: test the XML module functionalities, parsing, error reporting and returned document
1 parent 26968b2 commit 6b04553

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

tests/XMLTest.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
declare(strict_types = 1);
3+
4+
namespace Forensic\FeedParser\Test;
5+
6+
use Forensic\FeedParser\XML;
7+
use PHPUnit\Framework\TestCase;
8+
9+
class XMLTest extends TestCase
10+
{
11+
private $_xml = null;
12+
13+
public function setup()
14+
{
15+
$this->_xml = new XML();
16+
}
17+
18+
public function testInitialState()
19+
{
20+
$this->assertSame(false, $this->_xml->status());
21+
$this->assertNull($this->_xml->document());
22+
}
23+
24+
public function testErronousDocumentParse()
25+
{
26+
$xml = <<<'XML'
27+
<?xml version='1.0' standalone='yes'?>
28+
<movies>
29+
<movie>
30+
<titles>PHP: Behind the Parser</title>
31+
</movie>
32+
</movies>
33+
XML;
34+
$this->_xml->parse($xml);
35+
$this->assertGreaterThan(0, count($this->_xml->errors()));
36+
$this->assertFalse($this->_xml->status());
37+
$this->assertNull($this->_xml->document());
38+
}
39+
40+
public function testCorrectDocumentParse()
41+
{
42+
$xml = <<<'XML'
43+
<?xml version='1.0' standalone='yes'?>
44+
<movies>
45+
<movie>
46+
<titles>PHP: Behind the Parser</titles>
47+
</movie>
48+
</movies>
49+
XML;
50+
$this->_xml->parse($xml);
51+
52+
$this->assertEquals(0, count($this->_xml->errors()));
53+
$this->assertTrue($this->_xml->status());
54+
$this->assertInstanceOf('DOMDocument', $this->_xml->document());
55+
}
56+
}

0 commit comments

Comments
 (0)