Skip to content

Commit

Permalink
Add specs
Browse files Browse the repository at this point in the history
  • Loading branch information
mpysiak committed Apr 4, 2024
1 parent 816a068 commit 553b05a
Show file tree
Hide file tree
Showing 6 changed files with 953 additions and 2 deletions.
21 changes: 21 additions & 0 deletions spec/Api/GenericApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use PhpSpec\ObjectBehavior;
use Psr\Http\Client\ClientInterface;
use GuzzleHttp\ClientInterface as GuzzleClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -53,4 +54,24 @@ function it_calls_api_by_url(

$this->get('TOKEN', 'http://url.com/')->shouldReturn(['parameter' => 'VALUE']);
}

function it_calls_api_by_url_using_guzzle_client(
GuzzleClientInterface $client,
ResponseInterface $response,
StreamInterface $body
): void {
$this->beConstructedWith($client);

$client->request('GET', 'http://url.com/', [
'headers' => [
'Authorization' => 'Bearer TOKEN',
'Content-Type' => 'application/json',
'Accept' => 'application/json',
],
])->willReturn($response);
$response->getBody()->willReturn($body);
$body->getContents()->willReturn('{ "parameter": "VALUE" }');

$this->get('TOKEN', 'http://url.com/')->shouldReturn(['parameter' => 'VALUE']);
}
}
61 changes: 61 additions & 0 deletions spec/Api/WebhookApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Psr\Http\Client\ClientInterface;
use GuzzleHttp\ClientInterface as GuzzleClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -47,6 +48,36 @@ function it_registers_webhook(
$this->register('TOKEN', 'https://webhook.com')->shouldReturn(['status' => 'CREATED']);
}

function it_registers_webhook_using_guzzle_client(
GuzzleClientInterface $client,
ResponseInterface $response,
StreamInterface $body
): void {
$this->beConstructedWith($client, 'http://base-url.com/');

$client->request(
'POST',
'http://base-url.com/v1/notifications/webhooks',
[
'headers' => [
'Authorization' => 'Bearer TOKEN',
'Content-Type' => 'application/json',
'Accept' => 'application/json',
],
'json' => [
'url' => 'https://webhook.com',
'event_types' => [
['name' => 'PAYMENT.CAPTURE.REFUNDED'],
],
],
]
)->willReturn($response);
$response->getBody()->willReturn($body);
$body->getContents()->willReturn('{ "status": "CREATED" }');

$this->register('TOKEN', 'https://webhook.com')->shouldReturn(['status' => 'CREATED']);
}

function it_registers_webhook_without_https(
ClientInterface $client,
RequestFactoryInterface $requestFactory,
Expand All @@ -63,4 +94,34 @@ function it_registers_webhook_without_https(

$this->register('TOKEN', 'http://webhook.com')->shouldReturn(['status' => 'CREATED']);
}

function it_registers_webhook_without_https_using_guzzle_client(
GuzzleClientInterface $client,
ResponseInterface $response,
StreamInterface $body
): void {
$this->beConstructedWith($client, 'http://base-url.com/');

$client->request(
'POST',
'http://base-url.com/v1/notifications/webhooks',
[
'headers' => [
'Authorization' => 'Bearer TOKEN',
'Content-Type' => 'application/json',
'Accept' => 'application/json',
],
'json' => [
'url' => 'https://webhook.com',
'event_types' => [
['name' => 'PAYMENT.CAPTURE.REFUNDED'],
],
],
]
)->willReturn($response);
$response->getBody()->willReturn($body);
$body->getContents()->willReturn('{ "status": "CREATED" }');

$this->register('TOKEN', 'http://webhook.com')->shouldReturn(['status' => 'CREATED']);
}
}
Loading

0 comments on commit 553b05a

Please sign in to comment.