/**
     * @covers Intacct\Credentials\ProfileCredentialProvider::getLoginCredentials
     * @covers Intacct\Credentials\ProfileCredentialProvider::getIniProfileData
     * @expectedException InvalidArgumentException
     * @expectedExceptionMessage Profile name "default" not found in credentials file
     */
    public function testGetLoginCredentialsMissingDefault()
    {
        $dir = $this->clearEnv();
        $ini = <<<EOF
[notdefault]
sender_id = testsenderid
sender_password = testsenderpass
EOF;
        file_put_contents($dir . '/credentials.ini', $ini);
        putenv('HOME=' . dirname($dir));
        $this->provider->getLoginCredentials();
    }
Ejemplo n.º 2
0
 /**
  * Initializes the class with the given parameters.
  *
  * The constructor accepts the following options:
  *
  * - `profile_name` (string) Profile name to use
  * - `profile_file` (string) Profile file to load from
  * - `sender_id` (string) Intacct sender ID
  * - `sender_password` (string) Intacct sender password
  * - `endpoint_url` (string) Endpoint URL
  * - `verify_ssl` (bool, default=bool(true)) Verify SSL certificate of response
  *
  * @param array $params Sender Credentials configuration options
  * @throws InvalidArgumentException
  */
 public function __construct(array $params = [])
 {
     $defaults = ['profile_name' => getenv(static::SENDER_PROFILE_ENV_NAME) ? getenv(static::SENDER_PROFILE_ENV_NAME) : static::DEFAULT_SENDER_PROFILE, 'sender_id' => getenv(static::SENDER_ID_ENV_NAME), 'sender_password' => getenv(static::SENDER_PASSWORD_ENV_NAME), 'endpoint_url' => null, 'verify_ssl' => true];
     $config = array_merge($defaults, $params);
     if (!$config['sender_id'] && !$config['sender_password'] && $config['profile_name']) {
         $profileProvider = new ProfileCredentialProvider();
         $profileCreds = $profileProvider->getSenderCredentials($config);
         if ($config['endpoint_url'] && isset($profileCreds['endpoint_url'])) {
             //stop overwriting the endpoint_url if it was passed in already
             unset($profileCreds['endpoint_url']);
         }
         $config = array_merge($config, $profileCreds);
     }
     if (!$config['sender_id']) {
         throw new InvalidArgumentException('Required "sender_id" key not supplied in params or env variable "' . static::SENDER_ID_ENV_NAME . '"');
     }
     if (!$config['sender_password']) {
         throw new InvalidArgumentException('Required "sender_password" key not supplied in params or env variable "' . static::SENDER_PASSWORD_ENV_NAME . '"');
     }
     $this->senderId = $config['sender_id'];
     $this->password = $config['sender_password'];
     $this->endpoint = new Endpoint($config);
 }
Ejemplo n.º 3
0
 /**
  * Initializes the class with the given parameters.
  *
  * The constructor accepts the following options:
  *
  * - `profile_name` (string, default=string "default") Profile name to use
  * - `profile_file` (string) Profile file to load from
  * - `company_id` (string) Intacct company ID
  * - `user_id` (string) Intacct user ID
  * - `user_password` (string) Intacct user password
  * - `mock_handler` (GuzzleHttp\Handler\MockHandler) Mock handler for unit tests
  *
  * @param array $params Login Credentials configuration options
  * @param SenderCredentials $senderCreds
  * @throws InvalidArgumentException
  */
 public function __construct(array $params, SenderCredentials $senderCreds)
 {
     $defaults = ['profile_name' => getenv(static::COMPANY_PROFILE_ENV_NAME) ? getenv(static::COMPANY_PROFILE_ENV_NAME) : static::DEFAULT_COMPANY_PROFILE, 'company_id' => getenv(static::COMPANY_ID_ENV_NAME), 'user_id' => getenv(static::USER_ID_ENV_NAME), 'user_password' => getenv(static::USER_PASSWORD_ENV_NAME), 'mock_handler' => null];
     $config = array_merge($defaults, $params);
     if (!$config['company_id'] && !$config['user_id'] && !$config['user_password'] && $config['profile_name']) {
         $profileProvider = new ProfileCredentialProvider();
         $profileCreds = $profileProvider->getLoginCredentials($config);
         $config = array_merge($config, $profileCreds);
     }
     if (!$config['company_id']) {
         throw new InvalidArgumentException('Required "company_id" key not supplied in params or env variable "' . static::COMPANY_ID_ENV_NAME . '"');
     }
     if (!$config['user_id']) {
         throw new InvalidArgumentException('Required "user_id" key not supplied in params or env variable "' . static::USER_ID_ENV_NAME . '"');
     }
     if (!$config['user_password']) {
         throw new InvalidArgumentException('Required "user_password" key not supplied in params or env variable "' . static::USER_PASSWORD_ENV_NAME . '"');
     }
     $this->companyId = $config['company_id'];
     $this->userId = $config['user_id'];
     $this->password = $config['user_password'];
     $this->senderCreds = $senderCreds;
     $this->mockHandler = $config['mock_handler'];
 }