Completed
Push — master ( 49f631...00219d )
by Frank
03:48
created

ClientTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 65
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getClientWithoutEndpointThrowsException() 0 5 1
A getClientWithoutCredentialsThrowsException() 0 5 1
A invalidEndpointDataProvider() 0 16 1
A withEndpointThrowsExceptionForInvalidValues() 0 8 2
A getClientReturnClient() 0 8 1
1
<?php
2
declare(strict_types=1);
3
4
/*
5
 * This file is part of the package neoblack/free-at-home-api.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE file that was distributed with this source code.
9
 */
10
11
namespace NeoBlack\FreeAtHomeApi\Test\Unit\Service;
12
13
use NeoBlack\FreeAtHomeApi\Client;
14
use NeoBlack\FreeAtHomeApi\Exception\InvalidEndpointException;
15
use NeoBlack\FreeAtHomeApi\Exception\MissingCredentialsException;
16
use NeoBlack\FreeAtHomeApi\Exception\MissingEndpointException;
17
use PHPUnit\Framework\TestCase;
18
19
class ClientTest extends TestCase
20
{
21
    /**
22
     * @test
23
     */
24
    public function getClientWithoutEndpointThrowsException(): void
25
    {
26
        $this->expectException(MissingEndpointException::class);
27
        (new Client())->getClient();
28
    }
29
30
    /**
31
     * @test
32
     */
33
    public function getClientWithoutCredentialsThrowsException(): void
34
    {
35
        $this->expectException(MissingCredentialsException::class);
36
        (new Client())->withEndpoint('https://localhost')->getClient();
37
    }
38
39
    /**
40
     * @return array
41
     */
42
    public function invalidEndpointDataProvider(): array
43
    {
44
        return [
45
            '/' => ['/', false],
46
            '/foo' => ['/foo', false],
47
            'foo' => ['foo', false],
48
            'http://localhost' => ['http://localhost', true],
49
            'https://localhost' => ['https://localhost', true],
50
            'http://localhost.foo' => ['http://localhost.foo', true],
51
            'https://localhost.foo' => ['https://localhost.foo', true],
52
            'http://localhost.foo/foo/bar' => ['http://localhost.foo/foo/bar', true],
53
            'https://localhost.foo/foo/bar' => ['https://localhost.foo/foo/bar', true],
54
            'http://localhost.foo:8888/foo/bar' => ['http://localhost.foo:8888/foo/bar', true],
55
            'https://localhost.foo:8888/foo/bar' => ['https://localhost.foo:8888/foo/bar', true],
56
        ];
57
    }
58
59
    /**
60
     * @test
61
     * @dataProvider invalidEndpointDataProvider
62
     */
63
    public function withEndpointThrowsExceptionForInvalidValues(string $endpoint, $isValid): void
64
    {
65
        if (!$isValid) {
66
            $this->expectException(InvalidEndpointException::class);
67
        }
68
        /** @noinspection UnnecessaryAssertionInspection */
69
        $this->assertInstanceOf(Client::class, (new Client())->withEndpoint($endpoint));
70
    }
71
72
    /**
73
     * @test
74
     */
75
    public function getClientReturnClient(): void
76
    {
77
        /** @noinspection UnnecessaryAssertionInspection */
78
        $this->assertInstanceOf(Client::class, (new Client())
79
            ->withEndpoint('https://localhost')
80
            ->withCredentials('foo', 'bar')
81
            ->getClient());
82
    }
83
}
84