Minor dependency updates
[yaffs-website] / vendor / guzzlehttp / guzzle / src / Handler / MockHandler.php
index 7bbe7354c97a239416c950fb2d957f7d41d1ff73..d892061c7a0074063d33c20fea167c898dc2beb2 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 namespace GuzzleHttp\Handler;
 
 <?php
 namespace GuzzleHttp\Handler;
 
+use GuzzleHttp\Exception\RequestException;
 use GuzzleHttp\HandlerStack;
 use GuzzleHttp\Promise\PromiseInterface;
 use GuzzleHttp\Promise\RejectedPromise;
 use GuzzleHttp\HandlerStack;
 use GuzzleHttp\Promise\PromiseInterface;
 use GuzzleHttp\Promise\RejectedPromise;
@@ -13,7 +14,7 @@ use Psr\Http\Message\ResponseInterface;
  */
 class MockHandler implements \Countable
 {
  */
 class MockHandler implements \Countable
 {
-    private $queue;
+    private $queue = [];
     private $lastRequest;
     private $lastOptions;
     private $onFulfilled;
     private $lastRequest;
     private $lastOptions;
     private $onFulfilled;
@@ -73,12 +74,24 @@ class MockHandler implements \Countable
         $this->lastOptions = $options;
         $response = array_shift($this->queue);
 
         $this->lastOptions = $options;
         $response = array_shift($this->queue);
 
+        if (isset($options['on_headers'])) {
+            if (!is_callable($options['on_headers'])) {
+                throw new \InvalidArgumentException('on_headers must be callable');
+            }
+            try {
+                $options['on_headers']($response);
+            } catch (\Exception $e) {
+                $msg = 'An error was encountered during the on_headers event';
+                $response = new RequestException($msg, $request, $response, $e);
+            }
+        }
+
         if (is_callable($response)) {
             $response = call_user_func($response, $request, $options);
         }
 
         $response = $response instanceof \Exception
         if (is_callable($response)) {
             $response = call_user_func($response, $request, $options);
         }
 
         $response = $response instanceof \Exception
-            ? new RejectedPromise($response)
+            ? \GuzzleHttp\Promise\rejection_for($response)
             : \GuzzleHttp\Promise\promise_for($response);
 
         return $response->then(
             : \GuzzleHttp\Promise\promise_for($response);
 
         return $response->then(
@@ -107,7 +120,7 @@ class MockHandler implements \Countable
                 if ($this->onRejected) {
                     call_user_func($this->onRejected, $reason);
                 }
                 if ($this->onRejected) {
                     call_user_func($this->onRejected, $reason);
                 }
-                return new RejectedPromise($reason);
+                return \GuzzleHttp\Promise\rejection_for($reason);
             }
         );
     }
             }
         );
     }
@@ -145,7 +158,7 @@ class MockHandler implements \Countable
     /**
      * Get the last received request options.
      *
     /**
      * Get the last received request options.
      *
-     * @return RequestInterface
+     * @return array
      */
     public function getLastOptions()
     {
      */
     public function getLastOptions()
     {