Skip to content

Commit

Permalink
refactor #3 Provider31\Request\General::parse_request_data()
Browse files Browse the repository at this point in the history
  • Loading branch information
dshovchko committed Nov 29, 2017
1 parent 68ddf44 commit 1266bfa
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 10 deletions.
44 changes: 34 additions & 10 deletions src/Provider31/Request/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,13 @@ public function ServiceId()

/**
* Parse xml-request, which was previously "extracted" from the body of the http request
*
* @throws Exception\Structure
* processes contents of <Request> node
*/
protected function parse_request_data()
{
// process <Request> group
$r = $this->raw_request->get_nodes_from_request('Request');

if (count($r) < 1)
{
throw new Exception\Structure('The xml-query does not contain any element Request!', -52);
}
$r = $this->check_request_count(
$this->raw_request->get_nodes_from_request('Request')
);

foreach ($r[0]->childNodes as $child)
{
Expand All @@ -122,9 +117,38 @@ protected function parse_request_data()

$this->check_and_parse_operation($child);
}
$this->parse_operation_data();
}

/**
* Check count of <Request> nodes in xml-request
*
* @throws Exception\Structure
*/
protected function check_request_count($ar)
{
if (count($ar) < 1)
{
throw new Exception\Structure('The xml-query does not contain any element Request!', -52);
}
elseif (count($ar) > 1)
{
throw new Exception\Structure('The xml-query contains several elements Request!', -52);
}

return $ar;
}

/**
* Parse xml-request, which was previously "extracted" from the body of the http request
* processes contents of <Operation> node
*
* @throws Exception\Structure
*/
protected function parse_operation_data()
{
$this->check_presence_operation();

// process <Operation> group
$r = $this->raw_request->get_nodes_from_request($this->Operation);

foreach ($r[0]->childNodes as $child)
Expand Down
40 changes: 40 additions & 0 deletions test/Provider31/Request/GeneralTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,46 @@ public function test_ServiceId()
);
}

public function test_check_request_count()
{
file_put_contents('php://input', $this->XMLcheck());
$r = new General(new RAW());

$ar = array(1);

$this->invokeMethod($r, 'check_request_count', array($ar));
}

/**
* @expectedException EasyPay\Exception\Structure
* @expectedExceptionCode -52
* @expectedExceptionMessage The xml-query does not contain any element Request!
*/
public function test_check_request_count_exception1()
{
file_put_contents('php://input', $this->XMLcheck());
$r = new General(new RAW());

$ar = array();

$this->invokeMethod($r, 'check_request_count', array($ar));
}

/**
* @expectedException EasyPay\Exception\Structure
* @expectedExceptionCode -52
* @expectedExceptionMessage The xml-query contains several elements Request!
*/
public function test_check_request_count_exception2()
{
file_put_contents('php://input', $this->XMLcheck());
$r = new General(new RAW());

$ar = array(1,2,3);

$this->invokeMethod($r, 'check_request_count', array($ar));
}

/**
* @expectedException EasyPay\Exception\Structure
* @expectedExceptionCode -52
Expand Down

0 comments on commit 1266bfa

Please sign in to comment.