16
16
use BeSimple \SoapBundle \ServiceDefinition as Definition ;
17
17
use BeSimple \SoapBundle \Tests \fixtures \ServiceBinding as Fixtures ;
18
18
use BeSimple \SoapBundle \Util \Collection ;
19
+ use BeSimple \SoapCommon \Definition \Type \ComplexType ;
20
+ use BeSimple \SoapCommon \Definition \Type \TypeRepository ;
19
21
20
22
class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase
21
23
{
22
24
/**
23
25
* @dataProvider messageProvider
24
26
*/
25
- public function testProcessMessage (Definition \Method $ method , $ message , $ assert )
27
+ public function testProcessMessage (Definition \Method $ method , array $ message , array $ assert )
26
28
{
27
29
$ messageBinder = new RpcLiteralRequestMessageBinder ();
28
- $ result = $ messageBinder ->processMessage ($ method , $ message );
30
+ $ result = $ messageBinder ->processMessage ($ method , $ message, $ this -> getTypeRepository () );
29
31
30
32
$ this ->assertSame ($ assert , $ result );
31
33
}
32
34
33
35
public function testProcessMessageWithComplexType ()
34
36
{
37
+ $ typeRepository = $ this ->addComplexTypes ($ this ->getTypeRepository ());
35
38
$ messageBinder = new RpcLiteralRequestMessageBinder ();
36
39
40
+ $ method = new Definition \Method ('complextype_argument ' , null );
41
+ $ method ->addInput ('foo ' , 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo ' );
42
+
37
43
$ foo = new Fixtures \Foo ('foobar ' , 19395 );
38
44
$ result = $ messageBinder ->processMessage (
39
- new Definition \Method ('complextype_argument ' , null , array (), array (
40
- new Definition \Argument ('foo ' , new Definition \Type ('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo ' )),
41
- )),
45
+ $ method ,
42
46
array ($ foo ),
43
- $ this -> getDefinitionComplexTypes ()
47
+ $ typeRepository
44
48
);
45
49
46
50
$ this ->assertEquals (array ('foo ' => $ foo ), $ result );
47
51
48
-
49
52
$ foo1 = new Fixtures \Foo ('foobar ' , 29291 );
50
53
$ foo2 = new Fixtures \Foo ('barfoo ' , 39392 );
51
54
$ foos = new \stdClass ();
52
55
$ foos ->item = array ($ foo1 , $ foo2 );
53
56
57
+ $ method = new Definition \Method ('complextype_argument ' , null );
58
+ $ method ->addInput ('foos ' , 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo[] ' );
59
+
54
60
$ result = $ messageBinder ->processMessage (
55
- new Definition \Method ('complextype_argument ' , null , array (), array (
56
- new Definition \Argument ('foos ' , new Definition \Type ('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo[] ' )),
57
- )),
61
+ $ method ,
58
62
array ($ foos ),
59
- $ this -> getDefinitionComplexTypes ()
63
+ $ typeRepository
60
64
);
61
65
62
66
$ this ->assertEquals (array ('foos ' => array ($ foo1 , $ foo2 )), $ result );
63
67
}
64
68
65
- /**
66
- * @expectedException SoapFault
67
- */
68
69
public function testProcessMessageSoapFault ()
69
70
{
70
71
$ messageBinder = new RpcLiteralRequestMessageBinder ();
71
72
73
+ $ method = new Definition \Method ('complextype_argument ' , null );
74
+ $ method ->addInput ('foo ' , 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo ' );
75
+
72
76
$ foo = new Fixtures \Foo ('foo ' , null );
73
- $ result = $ messageBinder -> processMessage (
74
- new Definition \ Method ( ' complextype_argument ' , null , array (), array (
75
- new Definition \ Argument ( ' foo ' , new Definition \ Type ( ' BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo ' )),
76
- )) ,
77
+
78
+ $ this -> setExpectedException ( ' SoapFault ' );
79
+ $ messageBinder -> processMessage (
80
+ $ method ,
77
81
array ($ foo ),
78
- $ this ->getDefinitionComplexTypes ( )
82
+ $ this ->addComplexTypes ( $ this -> getTypeRepository () )
79
83
);
80
84
}
81
85
82
86
public function testProcessMessageWithComplexTypeReference ()
83
87
{
84
88
$ messageBinder = new RpcLiteralRequestMessageBinder ();
85
89
90
+ $ method = new Definition \Method ('complextype_argument ' , null );
91
+ $ method ->addInput ('foos ' , 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo[] ' );
92
+
86
93
$ foo = new Fixtures \Foo ('foo ' , 2499104 );
87
94
$ foos = new \stdClass ();
88
95
$ foos ->item = array ($ foo , $ foo );
89
96
90
97
$ result = $ messageBinder ->processMessage (
91
- new Definition \Method ('complextype_argument ' , null , array (), array (
92
- new Definition \Argument ('foos ' , new Definition \Type ('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo[] ' )),
93
- )),
98
+ $ method ,
94
99
array ($ foos ),
95
- $ this ->getDefinitionComplexTypes ( )
100
+ $ this ->addComplexTypes ( $ this -> getTypeRepository () )
96
101
);
97
102
98
103
$ this ->assertEquals (array ('foos ' => array ($ foo , $ foo )), $ result );
@@ -102,16 +107,17 @@ public function testProcessMessageWithComplexTypeIntoComplexType()
102
107
{
103
108
$ messageBinder = new RpcLiteralRequestMessageBinder ();
104
109
110
+ $ method = new Definition \Method ('complextype_argument ' , null );
111
+ $ method ->addInput ('fooBar ' , 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooBar ' );
112
+
105
113
$ foo = new Fixtures \Foo ('foo ' , 38845 );
106
114
$ bar = new Fixtures \Bar ('bar ' , null );
107
115
$ fooBar = new Fixtures \FooBar ($ foo , $ bar );
108
116
109
117
$ result = $ messageBinder ->processMessage (
110
- new Definition \Method ('complextype_argument ' , null , array (), array (
111
- new Definition \Argument ('fooBar ' , new Definition \Type ('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooBar ' )),
112
- )),
118
+ $ method ,
113
119
array ($ fooBar ),
114
- $ this ->getDefinitionComplexTypes ( )
120
+ $ this ->addComplexTypes ( $ this -> getTypeRepository () )
115
121
);
116
122
117
123
$ this ->assertEquals (array ('fooBar ' => $ fooBar ), $ result );
@@ -121,17 +127,18 @@ public function testProcessMessageComplexTypeWithArrays()
121
127
{
122
128
$ messageBinder = new RpcLiteralRequestMessageBinder ();
123
129
130
+ $ method = new Definition \Method ('complextype_with_array ' , null );
131
+ $ method ->addInput ('simple_arrays ' , 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\SimpleArrays ' );
132
+
124
133
$ array = array (1 , 2 , 3 , 4 );
125
134
$ stdClass = new \stdClass ();
126
135
$ stdClass ->item = $ array ;
127
136
$ simpleArrays = new Fixtures \SimpleArrays (null , new \stdClass (), $ stdClass );
128
137
129
138
$ result = $ messageBinder ->processMessage (
130
- new Definition \Method ('complextype_with_array ' , null , array (), array (
131
- new Definition \Argument ('simple_arrays ' , new Definition \Type ('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\SimpleArrays ' )),
132
- )),
139
+ $ method ,
133
140
array ($ simpleArrays ),
134
- $ this ->getDefinitionComplexTypes ( )
141
+ $ this ->addComplexTypes ( $ this -> getTypeRepository () )
135
142
);
136
143
137
144
$ result = $ result ['simple_arrays ' ];
@@ -144,12 +151,13 @@ public function testProcessMessageWithEmptyArrayComplexType()
144
151
{
145
152
$ messageBinder = new RpcLiteralRequestMessageBinder ();
146
153
154
+ $ method = new Definition \Method ('empty_array_complex_type ' , null );
155
+ $ method ->addInput ('foo ' , 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo[] ' );
156
+
147
157
$ result = $ messageBinder ->processMessage (
148
- new Definition \Method ('empty_array_complex_type ' , null , array (), array (
149
- new Definition \Argument ('foo ' , new Definition \Type ('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo[] ' )),
150
- )),
158
+ $ method ,
151
159
array (new \stdClass ()),
152
- $ this ->getDefinitionComplexTypes ( )
160
+ $ this ->addComplexTypes ( $ this -> getTypeRepository () )
153
161
);
154
162
155
163
$ this ->assertEquals (array ('foo ' => array ()), $ result );
@@ -159,16 +167,17 @@ public function testProccessMessagePreventInfiniteRecursion()
159
167
{
160
168
$ messageBinder = new RpcLiteralRequestMessageBinder ();
161
169
170
+ $ method = new Definition \Method ('prevent_infinite_recursion ' , null );
171
+ $ method ->addInput ('foo_recursive ' , 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooRecursive ' );
172
+
162
173
$ foo = new Fixtures \FooRecursive ('foo ' , '' );
163
174
$ bar = new Fixtures \BarRecursive ($ foo , 10394 );
164
175
$ foo ->bar = $ bar ;
165
176
166
177
$ result = $ messageBinder ->processMessage (
167
- new Definition \Method ('prevent_infinite_recursion ' , null , array (), array (
168
- new Definition \Argument ('foo_recursive ' , new Definition \Type ('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooRecursive ' )),
169
- )),
178
+ $ method ,
170
179
array ($ foo ),
171
- $ this ->getDefinitionComplexTypes ( )
180
+ $ this ->addComplexTypes ( $ this -> getTypeRepository () )
172
181
);
173
182
174
183
$ this ->assertEquals (array ('foo_recursive ' => $ foo ), $ result );
@@ -179,84 +188,82 @@ public function messageProvider()
179
188
$ messages = array ();
180
189
181
190
$ messages [] = array (
182
- new Definition \Method ('no_argument ' ),
191
+ new Definition \Method ('no_argument ' , null ),
183
192
array (),
184
193
array (),
185
194
);
186
195
196
+ $ method = new Definition \Method ('string_argument ' , null );
197
+ $ method ->addInput ('foo ' , 'string ' );
187
198
$ messages [] = array (
188
- new Definition \Method ('string_argument ' , null , array (), array (
189
- new Definition \Argument ('foo ' , new Definition \Type ('string ' )),
190
- )),
199
+ $ method ,
191
200
array ('bar ' ),
192
201
array ('foo ' => 'bar ' ),
193
202
);
194
203
204
+ $ method = new Definition \Method ('string_int_arguments ' , null );
205
+ $ method ->addInput ('foo ' , 'string ' );
206
+ $ method ->addInput ('bar ' , 'int ' );
195
207
$ messages [] = array (
196
- new Definition \Method ('string_int_arguments ' , null , array (), array (
197
- new Definition \Argument ('foo ' , new Definition \Type ('string ' )),
198
- new Definition \Argument ('bar ' , new Definition \Type ('int ' )),
199
- )),
208
+ $ method ,
200
209
array ('test ' , 20 ),
201
210
array ('foo ' => 'test ' , 'bar ' => 20 ),
202
211
);
203
212
213
+ $ method = new Definition \Method ('array_string_arguments ' , null );
214
+ $ method ->addInput ('foo ' , 'string[] ' );
215
+ $ method ->addInput ('bar ' , 'int ' );
204
216
$ strings = new \stdClass ();
205
217
$ strings ->item = array ('foo ' , 'bar ' , 'barfoo ' );
206
218
$ messages [] = array (
207
- new Definition \Method ('array_string_arguments ' , null , array (), array (
208
- new Definition \Argument ('foo ' , new Definition \Type ('string[] ' )),
209
- new Definition \Argument ('bar ' , new Definition \Type ('int ' )),
210
- )),
219
+ $ method ,
211
220
array ($ strings , 4 ),
212
221
array ('foo ' => array ('foo ' , 'bar ' , 'barfoo ' ), 'bar ' => 4 ),
213
222
);
214
223
224
+ $ method = new Definition \Method ('empty_array ' , null );
225
+ $ method ->addInput ('foo ' , 'string[] ' );
215
226
$ messages [] = array (
216
- new Definition \Method ('empty_array ' , null , array (), array (
217
- new Definition \Argument ('foo ' , new Definition \Type ('string[] ' )),
218
- )),
227
+ $ method ,
219
228
array (new \stdClass ()),
220
229
array ('foo ' => array ()),
221
230
);
222
231
223
232
return $ messages ;
224
233
}
225
234
226
- private function getDefinitionComplexTypes ( )
235
+ private function addComplexTypes ( TypeRepository $ typeRepository )
227
236
{
228
- $ definitionComplexTypes = array ();
229
-
230
- $ definitionComplexTypes ['BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo ' ] = $ this ->createComplexTypeCollection (array (
231
- array ('foo ' , 'string ' ),
232
- array ('bar ' , 'int ' ),
233
- ));
234
-
235
- $ definitionComplexTypes ['BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Bar ' ] = $ this ->createComplexTypeCollection (array (
236
- array ('foo ' , 'string ' ),
237
- array ('bar ' , 'int ' , true ),
238
- ));
239
-
240
- $ definitionComplexTypes ['BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooBar ' ] = $ this ->createComplexTypeCollection (array (
241
- array ('foo ' , 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo ' ),
242
- array ('bar ' , 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Bar ' ),
243
- ));
244
-
245
- $ definitionComplexTypes ['BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\SimpleArrays ' ] = $ this ->createComplexTypeCollection (array (
246
- array ('array1 ' , 'string[] ' , true ),
247
- array ('array2 ' , 'string[] ' ),
248
- array ('array3 ' , 'string[] ' ),
249
- ));
250
-
251
- $ definitionComplexTypes ['BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooRecursive ' ] = $ this ->createComplexTypeCollection (array (
252
- array ('bar ' , 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\BarRecursive ' ),
253
- ));
254
-
255
- $ definitionComplexTypes ['BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\BarRecursive ' ] = $ this ->createComplexTypeCollection (array (
256
- array ('foo ' , 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooRecursive ' ),
257
- ));
258
-
259
- return $ definitionComplexTypes ;
237
+ $ foo = new ComplexType ('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo ' , 'Foo ' );
238
+ $ foo ->add ('foo ' , 'string ' );
239
+ $ foo ->add ('bar ' , 'int ' );
240
+ $ typeRepository ->addComplexType ($ foo );
241
+
242
+ $ bar = new ComplexType ('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Bar ' , 'Bar ' );
243
+ $ bar ->add ('foo ' , 'string ' );
244
+ $ bar ->add ('bar ' , 'int ' , true );
245
+ $ typeRepository ->addComplexType ($ bar );
246
+
247
+ $ fooBar = new ComplexType ('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooBar ' , 'FooBar ' );
248
+ $ fooBar ->add ('foo ' , 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Foo ' );
249
+ $ fooBar ->add ('bar ' , 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\Bar ' );
250
+ $ typeRepository ->addComplexType ($ fooBar );
251
+
252
+ $ simpleArrays = new ComplexType ('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\SimpleArrays ' , 'SimpleArrays ' );
253
+ $ simpleArrays ->add ('array1 ' , 'string[] ' , true );
254
+ $ simpleArrays ->add ('array2 ' , 'string[] ' );
255
+ $ simpleArrays ->add ('array3 ' , 'string[] ' );
256
+ $ typeRepository ->addComplexType ($ simpleArrays );
257
+
258
+ $ fooRecursive = new ComplexType ('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooRecursive ' , 'FooRecursive ' );
259
+ $ fooRecursive ->add ('bar ' , 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\BarRecursive ' );
260
+ $ typeRepository ->addComplexType ($ fooRecursive );
261
+
262
+ $ barRecursive = new ComplexType ('BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\BarRecursive ' , 'BarRecursive ' );
263
+ $ barRecursive ->add ('foo ' , 'BeSimple\SoapBundle\Tests\fixtures\ServiceBinding\FooRecursive ' );
264
+ $ typeRepository ->addComplexType ($ barRecursive );
265
+
266
+ return $ typeRepository ;
260
267
}
261
268
262
269
private function createComplexTypeCollection (array $ properties )
@@ -277,4 +284,18 @@ private function createComplexTypeCollection(array $properties)
277
284
278
285
return array ('properties ' => $ collection );
279
286
}
287
+
288
+ private function getTypeRepository ()
289
+ {
290
+ $ typeRepository = new TypeRepository ();
291
+ $ typeRepository ->addXmlNamespace ('xsd ' , 'http://www.w3.org/2001/XMLSchema ' );
292
+ $ typeRepository ->addType ('string ' , 'xsd:string ' );
293
+ $ typeRepository ->addType ('boolean ' , 'xsd:boolean ' );
294
+ $ typeRepository ->addType ('int ' , 'xsd:int ' );
295
+ $ typeRepository ->addType ('float ' , 'xsd:float ' );
296
+ $ typeRepository ->addType ('date ' , 'xsd:date ' );
297
+ $ typeRepository ->addType ('dateTime ' , 'xsd:dateTime ' );
298
+
299
+ return $ typeRepository ;
300
+ }
280
301
}
0 commit comments