Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
676 lars 1
<?php
2
 
3
namespace Srmklive\PayPal\Tests\Unit;
4
 
5
use PHPUnit\Framework\TestCase;
6
use Srmklive\PayPal\Services\PayPal as PayPalClient;
7
use Srmklive\PayPal\Tests\MockClientClasses;
8
use Srmklive\PayPal\Tests\MockResponsePayloads;
9
 
10
class AdapterTest extends TestCase
11
{
12
    use MockClientClasses;
13
    use MockResponsePayloads;
14
 
15
    /** @test */
16
    public function it_can_be_instantiated()
17
    {
18
        $client = new PayPalClient($this->getMockCredentials());
19
 
20
        $this->assertInstanceOf(PayPalClient::class, $client);
21
    }
22
 
23
    /** @test */
24
    public function it_throws_exception_if_invalid_credentials_are_provided()
25
    {
26
        $this->expectException(\RuntimeException::class);
27
 
28
        $client = new PayPalClient();
29
    }
30
 
31
    /** @test */
32
    public function it_throws_exception_if_invalid_mode_is_provided()
33
    {
34
        $this->expectException(\RuntimeException::class);
35
        $this->expectErrorMessage('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.');
36
 
37
        $credentials = $this->getMockCredentials();
38
        $credentials['mode'] = '';
39
 
40
        $client = new PayPalClient($credentials);
41
    }
42
 
43
    /** @test */
44
    public function it_throws_exception_if_empty_credentials_are_provided()
45
    {
46
        $this->expectException(\RuntimeException::class);
47
        $this->expectErrorMessage('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.');
48
 
49
        $credentials = $this->getMockCredentials();
50
        $credentials['sandbox'] = [];
51
 
52
        $client = new PayPalClient($credentials);
53
    }
54
 
55
    /** @test */
56
    public function it_throws_exception_if_credentials_items_are_not_provided()
57
    {
58
        $item = 'client_id';
59
 
60
        $this->expectException(\RuntimeException::class);
61
        $this->expectErrorMessage("{$item} missing from the provided configuration. Please add your application {$item}.");
62
 
63
        $credentials = $this->getMockCredentials();
64
        $credentials['sandbox'][$item] = '';
65
 
66
        $client = new PayPalClient($credentials);
67
    }
68
 
69
    /** @test */
70
    public function it_can_get_access_token()
71
    {
72
        $expectedResponse = $this->mockAccessTokenResponse();
73
 
74
        $expectedMethod = 'getAccessToken';
75
 
76
        $mockClient = $this->mock_client($expectedResponse, $expectedMethod, false);
77
 
78
        $mockClient->setApiCredentials($this->getMockCredentials());
79
 
80
        $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}());
81
    }
82
}