@@ -42,7 +42,7 @@ class YamlRunnerTest extends \PHPUnit_Framework_TestCase
42
42
43
43
/** @var array A list of supported features */
44
44
private static $ supportedFeatures = [
45
- 'stash_in_path ' ,
45
+ 'stash_in_path ' , ' warnings '
46
46
];
47
47
48
48
/** @var array A mapping for endpoint when there is a reserved keywords for the method / namespace name */
@@ -236,13 +236,20 @@ public function processOperation($operation, $lastOperationResult, &$context, $t
236
236
public function operationDo ($ operation , $ lastOperationResult , &$ context , $ testName , $ async = false )
237
237
{
238
238
$ expectedError = null ;
239
+ $ expectedWarnings = null ;
239
240
240
- // Check if a error must be catched
241
+ // Check if a error must be caught
241
242
if ('catch ' === key ($ operation )) {
242
243
$ expectedError = current ($ operation );
243
244
next ($ operation );
244
245
}
245
246
247
+ // Check if a warning must be caught
248
+ if ('warnings ' === key ($ operation )) {
249
+ $ expectedWarnings = current ($ operation );
250
+ next ($ operation );
251
+ }
252
+
246
253
$ endpointInfo = explode ('. ' , key ($ operation ));
247
254
$ endpointParams = $ this ->replaceWithContext (current ($ operation ), $ context );
248
255
$ caller = $ this ->client ;
@@ -285,10 +292,10 @@ public function operationDo($operation, $lastOperationResult, &$context, $testNa
285
292
286
293
// Exist* methods have to be manually 'unwrapped' into true/false for async
287
294
if (strpos ($ method , "exist " ) !== false && $ async === true ) {
288
- return $ this ->executeAsyncExistRequest ($ caller , $ method , $ endpointParams , $ expectedError , $ testName );
295
+ return $ this ->executeAsyncExistRequest ($ caller , $ method , $ endpointParams , $ expectedError , $ expectedWarnings , $ testName );
289
296
}
290
297
291
- return $ this ->executeRequest ($ caller , $ method , $ endpointParams , $ expectedError , $ testName );
298
+ return $ this ->executeRequest ($ caller , $ method , $ endpointParams , $ expectedError , $ expectedWarnings , $ testName );
292
299
}
293
300
294
301
/**
@@ -304,7 +311,7 @@ public function operationDo($operation, $lastOperationResult, &$context, $testNa
304
311
*
305
312
* @return array|mixed
306
313
*/
307
- public function executeRequest ($ caller , $ method , $ endpointParams , $ expectedError , $ testName )
314
+ public function executeRequest ($ caller , $ method , $ endpointParams , $ expectedError , $ expectedWarnings , $ testName )
308
315
{
309
316
try {
310
317
$ response = $ caller ->$ method ($ endpointParams );
@@ -313,6 +320,8 @@ public function executeRequest($caller, $method, $endpointParams, $expectedError
313
320
$ response = $ response ->wait ();
314
321
}
315
322
323
+ $ this ->checkForWarnings ($ expectedWarnings );
324
+
316
325
return $ response ;
317
326
} catch (\Exception $ exception ) {
318
327
if (null !== $ expectedError ) {
@@ -340,7 +349,7 @@ public function executeRequest($caller, $method, $endpointParams, $expectedError
340
349
*
341
350
* @return bool
342
351
*/
343
- public function executeAsyncExistRequest ($ caller , $ method , $ endpointParams , $ expectedError , $ testName )
352
+ public function executeAsyncExistRequest ($ caller , $ method , $ endpointParams , $ expectedError , $ expectedWarnings , $ testName )
344
353
{
345
354
try {
346
355
@@ -350,6 +359,8 @@ public function executeAsyncExistRequest($caller, $method, $endpointParams, $exp
350
359
$ response = $ response ->wait ();
351
360
}
352
361
362
+ $ this ->checkForWarnings ($ expectedWarnings );
363
+
353
364
if ($ response ['status ' ] === 200 ) {
354
365
return true ;
355
366
} else {
@@ -368,6 +379,38 @@ public function executeAsyncExistRequest($caller, $method, $endpointParams, $exp
368
379
}
369
380
}
370
381
382
+ public function checkForWarnings ($ expectedWarnings ) {
383
+ $ last = $ this ->client ->transport ->getLastConnection ()->getLastRequestInfo ();
384
+
385
+
386
+ // We have some warnings to check
387
+ if ($ expectedWarnings !== null ) {
388
+ if (isset ($ last ['response ' ]['headers ' ]['Warning ' ]) === true ) {
389
+ foreach ($ last ['response ' ]['headers ' ]['Warning ' ] as $ warning ) {
390
+ $ position = array_search ($ warning , $ expectedWarnings );
391
+ if ($ position !== false ) {
392
+ // found the warning
393
+ unset($ expectedWarnings [$ position ]);
394
+ } else {
395
+ // didn't find, throw error
396
+ throw new \Exception ("Expected to find warning [ $ warning] but did not. " );
397
+ }
398
+ }
399
+ if (count ($ expectedWarnings ) > 0 ) {
400
+ throw new \Exception ("Expected to find more warnings: " . print_r ($ expectedWarnings , true ));
401
+ }
402
+ }
403
+ } else {
404
+ // no expected warnings, make sure we have none returned
405
+ if (isset ($ last ['response ' ]['headers ' ]['Warning ' ]) === true ) {
406
+ throw new \Exception ("Did not expect to find warnings, found some instead: "
407
+ . print_r ($ last ['response ' ]['headers ' ]['Warning ' ], true ));
408
+ }
409
+ }
410
+
411
+
412
+ }
413
+
371
414
/**
372
415
* Check if a field in the last operation is false
373
416
*
0 commit comments