XmlReaderTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 41
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testSimple() 0 18 2
A testXpath() 0 17 2
1
<?php
2
namespace Mathielen\DataImport\Reader;
3
4
class XmlReaderTest extends \PHPUnit_Framework_TestCase
5
{
6
7
    public function testSimple()
8
    {
9
        $reader = new XmlReader(new \SplFileObject('tests/metadata/testfiles/hierarchicaldata-xml.xml'));
10
11
        $this->assertEquals(2, count($reader));
12
        $this->assertEquals(array('attr1'), $reader->getFields());
13
        $this->assertEquals(array('value1'=>'1', '@attributes'=>array('attr1'=>'a')), $reader->current());
14
15
        $actualData = array();
16
        $expectedData = array(
17
            array('value1'=>'1', '@attributes'=>array('attr1'=>'a')),
18
            array('value1'=>'2', '@attributes'=>array('attr2'=>'b'))
19
        );
20
        foreach ($reader as $key=>$row) {
21
            $actualData[] = $row;
22
        }
23
        $this->assertEquals($expectedData, $actualData);
24
    }
25
26
    public function testXpath()
27
    {
28
        $reader = new XmlReader(new \SplFileObject('tests/metadata/testfiles/hierarchicaldata-xml.xml'), "/root/node[@attr2='b']");
29
30
        $this->assertEquals(1, count($reader));
31
        $this->assertEquals(array('attr2'), $reader->getFields());
32
        $this->assertEquals(array('value1'=>'2', '@attributes'=>array('attr2'=>'b')), $reader->current());
33
34
        $actualData = array();
35
        $expectedData = array(
36
            array('value1'=>'2', '@attributes'=>array('attr2'=>'b'))
37
        );
38
        foreach ($reader as $key=>$row) {
39
            $actualData[] = $row;
40
        }
41
        $this->assertEquals($expectedData, $actualData);
42
    }
43
44
}
45