| 676 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace Srmklive\PayPal\Tests\Unit\Client;
|
|
|
4 |
|
|
|
5 |
use GuzzleHttp\Utils;
|
|
|
6 |
use PHPUnit\Framework\TestCase;
|
|
|
7 |
use Srmklive\PayPal\Tests\MockClientClasses;
|
|
|
8 |
use Srmklive\PayPal\Tests\MockRequestPayloads;
|
|
|
9 |
use Srmklive\PayPal\Tests\MockResponsePayloads;
|
|
|
10 |
|
|
|
11 |
class WebHooksTest extends TestCase
|
|
|
12 |
{
|
|
|
13 |
use MockClientClasses;
|
|
|
14 |
use MockRequestPayloads;
|
|
|
15 |
use MockResponsePayloads;
|
|
|
16 |
|
|
|
17 |
/** @test */
|
|
|
18 |
public function it_can_create_a_web_hook()
|
|
|
19 |
{
|
|
|
20 |
$expectedResponse = $this->mockCreateWebHookResponse();
|
|
|
21 |
|
|
|
22 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks';
|
|
|
23 |
$expectedParams = [
|
|
|
24 |
'headers' => [
|
|
|
25 |
'Accept' => 'application/json',
|
|
|
26 |
'Accept-Language' => 'en_US',
|
|
|
27 |
'Authorization' => 'Bearer some-token',
|
|
|
28 |
],
|
|
|
29 |
'json' => $this->mockCreateWebHookParams(),
|
|
|
30 |
];
|
|
|
31 |
|
|
|
32 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post');
|
|
|
33 |
|
|
|
34 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
/** @test */
|
|
|
38 |
public function it_can_list_web_hooks()
|
|
|
39 |
{
|
|
|
40 |
$expectedResponse = $this->mockListWebHookResponse();
|
|
|
41 |
|
|
|
42 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks';
|
|
|
43 |
$expectedParams = [
|
|
|
44 |
'headers' => [
|
|
|
45 |
'Accept' => 'application/json',
|
|
|
46 |
'Accept-Language' => 'en_US',
|
|
|
47 |
'Authorization' => 'Bearer some-token',
|
|
|
48 |
],
|
|
|
49 |
];
|
|
|
50 |
|
|
|
51 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get');
|
|
|
52 |
|
|
|
53 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
/** @test */
|
|
|
57 |
public function it_can_delete_a_web_hook()
|
|
|
58 |
{
|
|
|
59 |
$expectedResponse = '';
|
|
|
60 |
|
|
|
61 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks/5GP028458E2496506';
|
|
|
62 |
$expectedParams = [
|
|
|
63 |
'headers' => [
|
|
|
64 |
'Accept' => 'application/json',
|
|
|
65 |
'Accept-Language' => 'en_US',
|
|
|
66 |
'Authorization' => 'Bearer some-token',
|
|
|
67 |
],
|
|
|
68 |
];
|
|
|
69 |
|
|
|
70 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'delete');
|
|
|
71 |
|
|
|
72 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->delete($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
/** @test */
|
|
|
76 |
public function it_can_update_a_web_hook()
|
|
|
77 |
{
|
|
|
78 |
$expectedResponse = $this->mockUpdateWebHookResponse();
|
|
|
79 |
|
|
|
80 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks/0EH40505U7160970P';
|
|
|
81 |
$expectedParams = [
|
|
|
82 |
'headers' => [
|
|
|
83 |
'Accept' => 'application/json',
|
|
|
84 |
'Accept-Language' => 'en_US',
|
|
|
85 |
'Authorization' => 'Bearer some-token',
|
|
|
86 |
],
|
|
|
87 |
'json' => $this->mockUpdateWebHookParams(),
|
|
|
88 |
];
|
|
|
89 |
|
|
|
90 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'patch');
|
|
|
91 |
|
|
|
92 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->patch($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
/** @test */
|
|
|
96 |
public function it_can_show_details_for_a_web_hook()
|
|
|
97 |
{
|
|
|
98 |
$expectedResponse = $this->mockGetWebHookResponse();
|
|
|
99 |
|
|
|
100 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks/0EH40505U7160970P';
|
|
|
101 |
$expectedParams = [
|
|
|
102 |
'headers' => [
|
|
|
103 |
'Accept' => 'application/json',
|
|
|
104 |
'Accept-Language' => 'en_US',
|
|
|
105 |
'Authorization' => 'Bearer some-token',
|
|
|
106 |
],
|
|
|
107 |
];
|
|
|
108 |
|
|
|
109 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get');
|
|
|
110 |
|
|
|
111 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
/** @test */
|
|
|
115 |
public function it_can_list_web_hooks_events()
|
|
|
116 |
{
|
|
|
117 |
$expectedResponse = $this->mockListWebHookEventsResponse();
|
|
|
118 |
|
|
|
119 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks/0EH40505U7160970P';
|
|
|
120 |
$expectedParams = [
|
|
|
121 |
'headers' => [
|
|
|
122 |
'Accept' => 'application/json',
|
|
|
123 |
'Accept-Language' => 'en_US',
|
|
|
124 |
'Authorization' => 'Bearer some-token',
|
|
|
125 |
],
|
|
|
126 |
];
|
|
|
127 |
|
|
|
128 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get');
|
|
|
129 |
|
|
|
130 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
131 |
}
|
|
|
132 |
}
|