| 676 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace Srmklive\PayPal\Tests\Feature;
|
|
|
4 |
|
|
|
5 |
use PHPUnit\Framework\TestCase;
|
|
|
6 |
use Srmklive\PayPal\Services\PayPal as PayPalClient;
|
|
|
7 |
use Srmklive\PayPal\Tests\MockClientClasses;
|
|
|
8 |
|
|
|
9 |
class AdapterConfigTest extends TestCase
|
|
|
10 |
{
|
|
|
11 |
use MockClientClasses;
|
|
|
12 |
|
|
|
13 |
/** @var \Srmklive\PayPal\Services\PayPal */
|
|
|
14 |
protected $client;
|
|
|
15 |
|
|
|
16 |
protected function setUp(): void
|
|
|
17 |
{
|
|
|
18 |
$this->client = new PayPalClient($this->getApiCredentials());
|
|
|
19 |
|
|
|
20 |
parent::setUp();
|
|
|
21 |
}
|
|
|
22 |
|
|
|
23 |
/** @test */
|
|
|
24 |
public function it_throws_exception_if_invalid_credentials_are_provided()
|
|
|
25 |
{
|
|
|
26 |
$this->expectException(\RuntimeException::class);
|
| 1663 |
lars |
27 |
$this->expectExceptionMessage('Invalid configuration provided. Please provide valid configuration for PayPal API. You can also refer to the documentation at https://srmklive.github.io/laravel-paypal/docs.html to setup correct configuration.');
|
| 676 |
lars |
28 |
|
|
|
29 |
$this->client = new PayPalClient([]);
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
/** @test */
|
|
|
33 |
public function it_throws_exception_if_invalid_mode_is_provided()
|
|
|
34 |
{
|
|
|
35 |
$this->expectException(\RuntimeException::class);
|
| 1663 |
lars |
36 |
$this->expectExceptionMessage('Invalid configuration provided. Please provide valid configuration for PayPal API. You can also refer to the documentation at https://srmklive.github.io/laravel-paypal/docs.html to setup correct configuration.');
|
| 676 |
lars |
37 |
|
|
|
38 |
$credentials = $this->getApiCredentials();
|
|
|
39 |
$credentials['mode'] = '';
|
|
|
40 |
|
|
|
41 |
$this->client = new PayPalClient($credentials);
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
/** @test */
|
|
|
45 |
public function it_throws_exception_if_empty_credentials_are_provided()
|
|
|
46 |
{
|
|
|
47 |
$this->expectException(\RuntimeException::class);
|
| 1663 |
lars |
48 |
$this->expectExceptionMessage('Invalid configuration provided. Please provide valid configuration for PayPal API. You can also refer to the documentation at https://srmklive.github.io/laravel-paypal/docs.html to setup correct configuration.');
|
| 676 |
lars |
49 |
|
|
|
50 |
$credentials = $this->getApiCredentials();
|
|
|
51 |
$credentials['sandbox'] = [];
|
|
|
52 |
|
|
|
53 |
$this->client = new PayPalClient($credentials);
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
/** @test */
|
|
|
57 |
public function it_throws_exception_if_credentials_items_are_not_provided()
|
|
|
58 |
{
|
|
|
59 |
$item = 'client_id';
|
|
|
60 |
|
|
|
61 |
$this->expectException(\RuntimeException::class);
|
| 1663 |
lars |
62 |
$this->expectExceptionMessage("{$item} missing from the provided configuration. Please add your application {$item}.");
|
| 676 |
lars |
63 |
|
|
|
64 |
$credentials = $this->getApiCredentials();
|
|
|
65 |
$credentials['sandbox'][$item] = '';
|
|
|
66 |
|
|
|
67 |
$client = new PayPalClient($credentials);
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
/** @test */
|
|
|
71 |
public function it_can_take_valid_credentials_and_return_the_client_instance()
|
|
|
72 |
{
|
|
|
73 |
$this->assertInstanceOf(PayPalClient::class, $this->client);
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
/** @test */
|
|
|
77 |
public function it_throws_exception_if_invalid_credentials_are_provided_through_method()
|
|
|
78 |
{
|
|
|
79 |
$this->expectException(\RuntimeException::class);
|
|
|
80 |
|
|
|
81 |
$this->client->setApiCredentials([]);
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
/** @test */
|
|
|
85 |
public function it_returns_the_client_instance_if_valid_credentials_are_provided_through_method()
|
|
|
86 |
{
|
|
|
87 |
$this->client->setApiCredentials($this->getApiCredentials());
|
|
|
88 |
|
|
|
89 |
$this->assertInstanceOf(PayPalClient::class, $this->client);
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
/** @test */
|
|
|
93 |
public function it_throws_exception_if_invalid_currency_is_set()
|
|
|
94 |
{
|
|
|
95 |
$this->expectException(\RuntimeException::class);
|
|
|
96 |
|
|
|
97 |
$this->client->setCurrency('PKR');
|
|
|
98 |
|
|
|
99 |
$this->assertNotEquals('PKR', $this->client->getCurrency());
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
/** @test */
|
|
|
103 |
public function it_can_set_a_valid_currency()
|
|
|
104 |
{
|
|
|
105 |
$this->client->setCurrency('EUR');
|
|
|
106 |
|
|
|
107 |
$this->assertNotEmpty($this->client->getCurrency());
|
|
|
108 |
$this->assertEquals('EUR', $this->client->getCurrency());
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
/** @test */
|
|
|
112 |
public function it_can_set_a_request_header()
|
|
|
113 |
{
|
|
|
114 |
$this->client->setRequestHeader('Prefer', 'return=representation');
|
|
|
115 |
|
|
|
116 |
$this->assertNotEmpty($this->client->getRequestHeader('Prefer'));
|
|
|
117 |
$this->assertEquals($this->client->getRequestHeader('Prefer'), 'return=representation');
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
/** @test */
|
|
|
121 |
public function it_throws_exception_if_options_header_not_set()
|
|
|
122 |
{
|
|
|
123 |
$this->expectException(\RuntimeException::class);
|
|
|
124 |
$this->expectExceptionCode('0');
|
|
|
125 |
$this->expectExceptionMessage('Options header is not set.');
|
|
|
126 |
|
|
|
127 |
$this->client->getRequestHeader('Prefer');
|
|
|
128 |
}
|
|
|
129 |
}
|