/** * @covers Intacct\Credentials\ProfileCredentialProvider::getSenderCredentials * @covers Intacct\Credentials\ProfileCredentialProvider::getIniProfileData * @covers Intacct\Credentials\ProfileCredentialProvider::getHomeDirProfile */ public function testGetCredentialsFromDefaultProfile() { $dir = $this->clearEnv(); $ini = <<<EOF [default] sender_id = defsenderid sender_password = defsenderpass company_id = defcompanyid user_id = defuserid user_password = defuserpass endpoint_url = https://unittest.intacct.com/ia/xmlgw.phtml [unittest] company_id = inicompanyid user_id = iniuserid user_password = iniuserpass EOF; file_put_contents($dir . '/credentials.ini', $ini); putenv('HOME=' . dirname($dir)); $config = []; $loginCreds = $this->provider->getLoginCredentials($config); $expectedLogin = ['company_id' => 'defcompanyid', 'user_id' => 'defuserid', 'user_password' => 'defuserpass']; $this->assertEquals($expectedLogin, $loginCreds); $senderCreds = $this->provider->getSenderCredentials($config); $expectedSender = ['sender_id' => 'defsenderid', 'sender_password' => 'defsenderpass', 'endpoint_url' => 'https://unittest.intacct.com/ia/xmlgw.phtml']; $this->assertEquals($expectedSender, $senderCreds); }
/** * 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); }