Completed
Push — master ( b736eb...f06be5 )
by Laurens
03:50 queued 01:55
created

AbstractClientTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 7
dl 0
loc 52
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setOrganizationUuid() 0 11 1
A validateAccessToken() 0 6 1
A getGuzzleClient() 0 15 1
A getAccessToken() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\IzettleApi\Tests\Unit;
6
7
use DateTime;
8
use GuzzleHttp\Client as GuzzleClient;
9
use LauLamanApps\IzettleApi\AbstractClient;
10
use LauLamanApps\IzettleApi\Client\AccessToken;
11
use Mockery;
12
use PHPUnit\Framework\TestCase;
13
use Psr\Http\Message\ResponseInterface;
14
use Ramsey\Uuid\Uuid;
15
16
class TestClassForAbstractClient extends AbstractClient
17
{
18
}
19
20
abstract class AbstractClientTest extends TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
21
{
22
    const ACCESS_TOKEN = 'access-token';
23
    const DEFAULT_ORGANIZATION_UUID = 'self';
24
25
    /**
26
     * @test
27
     */
28
    public function setOrganizationUuid()
29
    {
30
        $newOrganizationUuid = Uuid::uuid1();
31
        $abstractClient = new TestClassForAbstractClient(new GuzzleClient(), $this->getAccessToken());
32
33
        self::assertAttributeEquals(self::DEFAULT_ORGANIZATION_UUID, 'organizationUuid', $abstractClient);
34
35
        $abstractClient->setOrganizationUuid($newOrganizationUuid);
36
37
        self::assertAttributeEquals((string) $newOrganizationUuid, 'organizationUuid', $abstractClient);
38
    }
39
40
    /**
41
     * @test
42
     * @expectedException \LauLamanApps\IzettleApi\Client\Exceptions\AccessTokenExpiredException
43
     */
44
    public function validateAccessToken()
45
    {
46
        $invalidAccessToken =  new AccessToken('', new DateTime('-1 day'), '');
47
48
        new TestClassForAbstractClient(new GuzzleClient(), $invalidAccessToken);
49
    }
50
51
    protected function getGuzzleClient(
52
        string $method,
53
        string $url,
54
        array $options,
55
        ?array $return = []
56
    ): GuzzleClient {
57
        $guzzleResponseMock = Mockery::mock(ResponseInterface::class);
58
        $guzzleResponseMock->shouldReceive('getBody')->andReturnSelf();
59
        $guzzleResponseMock->shouldReceive('getContents')->andReturn(json_encode($return));
60
61
        $guzzleClientMock = Mockery::mock(GuzzleClient::class);
62
        $guzzleClientMock->shouldReceive($method)->withArgs([$url, $options])->andReturn($guzzleResponseMock);
63
64
        return $guzzleClientMock;
65
    }
66
67
    protected function getAccessToken() : AccessToken
68
    {
69
        return new AccessToken(self::ACCESS_TOKEN, new DateTime('+ 1 day'), '');
70
    }
71
}
72