MockApi.php in Auth0 Single Sign On 8.2
File
vendor/auth0/auth0-php/tests/MockApi.php
View source
<?php
namespace Auth0\Tests;
use Auth0\SDK\API\Authentication;
use Auth0\SDK\API\Management;
use Auth0\SDK\Helpers\JWKFetcher;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use GuzzleHttp\Psr7\Request;
abstract class MockApi {
protected $requestHistory = [];
protected $historyIndex = 0;
protected $client;
public function __construct(array $responses = [], array $config = []) {
$guzzleOptions = [];
if (count($responses)) {
$mock = new MockHandler($responses);
$handler = HandlerStack::create($mock);
$handler
->push(Middleware::history($this->requestHistory));
$guzzleOptions['handler'] = $handler;
}
$this
->setClient($guzzleOptions, $config);
}
public abstract function setClient(array $guzzleOptions, array $config = []);
public function call() {
$this->historyIndex++;
return $this->client;
}
public function getHistoryUrl($parse_component = null) {
$request = $this
->getHistory();
$request_url = $request
->getUri()
->__toString();
return is_null($parse_component) ? $request_url : parse_url($request_url, $parse_component);
}
public function getHistoryQuery() {
return $this
->getHistoryUrl(PHP_URL_QUERY);
}
public function getHistoryMethod() {
return $this
->getHistory()
->getMethod();
}
public function getHistoryBody() {
$body = $this
->getHistory()
->getBody();
return json_decode($body, true);
}
public function getHistoryBodyAsString() {
return $this
->getHistory()
->getBody()
->getContents();
}
public function getHistoryHeaders() {
return $this
->getHistory()
->getHeaders();
}
protected function getHistory() {
$requestHistoryIndex = $this->historyIndex - 1;
return $this->requestHistory[$requestHistoryIndex]['request'];
}
}