Example #1
0
 /**
  * @inheritDoc
  */
 public function buildRequest(ApiRequestBuilder $requestBuilder, ApiInterface $api)
 {
     $requestBuilder->withMethod('GET')->withUri($this->buildServiceUrl('/posts/'))->withJsonResponse('array<Rafrsr\\SampleApi\\Model\\Post>')->withMock('Rafrsr\\SampleApi\\Services\\GetPosts\\GetPostsMock');
     if ($this->getUserId()) {
         $requestBuilder->options()->addQuery('userId', $this->getUserId());
     }
 }
 /**
  * @inheritdoc
  */
 public function buildRequest(ApiRequestBuilder $requestBuilder, ApiInterface $api)
 {
     /** @var QPayApi $api */
     $data = Object2ArrayBuilder::create()->build()->createArray($this);
     if (array_key_exists('urn:Header', $data)) {
         $data['urn:Header'] = ['urn1:CertPublicKey' => $api->getCredentials()->getCertificateSerialNumber(), 'urn1:UIID' => $api->getCredentials()->getUuid(), 'urn1:User' => 'system'];
     }
     if (array_key_exists('urn:RequestToken', $data)) {
         $data['urn:RequestToken'] = Object2ArrayBuilder::create()->build()->createArray($api->getRequestToken());
     }
     //build the request url
     $uri = sprintf('https://pos.qpay123.biz/%s/Gateway.svc', $api->getCredentials()->getMerchantName());
     $xml = QPayXMLParser::createRequest($this->getActionName(), $data);
     $requestBuilder->withUri($uri)->withMethod('POST')->withXMLBody($xml)->options()->setCurlOption(CURLOPT_CAINFO, $api->getCredentials()->getAuthorityCertificateFile())->setCurlOption(CURLOPT_SSLCERT, $api->getCredentials()->getClientCertificateFile())->setCurlOption(CURLOPT_SSLKEY, $api->getCredentials()->getCertificateKeyFile())->setCurlOption(CURLOPT_SSLCERTPASSWD, $api->getCredentials()->getCertificatePassword())->SSLVerification(false);
 }
    public function testWithXmlBody()
    {
        $post = new Post();
        $post->setId(1);
        $post->setTitle('title');
        $post->setBody('body');
        $post->setUserId(1);
        $this->rb->withXMLBody($post);
        $xml = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<result>
  <userId>1</userId>
  <id>1</id>
  <title><![CDATA[title]]></title>
  <body><![CDATA[body]]></body>
</result>

XML;
        static::assertEquals($xml, $this->rb->getBody());
    }
Example #4
0
 public function testGenericApi()
 {
     $api = new GenericApi(ApiInterface::MODE_MOCK);
     //can use MODE_LIVE
     $mockCallback = function () {
         return new Response(200, [], file_get_contents(__DIR__ . '/../sample/Fixtures/post1.json'));
     };
     $request = ApiRequestBuilder::create()->withMethod('get')->withUri('http://jsonplaceholder.typicode.com/posts/1')->withMock(new GenericApiMock($mockCallback))->getRequest();
     $service = new GenericApiService($request);
     $response = $api->process($service);
     static::assertEquals('200', $response->getStatusCode());
     static::assertEquals(1, json_decode($response->getBody()->getContents(), true)['id']);
 }
Example #5
0
 /**
  * @inheritDoc
  */
 public function buildRequest(ApiRequestBuilder $requestBuilder, ApiInterface $api)
 {
     $requestBuilder->withMethod('DELETE')->withUri($this->buildServiceUrl('/posts/%s', [$this->getPost()->getId()]))->withMock('Rafrsr\\SampleApi\\Services\\DeletePost\\DeletePostMock');
 }
Example #6
0
 /**
  * @inheritDoc
  */
 public function buildRequest(ApiRequestBuilder $requestBuilder, ApiInterface $api)
 {
     $requestBuilder->withMethod('PUT')->withUri($this->buildServiceUrl('/posts/%s', [$this->getPost()->getId()]))->withJsonResponse('Rafrsr\\SampleApi\\Model\\Post')->withMock('Rafrsr\\SampleApi\\Services\\UpdatePost\\UpdatePostMock')->options()->setFormParams(json_decode(SerializerBuilder::create()->build()->serialize($this->post, 'json'), true));
 }
Example #7
0
 /**
  * @inheritDoc
  */
 public function buildRequest(ApiRequestBuilder $requestBuilder, ApiInterface $api)
 {
     $requestBuilder->withMethod('GET')->withUri($this->buildServiceUrl('/posts/%s', [$this->getPostId()]))->withMock('Rafrsr\\SampleApi\\Services\\GetPost\\GetPostMock')->withJsonResponse('Rafrsr\\SampleApi\\Model\\Post');
 }