Skip to content

Commit

Permalink
Added ability to retrieve the last result object
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebarlow committed Dec 8, 2016
1 parent 1f1a427 commit 7ca4a79
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/Reporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Reporter
'Finance.getVendorsAndRegions' => '\Snscripts\ITCReporter\Responses\FinanceGetVendors',
'Finance.getReport' => '\Snscripts\ITCReporter\Responses\FinanceGetReport'
];
protected $lastResult = null;

/**
* constructor - setup guzzle dependency
Expand All @@ -45,7 +46,7 @@ public function getSalesAccounts()
{
$json = $this->buildJsonRequest('Sales.getAccounts');

$Result = $this->performRequest(self::SALESURL, $json);
$this->lastResult = $Result = $this->performRequest(self::SALESURL, $json);

if ($Result->isSuccess()) {
return $this->processResponse(
Expand All @@ -66,7 +67,7 @@ public function getSalesVendors()
{
$json = $this->buildJsonRequest('Sales.getVendors');

$Result = $this->performRequest(self::SALESURL, $json);
$this->lastResult = $Result = $this->performRequest(self::SALESURL, $json);

if ($Result->isSuccess()) {
return $this->processResponse(
Expand Down Expand Up @@ -107,7 +108,7 @@ public function getSalesReport(
$date
);

$Result = $this->performRequest(self::SALESURL, $json);
$this->lastResult = $Result = $this->performRequest(self::SALESURL, $json);

if ($Result->isSuccess()) {
return $this->processResponse(
Expand All @@ -128,7 +129,7 @@ public function getFinanceAccounts()
{
$json = $this->buildJsonRequest('Finance.getAccounts');

$Result = $this->performRequest(self::FINANCEURL, $json);
$this->lastResult = $Result = $this->performRequest(self::FINANCEURL, $json);

if ($Result->isSuccess()) {
return $this->processResponse(
Expand All @@ -149,7 +150,7 @@ public function getFinanceVendors()
{
$json = $this->buildJsonRequest('Finance.getVendorsAndRegions');

$Result = $this->performRequest(self::FINANCEURL, $json);
$this->lastResult = $Result = $this->performRequest(self::FINANCEURL, $json);

if ($Result->isSuccess()) {
return $this->processResponse(
Expand Down Expand Up @@ -190,7 +191,7 @@ public function getFinanceReport(
$period
);

$Result = $this->performRequest(self::FINANCEURL, $json);
$this->lastResult = $Result = $this->performRequest(self::FINANCEURL, $json);

if ($Result->isSuccess()) {
return $this->processResponse(
Expand Down Expand Up @@ -302,6 +303,16 @@ public function processResponse($action, ResponseInterface $Response)
return $ResponseProcesser->process();
}

/**
* get the last result set
*
* @return Result|null
*/
public function getLastResult()
{
return $this->lastResult;
}

/**
* set the user id
*
Expand Down
31 changes: 31 additions & 0 deletions tests/ReporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,37 @@ public function testGetFinanceReportReturnsBlankArrayWhenNoReport()
$Reporter->getFinanceReport(1234567, 'GB', 'Financial', '2016', '1')
);
}

public function testGetLastResultReturnsCorrectValue()
{
$Response = $this->getMock('Psr\Http\Message\ResponseInterface');
$Response->method('getBody')
->willReturn('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Vendors><Vendor>1234567</Vendor><Vendor>9876543</Vendor></Vendors>');
$Response->method('getStatusCode')
->willReturn(200);

$GuzzleMock = $this->getMock('GuzzleHttp\ClientInterface');
$GuzzleMock->method('request')
->willReturn(
$Response
);

$Reporter = new Reporter(
$GuzzleMock
);
$Reporter->setUserId('me@me.com')->setPassword('123qaz');

$this->assertNull(
$Reporter->getLastResult()
);

$accounts = $Reporter->getSalesAccounts();

$this->assertInstanceOf(
'Snscripts\Result\Result',
$Reporter->getLastResult()
);
}
}

class TestSalesReportContent
Expand Down

0 comments on commit 7ca4a79

Please sign in to comment.