| 676 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace Srmklive\PayPal\Tests\Unit;
|
|
|
4 |
|
|
|
5 |
use GuzzleHttp\Client as HttpClient;
|
|
|
6 |
use GuzzleHttp\Utils;
|
|
|
7 |
use PHPUnit\Framework\TestCase;
|
|
|
8 |
use Srmklive\PayPal\Tests\MockClientClasses;
|
|
|
9 |
use Srmklive\PayPal\Tests\MockResponsePayloads;
|
|
|
10 |
|
|
|
11 |
class ClientTest extends TestCase
|
|
|
12 |
{
|
|
|
13 |
use MockClientClasses;
|
|
|
14 |
use MockResponsePayloads;
|
|
|
15 |
|
|
|
16 |
/** @test */
|
|
|
17 |
public function it_can_be_instantiated()
|
|
|
18 |
{
|
|
|
19 |
$client = new HttpClient();
|
|
|
20 |
$this->assertInstanceOf(HttpClient::class, $client);
|
|
|
21 |
}
|
|
|
22 |
|
|
|
23 |
/** @test */
|
|
|
24 |
public function it_can_get_access_token()
|
|
|
25 |
{
|
|
|
26 |
$expectedResponse = $this->mockAccessTokenResponse();
|
|
|
27 |
|
|
|
28 |
$expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/oauth2/token?grant_type=client_credentials';
|
|
|
29 |
$expectedParams = [
|
|
|
30 |
'headers' => [
|
|
|
31 |
'Accept' => 'application/json',
|
|
|
32 |
'Accept-Language' => 'en_US',
|
|
|
33 |
],
|
|
|
34 |
'auth' => ['username', 'password'],
|
|
|
35 |
];
|
|
|
36 |
|
|
|
37 |
$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams);
|
|
|
38 |
|
|
|
39 |
$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true));
|
|
|
40 |
}
|
|
|
41 |
}
|