Пример #1
0
 /**
  * Test sending a message, expecting an exception due to failure response.
  *
  */
 public function testSendMessageFailure404()
 {
     // Dummy and Mock required objects
     $statusCode = 404;
     $this->setExpectedException("com\\realexpayments\\remote\\sdk\\RealexException", "Exception communicating with Realex");
     try {
         $endpoint = 'https://some-test-endpoint';
         $onlyAllowHttps = true;
         $xml = "<element>test response xml</element>";
         $httpResponse = new HttpResponse();
         $httpResponse->setResponseCode($statusCode);
         $httpResponse->setBody($xml);
         /** @var HttpConfiguration $configurationMock */
         $configurationMock = \Phockito::mock("com\\realexpayments\\remote\\sdk\\http\\HttpConfiguration");
         \Phockito::when($configurationMock->getEndPoint())->return($endpoint);
         \Phockito::when($configurationMock->isOnlyAllowHttps())->return($onlyAllowHttps);
         /** @var HttpClient $httpClientMock */
         $httpClientMock = \Phockito::mock("com\\realexpayments\\remote\\sdk\\http\\HttpClient");
         /** @var HttpRequest $anything */
         \Phockito::when($httpClientMock->execute(\Hamcrest_Core_IsAnything::anything(), \Hamcrest_Core_IsAnything::anything()))->return($httpResponse);
         // execute the method
         $response = HttpUtils::sendMessage($xml, $httpClientMock, $configurationMock);
     } catch (RealexException $e) {
         throw $e;
     } catch (Exception $e) {
         $this->fail("Unexpected exception:" . $e->getMessage());
     }
 }
Пример #2
0
/**
 * This matcher always evaluates to true.
 * 
 * @param string $description A meaningful string used when describing itself.
 */
function anything($description = 'ANYTHING')
{
    require_once 'Hamcrest/Core/IsAnything.php';
    return Hamcrest_Core_IsAnything::anything($description);
}
Пример #3
0
 protected function createMatcher()
 {
     return Hamcrest_Core_IsAnything::anything();
 }
Пример #4
0
 /**
  * Test sending a ThreeDSecure Verify Enrolled request and receiving a ThreeDSecure Verify Enrolled response.
  *
  * @expectedException com\realexpayments\remote\sdk\RealexException
  */
 public function testSendThreeDSecureInvalidResponseHash()
 {
     //get sample response XML
     $path = SampleXmlValidationUtils::THREE_D_SECURE_VERIFY_ENROLLED_RESPONSE_XML_PATH;
     $prefix = __DIR__ . '/../../resources';
     $xml = file_get_contents($prefix . $path);
     $fromXMLResponse = new ThreeDSecureResponse();
     $fromXMLResponse = $fromXMLResponse->fromXml($xml);
     // add invalid hash
     $fromXMLResponse->setHash("invalid hash");
     //mock HttpResponse
     /** @var HttpResponse $httpResponseMock */
     $httpResponseMock = Phockito::mock("com\\realexpayments\\remote\\sdk\\http\\HttpResponse");
     \Phockito::when($httpResponseMock->getBody())->return($fromXMLResponse->toXML());
     \Phockito::when($httpResponseMock->getResponseCode())->return(200);
     // create empty request
     $request = new ThreeDSecureRequest();
     $httpConfiguration = new HttpConfiguration();
     $httpConfiguration->addOnlyAllowHttps(false)->addEndpoint("https://epage.payandshop.com/epage-remote.cgi");
     // mock HttpClient instance
     $httpClientMock = Phockito::mock("com\\realexpayments\\remote\\sdk\\http\\HttpClient");
     \Phockito::when($httpClientMock->execute(\Hamcrest_Core_IsAnything::anything(), \Hamcrest_Core_IsAnything::anything()))->return($httpResponseMock);
     // execute and send on client
     $realexClient = new RealexClient(SampleXmlValidationUtils::SECRET, $httpConfiguration, $httpClientMock);
     $realexClient->send($request);
     $this->fail("RealexException should have been thrown before this point.");
 }