Skip to content

Commit

Permalink
check property status response
Browse files Browse the repository at this point in the history
  • Loading branch information
giansalex committed Dec 8, 2019
1 parent 3a34432 commit 469e6c2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/Ws/Services/ExtService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Greenter\Ws\Services;

use Exception;
use Greenter\Model\Response\Error;
use Greenter\Model\Response\StatusResult;

Expand All @@ -20,6 +21,7 @@ class ExtService extends BaseSunat
* @param string $ticket
*
* @return StatusResult
* @throws Exception
*/
public function getStatus($ticket)
{
Expand All @@ -40,7 +42,15 @@ private function getStatusInternal($ticket)
];

$response = $this->getClient()->call('getStatus', ['parameters' => $params]);
$status = $response->status;
if (!isset($response->status)) {
throw new Exception('Invalid getStatus service response.');
}

return $this->processResponse($response->status);
}

private function processResponse($status)
{
$code = intval($status->statusCode);

$result = new StatusResult();
Expand Down
9 changes: 9 additions & 0 deletions tests/Ws/Services/FeSunatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ public function testGetStatus()
$this->assertContains('aceptada', $result->getCdrResponse()->getDescription());
}

/**
* @expectedException \Exception
*/
public function testGetStatusInvalidResponse()
{
$wss = $this->getExtServiceMock();
$wss->getStatus('1500523236600');
}

public function testGetStatusWithExceptionCode()
{
$wss = $this->getExtServiceMock();
Expand Down
3 changes: 2 additions & 1 deletion tests/Ws/Services/FeSunatTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,9 @@ private function getExtServiceMock()
$ticket = $args['parameters']['ticket'];

$obj = new \stdClass();
$obj->status = new \stdClass();
if ($ticket === '1500523236600') return $obj;

$obj->status = new \stdClass();
if ('223123123213' === $ticket) {
$obj->status->statusCode = '98';
} elseif ('667123123214' === $ticket){
Expand Down

0 comments on commit 469e6c2

Please sign in to comment.