Test Setup Failed
Push — static-analysis ( af1336...1f5c7e )
by SignpostMarv
06:23
created

TypeInheritanceTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 182
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 182
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testBase() 0 59 1
A testAnonymUnion() 0 47 1
B testAnonyeExtension() 0 30 1
B testInheritanceWithExtension() 0 34 1
1
<?php
2
namespace GoetasWebservices\XML\XSDReader\Tests;
3
4
class TypeInheritanceTest extends BaseTest
5
{
6
7
    public function testInheritanceWithExtension()
8
    {
9
        $schema = $this->reader->readString('
10
             <xs:schema targetNamespace="http://www.example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema"  xmlns:ex="http://www.example.com">
11
                <xs:complexType name="complexType-1">
12
                     <xs:attribute name="attribute-2" type="xs:string"/>
13
                     <xs:sequence>
14
                            <xs:element name="complexType-1-el-1" type="xs:string"/>
15
                     </xs:sequence>
16
                </xs:complexType>
17
                <xs:complexType name="complexType-2">
18
                     <xs:complexContent>
19
                        <xs:extension base="ex:complexType-1">
20
                             <xs:sequence>
21
                                <xs:element name="complexType-2-el1" type="xs:string"></xs:element>
22
                            </xs:sequence>
23
                            <xs:attribute name="complexType-2-att1" type="xs:string"></xs:attribute>
24
                        </xs:extension>
25
                    </xs:complexContent>
26
                </xs:complexType>
27
            </xs:schema>
28
            ');
29
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType', $type1 = $schema->findType('complexType-1', 'http://www.example.com'));
30
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType', $type2 = $schema->findType('complexType-2', 'http://www.example.com'));
31
32
        $this->assertSame($type1, $type2->getExtension()->getBase());
33
34
        $elements = $type2->getElements();
0 ignored issues
show
Bug introduced by
The method getElements() does not exist on GoetasWebservices\XML\XSDReader\Schema\Type\Type. It seems like you code against a sub-type of GoetasWebservices\XML\XSDReader\Schema\Type\Type such as GoetasWebservices\XML\XS...Schema\Type\ComplexType. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
        $elements = $type2->/** @scrutinizer ignore-call */ getElements();
Loading history...
35
        $attributes = $type2->getAttributes();
0 ignored issues
show
Bug introduced by
The method getAttributes() does not exist on GoetasWebservices\XML\XSDReader\Schema\Type\Type. It seems like you code against a sub-type of GoetasWebservices\XML\XSDReader\Schema\Type\Type such as GoetasWebservices\XML\XS...ma\Type\BaseComplexType. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

35
        $attributes = $type2->/** @scrutinizer ignore-call */ getAttributes();
Loading history...
36
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Element\Element', $elements[0]);
37
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Attribute\Attribute', $attributes[0]);
38
39
        $this->assertEquals('complexType-2-el1', $elements[0]->getName());
40
        $this->assertEquals('complexType-2-att1', $attributes[0]->getName());
41
42
43
    }
44
45
    public function testBase()
46
    {
47
        $schema = $this->reader->readString('
48
            <xs:schema targetNamespace="http://www.example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
49
50
                <xs:simpleType name="mySimple">
51
                    <xs:restriction base="xs:string"></xs:restriction>
52
                </xs:simpleType>
53
54
                <xs:simpleType name="mySimpleWithRestr">
55
                    <xs:restriction base="mySimple"></xs:restriction>
56
                </xs:simpleType>
57
58
                <xs:complexType name="myComplex">
59
                    <xs:simpleContent>
60
                        <xs:extension base="mySimpleWithRestr"></xs:extension>
61
                    </xs:simpleContent>
62
                </xs:complexType>
63
64
                <xs:simpleType name="mySimpleWithUnion">
65
                    <xs:union memberTypes="xs:string mySimpleWithRestr"></xs:union>
66
                </xs:simpleType>
67
68
            </xs:schema>');
69
70
        $this->assertCount(4, $schema->getTypes());
71
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType', $type = $schema->findType('mySimple', 'http://www.example.com'));
72
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType', $type2 = $schema->findType('mySimpleWithRestr', 'http://www.example.com'));
73
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Type\ComplexTypeSimpleContent', $type3 = $schema->findType('myComplex', 'http://www.example.com'));
74
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType', $type4 = $schema->findType('mySimpleWithUnion', 'http://www.example.com'));
75
76
        $restriction1 = $type->getRestriction();
77
        $base1 = $restriction1->getBase();
78
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType', $base1);
79
        $this->assertEquals('http://www.w3.org/2001/XMLSchema', $base1->getSchema()->getTargetNamespace());
80
        $this->assertEquals('string', $base1->getName());
81
82
        $restriction2 = $type2->getRestriction();
83
        $base2 = $restriction2->getBase();
84
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType', $base2);
85
        $this->assertEquals('http://www.example.com', $base2->getSchema()->getTargetNamespace());
86
        $this->assertEquals('mySimple', $base2->getName());
87
88
        $extension = $type3->getExtension();
89
        $base3 = $extension->getBase();
90
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType', $base3);
91
        $this->assertEquals('http://www.example.com', $base3->getSchema()->getTargetNamespace());
92
        $this->assertEquals('mySimpleWithRestr', $base3->getName());
93
94
        $unions = $type4->getUnions();
0 ignored issues
show
Bug introduced by
The method getUnions() does not exist on GoetasWebservices\XML\XSDReader\Schema\Type\Type. It seems like you code against a sub-type of GoetasWebservices\XML\XSDReader\Schema\Type\Type such as GoetasWebservices\XML\XS...\Schema\Type\SimpleType. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

94
        $unions = $type4->/** @scrutinizer ignore-call */ getUnions();
Loading history...
95
        $this->assertCount(2, $unions);
96
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType', $unions[0]);
97
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType', $unions[1]);
98
99
        $this->assertEquals('http://www.w3.org/2001/XMLSchema', $unions[0]->getSchema()->getTargetNamespace());
100
        $this->assertEquals('string', $unions[0]->getName());
101
102
        $this->assertEquals('http://www.example.com', $unions[1]->getSchema()->getTargetNamespace());
103
        $this->assertEquals('mySimpleWithRestr', $unions[1]->getName());
104
    }
105
106
    public function testAnonyeExtension()
107
    {
108
        $schema = $this->reader->readString('
109
            <xs:schema targetNamespace="http://www.example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
110
111
                <xs:simpleType name="myType">
112
                    <xs:restriction>
113
                        <xs:simpleType>
114
                            <xs:restriction base="xs:string"></xs:restriction>
115
                        </xs:simpleType>
116
                    </xs:restriction>
117
                </xs:simpleType>
118
119
            </xs:schema>');
120
121
        $this->assertCount(1, $schema->getTypes());
122
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType', $type = $schema->findType('myType', 'http://www.example.com'));
123
124
        $restriction = $type->getRestriction();
125
        $base = $restriction->getBase();
126
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType', $base);
127
        $this->assertEquals('http://www.example.com', $base->getSchema()->getTargetNamespace());
128
        $this->assertTrue(!$base->getName());
129
130
131
        $restriction2 = $base->getRestriction();
132
        $base2 = $restriction2->getBase();
133
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType', $base2);
134
        $this->assertEquals('http://www.w3.org/2001/XMLSchema', $base2->getSchema()->getTargetNamespace());
135
        $this->assertEquals('string', $base2->getName());
136
137
    }
138
139
    public function testAnonymUnion()
140
    {
141
        $schema = $this->reader->readString('
142
            <xs:schema targetNamespace="http://www.example.com"
143
            xmlns:xs="http://www.w3.org/2001/XMLSchema"
144
            xmlns:ex="http://www.example.com">
145
146
                <xs:simpleType name="myType">
147
                    <xs:restriction base="xs:string"></xs:restriction>
148
                </xs:simpleType>
149
150
                <xs:simpleType name="myAnonUnion">
151
                    <xs:union>
152
                        <xs:simpleType><xs:restriction base="xs:string"></xs:restriction></xs:simpleType>
153
                        <xs:simpleType><xs:restriction base="ex:myType"></xs:restriction></xs:simpleType>
154
                    </xs:union>
155
                </xs:simpleType>
156
157
            </xs:schema>');
158
159
160
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType', $type = $schema->findType('myAnonUnion', 'http://www.example.com'));
161
162
163
        $unions = $type->getUnions();
164
165
        $this->assertCount(2, $unions);
166
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType', $unions[0]);
167
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType', $unions[1]);
168
169
        $this->assertEquals('http://www.example.com', $unions[0]->getSchema()->getTargetNamespace());
170
        $this->assertTrue(!$unions[0]->getName());
171
172
        $this->assertEquals('http://www.example.com', $unions[1]->getSchema()->getTargetNamespace());
173
        $this->assertTrue(!$unions[1]->getName());
174
175
        $restriction1 = $unions[0]->getRestriction();
176
        $base1 = $restriction1->getBase();
177
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType', $base1);
178
        $this->assertEquals('http://www.w3.org/2001/XMLSchema', $base1->getSchema()->getTargetNamespace());
179
        $this->assertEquals('string', $base1->getName());
180
181
        $restriction2 = $unions[1]->getRestriction();
182
        $base2 = $restriction2->getBase();
183
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType', $base2);
184
        $this->assertEquals('http://www.example.com', $base2->getSchema()->getTargetNamespace());
185
        $this->assertEquals('myType', $base2->getName());
186
187
    }
188
}
189