/** * @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(); }
/** * 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']; }