Пример #1
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
  * - `sender_id` (string) Intacct sender ID
  * - `sender_password` (string) Intacct sender password
  * - `session_id` (string) Intacct session ID
  * - `endpoint_url` (string) Endpoint URL
  * - `company_id` (string) Intacct company ID
  * - `user_id` (string) Intacct user ID
  * - `user_password` (string) Intacct user password
  * - `max_retries` (int, default=int(5)) Max number of retries
  * - `no_retry_server_error_codes` (int[], default=array(524)) HTTP server error codes to abort
  * retrying if one occurs
  * - `verify_ssl` (bool, default=bool(true)) Verify SSL certificate of response
  * - `logger` (Psr\Log\LoggerInterface)
  * - `log_formatter` (Intacct\Logging\MessageFormatter) Log formatter
  * - `log_level` (int, default=int(400)) Log level
  * - `mock_handler` (GuzzleHttp\Handler\MockHandler) Mock handler for unit tests
  *
  * @param array $params Client configuration options
  */
 public function __construct(array $params = [])
 {
     $defaults = ['session_id' => null, 'endpoint_url' => null, 'verify_ssl' => true];
     $envProfile = getenv(static::PROFILE_ENV_NAME);
     if ($envProfile) {
         $defaults['profile_name'] = $envProfile;
     }
     $config = array_merge($defaults, $params);
     $provider = new SessionProvider();
     $senderCreds = new SenderCredentials($config);
     if ($config['session_id']) {
         $sessionCreds = new SessionCredentials($config, $senderCreds);
         $this->sessionCreds = $provider->fromSessionCredentials($sessionCreds);
     } else {
         $loginCreds = new LoginCredentials($config, $senderCreds);
         $this->sessionCreds = $provider->fromLoginCredentials($loginCreds);
     }
 }
    /**
     * @covers Intacct\Credentials\SessionProvider::__construct
     * @covers Intacct\Credentials\SessionProvider::fromSessionCredentials
     * @covers Intacct\Credentials\SessionProvider::getAPISession
     * @covers Intacct\Credentials\SessionProvider::getConfig
     */
    public function testFromSessionCredentials()
    {
        $xml = <<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<response>
      <control>
            <status>success</status>
            <senderid>testsenderid</senderid>
            <controlid>sessionProvider</controlid>
            <uniqueid>false</uniqueid>
            <dtdversion>3.0</dtdversion>
      </control>
      <operation>
            <authentication>
                  <status>success</status>
                  <userid>testuser</userid>
                  <companyid>testcompany</companyid>
                  <sessiontimestamp>2015-12-06T15:57:08-08:00</sessiontimestamp>
            </authentication>
            <result>
                  <status>success</status>
                  <function>getSession</function>
                  <controlid>testControlId</controlid>
                  <data>
                        <api>
                              <sessionid>fAkESesSiOnId..</sessionid>
                              <endpoint>https://unittest.intacct.com/ia/xml/xmlgw.phtml</endpoint>
                        </api>
                  </data>
            </result>
      </operation>
</response>
EOF;
        $headers = ['Content-Type' => 'text/xml; encoding="UTF-8"'];
        $response = new Response(200, $headers, $xml);
        $mock = new MockHandler([$response]);
        $config = ['session_id' => 'fAkESesSiOnId..', 'endpoint_url' => 'https://unittest.intacct.com/ia/xml/xmlgw.phtml', 'mock_handler' => $mock];
        $sessionCreds = new SessionCredentials($config, $this->senderCreds);
        $newSessionCreds = $this->object->fromSessionCredentials($sessionCreds);
        $this->assertEquals('fAkESesSiOnId..', $newSessionCreds->getSessionId());
        $endpoint = $newSessionCreds->getEndpoint();
        $this->assertEquals('https://unittest.intacct.com/ia/xml/xmlgw.phtml', $endpoint->getEndpoint());
        $this->assertThat($newSessionCreds->getSenderCredentials(), $this->isInstanceOf('Intacct\\Credentials\\SenderCredentials'));
    }