Version3Test   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 152
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 152
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 2

11 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testItConvertsPhpdoc3XmlToAnArray() 0 8 1
A testItUsesTheDefaultTemplateIfNoneIsFoundInThePhpdoc3Xml() 0 8 1
A testItOnlyAcceptsAValidPhpdoc3XmlStructure() 0 14 1
A testItSetsDefaultValuesIfNoneAreFoundInThePhpdoc3Xml() 0 8 1
A testItAcceptsMultipleVersionsInThePhpdoc3Xml() 0 8 1
A testItAcceptsMultipleApisInThePhpdoc3Xml() 0 8 1
A testItAcceptsMultipleGuidesInThePhpdoc3Xml() 0 8 1
A testItAcceptsMultipleTemplatesInThePhpdoc3Xml() 0 8 1
A testItMatchesWhenVersionIs3() 0 8 1
A givenXmlFromFile() 0 4 1
1
<?php
2
/**
3
 * This file is part of phpDocumentor.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @copyright 2010-2015 Mike van Riel<[email protected]>
9
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
10
 * @link      http://phpdoc.org
11
 */
12
13
namespace phpDocumentor\Configuration\Factory;
14
15
use PHPUnit\Framework\TestCase;
16
17
/**
18
 * Test case for Version3
19
 *
20
 * @coversDefaultClass \phpDocumentor\Configuration\Factory\Version3
21
 */
22
final class Version3Test extends TestCase
23
{
24
    /** @var string */
25
    private $dataFolder = '';
26
27
    /** @var Version3 */
28
    private $strategy;
29
30
    protected function setUp()
31
    {
32
        $this->strategy = new Version3(__DIR__ . '/../../../../../data/xsd/phpdoc.xsd');
33
        $this->dataFolder = __DIR__ . '/../../../data/';
34
    }
35
36
    /**
37
     * @covers ::__construct
38
     * @covers ::convert
39
     * @covers ::<private>
40
     */
41
    public function testItConvertsPhpdoc3XmlToAnArray()
42
    {
43
        $xml = $this->givenXmlFromFile('phpDocumentor3XML.xml');
44
45
        $array = $this->strategy->convert($xml);
46
47
        $this->assertEquals(Version3ExpectedArrays::getDefaultArray(), $array);
48
    }
49
50
    /**
51
     * @covers ::__construct
52
     * @covers ::convert
53
     * @covers ::<private>
54
     */
55
    public function testItUsesTheDefaultTemplateIfNoneIsFoundInThePhpdoc3Xml()
56
    {
57
        $xml = $this->givenXmlFromFile('phpDocumentor3XMLWithoutTemplate.xml');
58
59
        $array = $this->strategy->convert($xml);
60
61
        $this->assertEquals(Version3ExpectedArrays::getDefaultArray(), $array);
62
    }
63
64
    /**
65
     * @covers ::__construct
66
     * @covers ::convert
67
     * @covers ::<private>
68
     * @expectedException \Exception
69
     * @expectedExceptionMessage Element '{http://www.phpdoc.org}phpdocumentor': Missing child element(s). Expected is
70
     *                           ( {http://www.phpdoc.org}paths ).
71
     */
72
    public function testItOnlyAcceptsAValidPhpdoc3XmlStructure()
73
    {
74
        $xml = <<<XML
75
<phpdocumentor
76
    version="3"
77
    xmlns="http://www.phpdoc.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
78
    xsi:schemaLocation="http://www.phpdoc.org phpdoc.xsd">
79
</phpdocumentor>
80
XML;
81
82
        $xml = new \SimpleXMLElement($xml);
83
84
        $this->strategy->convert($xml);
85
    }
86
87
    /**
88
     * @covers ::__construct
89
     * @covers ::convert
90
     * @covers ::<private>
91
     */
92
    public function testItSetsDefaultValuesIfNoneAreFoundInThePhpdoc3Xml()
93
    {
94
        $xml = $this->givenXmlFromFile('phpDocumentor3XMLWithoutValues.xml');
95
96
        $array = $this->strategy->convert($xml);
97
98
        $this->assertEquals(Version3ExpectedArrays::getArrayWithEmptyExtensionsAndMarkers(), $array);
99
    }
100
101
    /**
102
     * @covers ::__construct
103
     * @covers ::convert
104
     * @covers ::<private>
105
     */
106
    public function testItAcceptsMultipleVersionsInThePhpdoc3Xml()
107
    {
108
        $xml = $this->givenXmlFromFile('phpDocumentor3XMLWithMultipleVersions.xml');
109
110
        $array = $this->strategy->convert($xml);
111
112
        $this->assertEquals(Version3ExpectedArrays::getArrayWithMultipleVersions(), $array);
113
    }
114
115
    /**
116
     * @covers ::__construct
117
     * @covers ::convert
118
     * @covers ::<private>
119
     */
120
    public function testItAcceptsMultipleApisInThePhpdoc3Xml()
121
    {
122
        $xml = $this->givenXmlFromFile('phpDocumentor3XMLWithMultipleApis.xml');
123
124
        $array = $this->strategy->convert($xml);
125
126
        $this->assertEquals(Version3ExpectedArrays::getArrayWithMultipleApis(), $array);
127
    }
128
129
    /**
130
     * @covers ::__construct
131
     * @covers ::convert
132
     * @covers ::<private>
133
     */
134
    public function testItAcceptsMultipleGuidesInThePhpdoc3Xml()
135
    {
136
        $xml = $xml = $this->givenXmlFromFile('phpDocumentor3XMLWithMultipleGuides.xml');
137
138
        $array = $this->strategy->convert($xml);
139
140
        $this->assertEquals(Version3ExpectedArrays::getArrayWithMultipleGuides(), $array);
141
    }
142
143
    /**
144
     * @covers ::__construct
145
     * @covers ::convert
146
     * @covers ::<private>
147
     */
148
    public function testItAcceptsMultipleTemplatesInThePhpdoc3Xml()
149
    {
150
        $xml = $this->givenXmlFromFile('phpDocumentor3XMLWithMultipleTemplates.xml');
151
152
        $array = $this->strategy->convert($xml);
153
154
        $this->assertEquals(Version3ExpectedArrays::getArrayWithMultipleTemplates(), $array);
155
    }
156
157
    /**
158
     * @covers ::supports
159
     */
160
    public function testItMatchesWhenVersionIs3()
161
    {
162
        $xml = $this->givenXmlFromFile('phpDocumentor3XML.xml');
163
164
        $bool = $this->strategy->supports($xml);
165
166
        $this->assertTrue($bool);
167
    }
168
169
    private function givenXmlFromFile(string $file): \SimpleXMLElement
170
    {
171
        return new \SimpleXMLElement($this->dataFolder . $file, 0, true);
172
    }
173
}
174