99use React \EventLoop \Loop ;
1010use React \Http \Browser ;
1111
12- class BankResponse
12+ class AddResponse
1313{
14+ public readonly int $ additionResult ;
1415}
1516
1617/**
@@ -28,14 +29,37 @@ class FunctionalTest extends TestCase
2829 */
2930 private $ client ;
3031
32+ // set up server once for all test cases
33+ private static $ serverProcess ;
34+
3135 // download WSDL file only once for all test cases
3236 private static $ wsdl ;
37+
38+ /**
39+ * @beforeClass
40+ */
41+ public static function setUpServerBeforeClass ()
42+ {
43+ $ listenAddress = '127.0.0.1:8000 ' ;
44+ $ serverRoot = __DIR__ ;
45+ $ serverStartCommand = sprintf ('php -S %s -t %s >/dev/null 2>&1 & ' , $ listenAddress , $ serverRoot );
46+ self ::$ serverProcess = \proc_open ($ serverStartCommand , [], $ pipes );
47+
48+ // Briefly wait for the server to settle.
49+ sleep (1 );
50+ }
51+
52+ public static function tearDownAfterClass (): void
53+ {
54+ proc_close (self ::$ serverProcess );
55+ }
56+
3357 /**
3458 * @beforeClass
3559 */
3660 public static function setUpFileBeforeClass ()
3761 {
38- self ::$ wsdl = file_get_contents ('http://www.thomas-bayer.com/axis2/services/BLZService ?wsdl ' );
62+ self ::$ wsdl = file_get_contents ('http://localhost:8000/SimpleSoapServer.php ?wsdl ' );
3963 }
4064
4165 /**
@@ -46,111 +70,91 @@ public function setUpClient()
4670 $ this ->client = new Client (null , self ::$ wsdl );
4771 }
4872
49- public function testBlzService ()
73+ public function testSoapService ()
5074 {
51- $ this ->assertCount (2 , $ this ->client ->getFunctions ());
52- $ this ->assertCount (3 , $ this ->client ->getTypes ());
75+ $ this ->assertCount (1 , $ this ->client ->getFunctions ());
76+ $ this ->assertCount (2 , $ this ->client ->getTypes ());
5377
5478 $ api = new Proxy ($ this ->client );
5579
56- $ promise = $ api ->getBank ( array ( ' blz ' => ' 12070000 ' ) );
80+ $ promise = $ api ->add ([ ' x ' => 21 , ' y ' => 21 ] );
5781
5882 $ result = Block \await ($ promise , Loop::get ());
5983
6084 $ this ->assertIsObject ($ result );
61- $ this ->assertTrue (isset ($ result ->details ));
62- $ this ->assertTrue (isset ($ result ->details ->bic ));
85+ $ this ->assertEquals (42 , $ result ->additionResult );
6386 }
6487
65- public function testBlzServiceWithClassmapReturnsExpectedType ()
88+ public function testSoapServiceWithClassmapReturnsExpectedType ()
6689 {
6790 $ this ->client = new Client (null , self ::$ wsdl , array (
6891 'classmap ' => array (
69- 'getBankResponseType ' => ' Clue\Tests\React\Soap\BankResponse '
92+ 'AddResponse ' => AddResponse::class
7093 )
7194 ));
7295
73- $ this ->assertCount (2 , $ this ->client ->getFunctions ());
74- $ this ->assertCount (3 , $ this ->client ->getTypes ());
96+ $ this ->assertCount (1 , $ this ->client ->getFunctions ());
97+ $ this ->assertCount (2 , $ this ->client ->getTypes ());
7598
7699 $ api = new Proxy ($ this ->client );
77100
78- $ promise = $ api ->getBank ( array ( ' blz ' => ' 12070000 ' ) );
101+ $ promise = $ api ->add ([ ' x ' => 21 , ' y ' => 21 ] );
79102
80103 $ result = Block \await ($ promise , Loop::get ());
81104
82- $ this ->assertInstanceOf ('Clue\Tests\React\Soap\BankResponse ' , $ result );
83- $ this ->assertTrue (isset ($ result ->details ));
84- $ this ->assertTrue (isset ($ result ->details ->bic ));
105+ $ this ->assertInstanceOf (AddResponse::class, $ result );
106+ $ this ->assertEquals (42 , $ result ->additionResult );
85107 }
86108
87- public function testBlzServiceWithSoapV12 ()
109+ public function testSoapServiceWithSoapV12 ()
88110 {
89111 $ this ->client = new Client (null , self ::$ wsdl , array (
90112 'soap_version ' => SOAP_1_2
91113 ));
92114
93- $ this ->assertCount (2 , $ this ->client ->getFunctions ());
94- $ this ->assertCount (3 , $ this ->client ->getTypes ());
115+ $ this ->assertCount (1 , $ this ->client ->getFunctions ());
116+ $ this ->assertCount (2 , $ this ->client ->getTypes ());
95117
96118 $ api = new Proxy ($ this ->client );
97119
98- $ promise = $ api ->getBank ( array ( ' blz ' => ' 12070000 ' ) );
120+ $ promise = $ api ->add ([ ' x ' => 21 , ' y ' => 21 ] );
99121
100122 $ result = Block \await ($ promise , Loop::get ());
101123
102124 $ this ->assertIsObject ($ result );
103- $ this ->assertTrue (isset ($ result ->details ));
104- $ this ->assertTrue (isset ($ result ->details ->bic ));
125+ $ this ->assertEquals (42 , $ result ->additionResult );
105126 }
106127
107- public function testBlzServiceNonWsdlModeReturnedWithoutOuterResultStructure ()
128+ public function testSoapServiceNonWsdlMode ()
108129 {
109130 $ this ->client = new Client (null , null , array (
110- 'location ' => 'http://www.thomas-bayer.com/axis2/services/BLZService ' ,
111- 'uri ' => 'http://thomas-bayer.com/blz/ ' ,
131+ 'location ' => 'http://localhost:8000/SimpleSoapServer.php ' ,
132+ 'uri ' => 'http://localhost:8000/SimpleSoapServer.php '
112133 ));
113134
114135 $ api = new Proxy ($ this ->client );
115-
116- // try encoding the "blz" parameter with the correct namespace (see uri)
117- // $promise = $api->getBank(new SoapParam('12070000', 'ns1:blz'));
118- $ promise = $ api ->getBank (new \SoapVar ('12070000 ' , XSD_STRING , null , null , 'blz ' , 'http://thomas-bayer.com/blz/ ' ));
136+
137+ $ promise = $ api ->add ((object )['x ' => 21 , 'y ' => 21 ]);
119138
120139 $ result = Block \await ($ promise , Loop::get ());
121140
122- $ this ->assertIsObject ($ result );
123- $ this ->assertFalse (isset ($ result ->details ));
124- $ this ->assertTrue (isset ($ result ->bic ));
141+ $ this ->assertEquals (42 , $ result ->additionResult );
125142 }
126-
127- public function testBlzServiceWithRedirectLocationRejectsWithRuntimeException ()
143+ public function testSoapServiceWithRedirectLocationRejectsWithRuntimeException ()
128144 {
129145 $ this ->client = new Client (null , null , array (
130- 'location ' => 'http://httpbingo .org/redirect-to?url= ' . rawurlencode ('http://www.thomas-bayer.com/axis2/services/BLZService ' ),
131- 'uri ' => 'http://thomas-bayer.com/blz / ' ,
146+ 'location ' => 'http://httpbin .org/redirect-to?url= ' . rawurlencode ('http://localhost:8000/SimpleSoapServer.php/ ' ),
147+ 'uri ' => 'http://localhost:8000/SimpleSoapServer.php / ' ,
132148 ));
133149
134150 $ api = new Proxy ($ this ->client );
135- $ promise = $ api ->getBank ( ' a ' );
151+ $ promise = $ api ->add ([ ' x ' => 21 , ' y ' => 21 ] );
136152
137153 $ this ->expectException (\RuntimeException::class);
138154 $ this ->expectExceptionMessage ('redirects ' );
139- Block \await ($ promise , Loop::get ());
140- }
141-
142- public function testBlzServiceWithInvalidBlzRejectsWithSoapFault ()
143- {
144- $ api = new Proxy ($ this ->client );
145-
146- $ promise = $ api ->getBank (array ('blz ' => 'invalid ' ));
147-
148- $ this ->expectException (\SoapFault::class);
149- $ this ->expectExceptionMessage ('Keine Bank zur BLZ invalid gefunden! ' );
150- Block \await ($ promise , Loop::get ());
155+ Async \await ($ promise );
151156 }
152-
153- public function testBlzServiceWithInvalidMethodRejectsWithSoapFault ()
157+ public function testSoapServiceWithInvalidMethodRejectsWithSoapFault ()
154158 {
155159 $ api = new Proxy ($ this ->client );
156160
@@ -165,7 +169,7 @@ public function testCancelMethodRejectsWithRuntimeException()
165169 {
166170 $ api = new Proxy ($ this ->client );
167171
168- $ promise = $ api ->getBank ( array ( ' blz ' => ' 12070000 ' ) );
172+ $ promise = $ api ->add ([ ' x ' => 21 , ' y ' => 21 ] );
169173 $ promise ->cancel ();
170174
171175 $ this ->expectException (\RuntimeException::class);
@@ -181,7 +185,7 @@ public function testTimeoutRejectsWithRuntimeException()
181185 $ this ->client = new Client ($ browser , self ::$ wsdl );
182186 $ api = new Proxy ($ this ->client );
183187
184- $ promise = $ api ->getBank ( array ( ' blz ' => ' 12070000 ' ) );
188+ $ promise = $ api ->add ([ ' x ' => 21 , ' y ' => 21 ] );
185189
186190 $ this ->expectException (\RuntimeException::class);
187191 $ this ->expectExceptionMessage ('timed out ' );
@@ -190,13 +194,13 @@ public function testTimeoutRejectsWithRuntimeException()
190194
191195 public function testGetLocationForFunctionName ()
192196 {
193- $ this ->assertEquals ('http://www.thomas-bayer.com/axis2/services/BLZService ' , $ this ->client ->getLocation ('getBank ' ));
194- $ this ->assertEquals ('http://www.thomas-bayer.com/axis2/services/BLZService ' , $ this ->client ->getLocation ('getBank ' ));
197+ $ this ->assertEquals ('http://localhost:8000/SimpleSoapServer.php ' , $ this ->client ->getLocation ('add ' ));
198+ $ this ->assertEquals ('http://localhost:8000/SimpleSoapServer.php ' , $ this ->client ->getLocation ('add ' ));
195199 }
196200
197201 public function testGetLocationForFunctionNumber ()
198202 {
199- $ this ->assertEquals ('http://www.thomas-bayer.com/axis2/services/BLZService ' , $ this ->client ->getLocation (0 ));
203+ $ this ->assertEquals ('http://localhost:8000/SimpleSoapServer.php ' , $ this ->client ->getLocation (0 ));
200204 }
201205
202206 public function testGetLocationOfUnknownFunctionNameFails ()
@@ -208,7 +212,7 @@ public function testGetLocationOfUnknownFunctionNameFails()
208212 public function testGetLocationForUnknownFunctionNumberFails ()
209213 {
210214 $ this ->expectException (\SoapFault::class);
211- $ this ->assertEquals ('http://www.thomas-bayer.com/axis2/services/BLZService ' , $ this ->client ->getLocation (100 ));
215+ $ this ->assertEquals ('http://localhost:8000/SimpleSoapServer.php ' , $ this ->client ->getLocation (100 ));
212216 }
213217
214218 public function testGetLocationWithExplicitLocationOptionReturnsAsIs ()
@@ -233,7 +237,7 @@ public function testWithLocationInvalidRejectsWithRuntimeException()
233237 {
234238 $ api = new Proxy ($ this ->client ->withLocation ('http://nonsense.invalid ' ));
235239
236- $ promise = $ api ->getBank ( array ( ' blz ' => ' 12070000 ' ) );
240+ $ promise = $ api ->add ([ ' x ' => 21 , ' y ' => 21 ] );
237241
238242 $ this ->expectException (\RuntimeException::class);
239243 Block \await ($ promise , Loop::get ());
@@ -246,9 +250,10 @@ public function testWithLocationRestoredToOriginalResolves()
246250 $ client = $ client ->withLocation ($ original );
247251 $ api = new Proxy ($ client );
248252
249- $ promise = $ api ->getBank ( array ( ' blz ' => ' 12070000 ' ) );
253+ $ promise = $ api ->add ([ ' x ' => 21 , ' y ' => 21 ] );
250254
251255 $ result = Block \await ($ promise , Loop::get ());
252256 $ this ->assertIsObject ($ result );
257+ $ this ->assertEquals (42 , $ result ->additionResult );
253258 }
254259}
0 commit comments