/** * Initializes the class with the given parameters. * * The constructor accepts the following options: * * - `session_id` (string) Intacct session ID * - `endpoint_url` (string) Endpoint URL * - `current_company_id` (string) Current Intacct company ID * - `current_user_id` (string) Current Intacct user ID * - `current_user_is_external` (bool) Current Intacct user is external * - `mock_handler` (GuzzleHttp\Handler\MockHandler) Mock handler for unit tests * * @param array $params Client configuration options * @throws InvalidArgumentException * * Initializes the class with the given parameters. * * @param array $params { * @var string $endpoint_url Endpoint URL * @var MockHandler $mock_handler Mock handler for unit testing * @var string $session_id Intacct session ID * } * @param SenderCredentials $senderCreds Sender credentials */ public function __construct(array $params, SenderCredentials $senderCreds) { $defaults = ['session_id' => null, 'endpoint_url' => null, 'mock_handler' => null, 'current_company_id' => null, 'current_user_id' => null, 'current_user_is_external' => false, 'logger' => null, 'log_formatter' => new MessageFormatter(MessageFormatter::CLF . MessageFormatter::DEBUG), 'log_level' => LogLevel::DEBUG]; $config = array_merge($defaults, $params); if (!$config['session_id']) { throw new InvalidArgumentException('Required "session_id" key not supplied in params'); } $this->sessionId = $config['session_id']; if ($config['endpoint_url']) { $this->endpoint = new Endpoint($config); } else { $this->endpoint = $senderCreds->getEndpoint(); } $this->senderCreds = $senderCreds; $this->currentCompanyId = $config['current_company_id']; $this->currentUserId = $config['current_user_id']; $this->currentUserIsExternal = $config['current_user_is_external']; $this->mockHandler = $config['mock_handler']; if ($config['logger']) { $this->logger = $config['logger']; } $this->logMessageFormat = $config['log_formatter']; $this->logLevel = $config['log_level']; }
/** * Get endpoint * * @return Endpoint */ public function getEndpoint() { return $this->senderCreds->getEndpoint(); }
/** * @covers Intacct\Credentials\SenderCredentials::__construct * @covers Intacct\Credentials\SenderCredentials::getSenderId * @covers Intacct\Credentials\SenderCredentials::getPassword * @covers Intacct\Credentials\SenderCredentials::getEndpoint */ public function testCredsFromProfileOverrideEndpoint() { $dir = $this->clearEnv(); $ini = <<<EOF [unittest] sender_id = inisenderid sender_password = inisenderpass endpoint_url = https://unittest.intacct.com/ia/xmlgw.phtml EOF; file_put_contents($dir . '/credentials.ini', $ini); putenv('HOME=' . dirname($dir)); $config = ['profile_name' => 'unittest', 'endpoint_url' => 'https://somethingelse.intacct.com/ia/xmlgw.phtml']; $senderCreds = new SenderCredentials($config); $this->assertEquals('inisenderid', $senderCreds->getSenderId()); $this->assertEquals('inisenderpass', $senderCreds->getPassword()); $this->assertEquals('https://somethingelse.intacct.com/ia/xmlgw.phtml', $senderCreds->getEndpoint()); }