Skip to content

Commit

Permalink
Fixes for SessionProvider.factory (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmymcpeter authored Jan 26, 2018
1 parent 738aeac commit 496a9cb
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/Intacct/SessionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Intacct\Credentials\SenderCredentials;
use Intacct\Credentials\SessionCredentials;
use Intacct\Functions\Company\ApiSessionCreate;
use Intacct\Xml\RequestHandler;

class SessionProvider
{
Expand All @@ -39,11 +38,9 @@ public static function factory(ClientConfig $config = null): ClientConfig
$requestConfig->setControlId('sessionProvider');
$requestConfig->setNoRetryServerErrorCodes([]); // Retry all 500 level errors

$handler = new RequestHandler($config, $requestConfig);
$content = [
new ApiSessionCreate(),
];
$response = $handler->executeOnline($content);
$client = new OnlineClient($config);
$response = $client->execute(new ApiSessionCreate(), $requestConfig);

$authentication = $response->getAuthentication();
$result = $response->getResult();

Expand Down
63 changes: 63 additions & 0 deletions test/Intacct/SessionProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,67 @@ public function testFromSessionCredentials()
$sessionCreds->getEndpointUrl()
);
}

public function testFromSessionCredsUsingEnvironmentSender()
{
$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,
]);

putenv('INTACCT_SENDER_ID=envsender');
putenv('INTACCT_SENDER_PASSWORD=envpass');

$config = new ClientConfig();
$config->setSessionId('fAkESesSiOnId..');
$config->setEndpointUrl('https://unittest.intacct.com/ia/xml/xmlgw.phtml');
$config->setMockHandler($mock);

$sessionCreds = SessionProvider::factory($config);

$this->assertEquals('fAkESesSiOnId..', $sessionCreds->getSessionId());
$this->assertEquals(
'https://unittest.intacct.com/ia/xml/xmlgw.phtml',
$sessionCreds->getEndpointUrl()
);
$this->assertEquals('envsender', $sessionCreds->getSenderId());
$this->assertEquals('envpass', $sessionCreds->getSenderPassword());

putenv('INTACCT_SENDER_ID');
putenv('INTACCT_SENDER_PASSWORD');
}
}

0 comments on commit 496a9cb

Please sign in to comment.