public static function ContentHubClientMock::register in Acquia Content Hub 8.2
1 call to ContentHubClientMock::register()
- ClientFactoryMock::registerClient in tests/
modules/ acquia_contenthub_server_test/ src/ Client/ ClientFactoryMock.php - Override original, and replace Conent Hub client with mock.
File
- tests/
modules/ acquia_contenthub_server_test/ src/ Client/ ContentHubClientMock.php, line 42
Class
- ContentHubClientMock
- Mocks server responses.
Namespace
Drupal\acquia_contenthub_server_test\ClientCode
public static function register(LoggerInterface $logger, EventDispatcherInterface $dispatcher, $name, $url, $api_key, $secret, $api_version = 'v2') {
if ($url !== MockDataProvider::VALID_HOSTNAME) {
throw new RequestException("Could not get authorization from Content Hub to register client {$name}. Are your credentials inserted correctly?", new Request('POST', \Drupal::request()
->getRequestUri()));
}
if ($api_key !== MockDataProvider::VALID_API_KEY) {
self::generateErrorResponse("[4001] Not Found: Customer Key {$api_key} could not be found.", 401);
}
if ($secret !== MockDataProvider::VALID_SECRET) {
self::generateErrorResponse('[4001] Signature for the message does not match expected signature for API key.', 401);
}
if ($name !== MockDataProvider::VALID_CLIENT_NAME) {
self::generateErrorResponse('Name is already in use within subscription.', 4006);
}
$config = [
'base_uri' => "{$url}/{$api_version}",
'headers' => [
'Content-Type' => 'application/json',
'User-Agent' => self::LIBRARYNAME . '/' . static::VERSION . ' ' . \GuzzleHttp\default_user_agent(),
],
];
$key = new Key($api_key, $secret);
$middleware = new HmacAuthMiddleware($key);
$settings = new Settings($name, MockDataProvider::SETTINGS_UUID, $api_key, $secret, $url);
return new ContentHubClientMock($config, $logger, $settings, $middleware, $dispatcher, $api_version);
}