Example #1
0
 /**
  * Config options:
  * - client_id
  * - client_secret
  * - base_url
  * - logging_enable
  *   default value false
  * - logging_level
  *   default value @see \Psr\Log\LogLevel::INFO
  * - logging_file_name
  *   default value @see SubscribePro\Http::DEFAULT_LOG_FILE_NAME
  * - logging_line_format
  *   default value  @see SubscribePro\Http::DEFAULT_LOG_LINE_FORMAT
  * - logging_message_format
  *   default value @see SubscribePro\Http::DEFAULT_LOG_MESSAGE_FORMAT
  * - <service_name>
  *   Config options for specified service
  *
  * @param array $config
  * @throws \SubscribePro\Exception\InvalidArgumentException
  */
 public function __construct(array $config = [])
 {
     $config = array_merge(['client_id' => getenv(static::CLIENT_ID_ENV_NAME), 'client_secret' => getenv(static::CLIENT_SECRET_ENV_NAME), 'base_url' => null, 'logging_enable' => false, 'logging_level' => null, 'logging_file_name' => null, 'logging_line_format' => null, 'logging_message_format' => null], $config);
     if (!$config['client_id']) {
         throw new InvalidArgumentException('Required "client_id" key is not supplied in config and could not find fallback environment variable "' . static::CLIENT_ID_ENV_NAME . '"');
     }
     if (!$config['client_secret']) {
         throw new InvalidArgumentException('Required "client_secret" key is not supplied in config and could not find fallback environment variable "' . static::CLIENT_SECRET_ENV_NAME . '"');
     }
     $app = new App($config['client_id'], $config['client_secret']);
     unset($config['client_id']);
     unset($config['client_secret']);
     $this->http = new Http($app, $config['base_url']);
     unset($config['base_url']);
     if ($config['logging_enable']) {
         $this->http->addDefaultLogger($config['logging_file_name'], $config['logging_line_format'], $config['logging_message_format'], $config['logging_level']);
     }
     unset($config['logging_enable']);
     unset($config['logging_level']);
     unset($config['logging_file_name']);
     unset($config['logging_line_format']);
     unset($config['logging_message_format']);
     $this->serviceFactoryResolver = new ServiceFactoryResolver($this->http, $config);
     $this->toolFactory = new ToolFactory($this->http);
 }
 /**
  * @param string|null $fileName
  * @param string|null $lineFormat
  * @param string|null $messageFormat
  * @param string $logLevel
  * @param \Psr\Log\LoggerInterface $logger
  * @param \GuzzleHttp\MessageFormatter $messageFormatter
  * @param callable $middlewareCallback
  * @dataProvider addDefaultLoggerDataProvider
  */
 public function testAddDefaultLogger($fileName, $lineFormat, $messageFormat, $logLevel, $logger, $messageFormatter, $middlewareCallback)
 {
     $this->httpMock->expects($this->once())->method('createMiddlewareLogCallback')->with($logger, $messageFormatter, $logLevel)->willReturn($middlewareCallback);
     $this->handlerStackMock->expects($this->once())->method('push')->with($middlewareCallback, 'logger');
     $this->httpMock->addDefaultLogger($fileName, $lineFormat, $messageFormat, $logLevel);
 }