From 0c8af4992cb0f7589dcafaad65ada12753c64594 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 23 Nov 2022 21:14:33 +0300 Subject: initial --- vendor/aws/aws-sdk-php/src/MockHandler.php | 147 +++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 vendor/aws/aws-sdk-php/src/MockHandler.php (limited to 'vendor/aws/aws-sdk-php/src/MockHandler.php') diff --git a/vendor/aws/aws-sdk-php/src/MockHandler.php b/vendor/aws/aws-sdk-php/src/MockHandler.php new file mode 100644 index 0000000..61373ad --- /dev/null +++ b/vendor/aws/aws-sdk-php/src/MockHandler.php @@ -0,0 +1,147 @@ +onFulfilled = $onFulfilled; + $this->onRejected = $onRejected; + + if ($resultOrQueue) { + call_user_func_array([$this, 'append'], array_values($resultOrQueue)); + } + } + + /** + * Adds one or more variadic ResultInterface or AwsException objects to the + * queue. + */ + public function append() + { + foreach (func_get_args() as $value) { + if ($value instanceof ResultInterface + || $value instanceof Exception + || is_callable($value) + ) { + $this->queue[] = $value; + } else { + throw new \InvalidArgumentException('Expected an Aws\ResultInterface or Exception.'); + } + } + } + + /** + * Adds one or more \Exception or \Throwable to the queue + */ + public function appendException() + { + foreach (func_get_args() as $value) { + if ($value instanceof \Exception || $value instanceof \Throwable) { + $this->queue[] = $value; + } else { + throw new \InvalidArgumentException('Expected an \Exception or \Throwable.'); + } + } + } + + public function __invoke( + CommandInterface $command, + RequestInterface $request + ) { + if (!$this->queue) { + $last = $this->lastCommand + ? ' The last command sent was ' . $this->lastCommand->getName() . '.' + : ''; + throw new \RuntimeException('Mock queue is empty. Trying to send a ' + . $command->getName() . ' command failed.' . $last); + } + + $this->lastCommand = $command; + $this->lastRequest = $request; + + $result = array_shift($this->queue); + + if (is_callable($result)) { + $result = $result($command, $request); + } + + if ($result instanceof \Exception) { + $result = new RejectedPromise($result); + } else { + // Add an effective URI and statusCode if not present. + $meta = $result['@metadata']; + if (!isset($meta['effectiveUri'])) { + $meta['effectiveUri'] = (string) $request->getUri(); + } + if (!isset($meta['statusCode'])) { + $meta['statusCode'] = 200; + } + $result['@metadata'] = $meta; + $result = Promise\Create::promiseFor($result); + } + + $result->then($this->onFulfilled, $this->onRejected); + + return $result; + } + + /** + * Get the last received request. + * + * @return RequestInterface + */ + public function getLastRequest() + { + return $this->lastRequest; + } + + /** + * Get the last received command. + * + * @return CommandInterface + */ + public function getLastCommand() + { + return $this->lastCommand; + } + + /** + * Returns the number of remaining items in the queue. + * + * @return int + */ + #[\ReturnTypeWillChange] + public function count() + { + return count($this->queue); + } +} -- cgit v1.2.3