abstract class MockApi in Auth0 Single Sign On 8.2
Class MockApi
@package Auth0\Tests
Hierarchy
- class \Auth0\Tests\MockApi
Expanded class hierarchy of MockApi
2 files declare their use of MockApi
- MockAuthenticationApi.php in vendor/
auth0/ auth0-php/ tests/ API/ Authentication/ MockAuthenticationApi.php - MockManagementApi.php in vendor/
auth0/ auth0-php/ tests/ API/ Management/ MockManagementApi.php
File
- vendor/
auth0/ auth0-php/ tests/ MockApi.php, line 17
Namespace
Auth0\TestsView source
abstract class MockApi {
/**
* Guzzle request history container for mock API.
*
* @var array
*/
protected $requestHistory = [];
/**
* History index to use.
*
* @var integer
*/
protected $historyIndex = 0;
/**
* Management API object.
*
* @var Management|Authentication|JWKFetcher
*/
protected $client;
/**
* MockApi constructor.
*
* @param array $responses Array of GuzzleHttp\Psr7\Response objects.
* @param array $config Additional optional configuration needed for mocked class.
*/
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);
}
/**
* @param array $guzzleOptions
* @param array $config
*
* @return mixed
*/
public abstract function setClient(array $guzzleOptions, array $config = []);
/**
* Return the endpoint being used.
*
* @return Management|Authentication|JWKFetcher
*/
public function call() {
$this->historyIndex++;
return $this->client;
}
/**
* Get the URL from a mocked request.
*
* @param integer $parse_component Component for parse_url, null to return complete URL.
*
* @return string
*/
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);
}
/**
* Get the URL query from a mocked request.
*
* @return string
*/
public function getHistoryQuery() {
return $this
->getHistoryUrl(PHP_URL_QUERY);
}
/**
* Get the HTTP method from a mocked request.
*
* @return string
*/
public function getHistoryMethod() {
return $this
->getHistory()
->getMethod();
}
/**
* Get the body from a mocked request.
*
* @return \stdClass|array
*/
public function getHistoryBody() {
$body = $this
->getHistory()
->getBody();
return json_decode($body, true);
}
/**
* Get the form body from a mocked request.
*
* @return string
*/
public function getHistoryBodyAsString() {
return $this
->getHistory()
->getBody()
->getContents();
}
/**
* Get the headers from a mocked request.
*
* @return array
*/
public function getHistoryHeaders() {
return $this
->getHistory()
->getHeaders();
}
/**
* Get a Guzzle history record from an array populated by Middleware::history().
*
* @return Request
*/
protected function getHistory() {
$requestHistoryIndex = $this->historyIndex - 1;
return $this->requestHistory[$requestHistoryIndex]['request'];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MockApi:: |
protected | property | Management API object. | 2 |
MockApi:: |
protected | property | History index to use. | |
MockApi:: |
protected | property | Guzzle request history container for mock API. | |
MockApi:: |
public | function | Return the endpoint being used. | |
MockApi:: |
protected | function | Get a Guzzle history record from an array populated by Middleware::history(). | |
MockApi:: |
public | function | Get the body from a mocked request. | |
MockApi:: |
public | function | Get the form body from a mocked request. | |
MockApi:: |
public | function | Get the headers from a mocked request. | |
MockApi:: |
public | function | Get the HTTP method from a mocked request. | |
MockApi:: |
public | function | Get the URL query from a mocked request. | |
MockApi:: |
public | function | Get the URL from a mocked request. | |
MockApi:: |
abstract public | function | 2 | |
MockApi:: |
public | function | MockApi constructor. |