1
+ <?php
2
+ /**
3
+ * @package
4
+ * @author David Pommer (conlabz GmbH) <[email protected] >
5
+ */
6
+
7
+ namespace GoetasWebservices \Xsd \XsdToPhp \Tests \Issues \I182 ;
8
+
9
+ use GoetasWebservices \XML \XSDReader \SchemaReader ;
10
+ use GoetasWebservices \Xsd \XsdToPhp \DependencyInjection \Xsd2PhpExtension ;
11
+ use GoetasWebservices \Xsd \XsdToPhp \Jms \YamlConverter ;
12
+ use PHPUnit \Framework \TestCase ;
13
+ use Psr \Log \NullLogger ;
14
+ use Symfony \Component \Config \FileLocator ;
15
+ use Symfony \Component \Config \Loader \DelegatingLoader ;
16
+ use Symfony \Component \Config \Loader \LoaderResolver ;
17
+ use Symfony \Component \DependencyInjection \ContainerBuilder ;
18
+ use Symfony \Component \DependencyInjection \ContainerInterface ;
19
+ use Symfony \Component \DependencyInjection \Loader \XmlFileLoader ;
20
+ use Symfony \Component \DependencyInjection \Loader \YamlFileLoader ;
21
+
22
+ class I182Test extends TestCase
23
+ {
24
+ protected ContainerInterface $ container ;
25
+ protected SchemaReader $ reader ;
26
+
27
+ protected YamlConverter $ converter ;
28
+
29
+ public function setUp (): void
30
+ {
31
+ parent ::setUp ();
32
+
33
+ $ this ->container = new ContainerBuilder ();
34
+ $ this ->container ->registerExtension (
35
+ new Xsd2PhpExtension ()
36
+ );
37
+ $ this ->container ->set ('logger ' , new NullLogger ());
38
+
39
+ $ this ->reader = new SchemaReader ();
40
+ }
41
+
42
+ public function testXmlRootPrefix ()
43
+ {
44
+ $ this ->loadConfigurations (__DIR__ . '/config.yml ' );
45
+
46
+ $ schema = $ this ->reader ->readFile (__DIR__ . '/data.xsd ' );
47
+
48
+ $ converter = $ this ->container ->get ('goetas_webservices.xsd2php.converter.jms ' );
49
+
50
+ $ actual = $ converter ->convert ([$ schema ]);
51
+
52
+ $ expected = [
53
+ 'Example \\Root \\RootAType ' => [
54
+ 'Example \\Root \\RootAType ' => [
55
+ 'properties ' => [
56
+ 'child ' => [
57
+ 'expose ' => true ,
58
+ 'access_type ' => 'public_method ' ,
59
+ 'serialized_name ' => 'child ' ,
60
+ 'accessor ' => [
61
+ 'getter ' => 'getChild ' ,
62
+ 'setter ' => 'setChild ' ,
63
+ ],
64
+ 'xml_list ' => [
65
+ 'inline ' => true ,
66
+ 'entry_name ' => 'child ' ,
67
+ ],
68
+ 'type ' => 'array<Example \\ChildType> ' ,
69
+ ],
70
+ 'childRoot ' => [
71
+ 'expose ' => true ,
72
+ 'access_type ' => 'public_method ' ,
73
+ 'serialized_name ' => 'childRoot ' ,
74
+ 'xml_element ' => [
75
+ 'namespace ' => 'http://www.example.com ' ,
76
+ ],
77
+ 'accessor ' => [
78
+ 'getter ' => 'getChildRoot ' ,
79
+ 'setter ' => 'setChildRoot ' ,
80
+ ],
81
+ 'type ' => 'Example \\ChildType ' ,
82
+ ],
83
+ ],
84
+ ],
85
+ ],
86
+ 'Example \\Root ' => [
87
+ 'Example \\Root ' => [
88
+ 'xml_root_name ' => 'ns-8ece61d2:root ' ,
89
+ 'xml_root_namespace ' => 'http://www.example.com ' ,
90
+ 'xml_root_prefix ' => 'prefix '
91
+ ],
92
+ ],
93
+ 'Example \\ChildType ' => [
94
+ 'Example \\ChildType ' => [
95
+ 'properties ' => [
96
+ 'id ' => [
97
+ 'expose ' => true ,
98
+ 'access_type ' => 'public_method ' ,
99
+ 'serialized_name ' => 'id ' ,
100
+ 'accessor ' => [
101
+ 'getter ' => 'getId ' ,
102
+ 'setter ' => 'setId ' ,
103
+ ],
104
+ 'type ' => 'string ' ,
105
+ ],
106
+ ],
107
+ ],
108
+ ],
109
+ ];
110
+
111
+ $ this ->assertEquals ($ expected , $ actual );
112
+ }
113
+
114
+ private function loadConfigurations ($ configFile )
115
+ {
116
+ $ locator = new FileLocator ('. ' );
117
+ $ yaml = new YamlFileLoader ($ this ->container , $ locator );
118
+ $ xml = new XmlFileLoader ($ this ->container , $ locator );
119
+
120
+ $ delegatingLoader = new DelegatingLoader (new LoaderResolver ([$ yaml , $ xml ]));
121
+ $ delegatingLoader ->load ($ configFile );
122
+
123
+ $ this ->container ->compile ();
124
+ }
125
+ }
0 commit comments