MainLaLitTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A provideTestData() 0 4 1
A testArrayToXML() 0 7 1
A testXMLToArray() 0 14 1
1
<?php
2
3
namespace LaLit;
4
5
class MainLaLitTest extends \PHPUnit_Framework_TestCase
6
{
7
    public function provideTestData()
8
    {
9
        return include __DIR__.'/files/testData.inc';
10
    }
11
12
    /**
13
     * @dataProvider provideTestData
14
     *
15
     * @param string $php
16
     * @param string $xml
17
     * @param string $structure
18
     */
19
    public function testArrayToXML($php, $xml, $structure)
20
    {
21
        $actualResults = Array2XML::createXML('root', $php['root'])->saveXML();
0 ignored issues
show
Documentation introduced by
$php['root'] is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
22
        $expectedResults = $xml;
23
24
        $this->assertEquals($expectedResults, $actualResults, $structure);
25
    }
26
27
    /**
28
     * @dataProvider provideTestData
29
     *
30
     * @param string $php
31
     * @param string $xmlString
32
     * @param string $structure
33
     */
34
    public function testXMLToArray($php, $xmlString, $structure)
35
    {
36
        $xmlDOM = new \DOMDocument(1.0, 'UTF-8');
37
        $xmlDOM->xmlStandalone = false;
38
        $xmlDOM->preserveWhiteSpace = false;
39
        $xmlDOM->loadXML($xmlString);
40
        $xmlDOM->formatOutput = true;
41
42
        $xmlStringResults = XML2Array::createArray($xmlString);
43
        $xmlDOMResults = XML2Array::createArray($xmlDOM);
44
45
        $this->assertEquals($php, $xmlStringResults, $structure);
46
        $this->assertEquals($php, $xmlDOMResults, $structure);
47
    }
48
}
49