GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( bfb6d8...8dab72 )
by Christian
01:17
created

ClientTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testItIsInstantiable() 0 6 1
A testGetConnection() 0 6 1
A testCall() 0 16 1
A testCallWithCustomFormat() 0 16 1
A testCallWithApiError() 0 18 1
1
<?php
2
3
/*
4
 * (c) Christian Gripp <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Core23\MatomoBundle\Tests\Client;
11
12
use Core23\MatomoBundle\Client\Client;
13
use Core23\MatomoBundle\Client\ClientInterface;
14
use Core23\MatomoBundle\Connection\ConnectionInterface;
15
use Core23\MatomoBundle\Exception\MatomoException;
16
use PHPUnit\Framework\TestCase;
17
18
class ClientTest extends TestCase
19
{
20
    private $connection;
21
22
    protected function setUp()
23
    {
24
        $this->connection = $this->prophesize(ConnectionInterface::class);
25
    }
26
27
    public function testItIsInstantiable(): void
28
    {
29
        $client = new Client($this->connection->reveal());
30
31
        $this->assertInstanceOf(ClientInterface::class, $client);
32
    }
33
34
    public function testGetConnection(): void
35
    {
36
        $client = new Client($this->connection->reveal());
37
38
        $this->assertSame($this->connection->reveal(), $client->getConnection());
39
    }
40
41
    public function testCall(): void
42
    {
43
        $this->connection->send([
44
            'foo'        => 'bar',
45
            'method'     => 'foo/method',
46
            'token_auth' => 'MY_TOKEN',
47
            'format'     => 'php',
48
        ])
49
        ->willReturn('a:1:{s:6:"result";s:4:"data";}')
50
        ;
51
52
        $client = new Client($this->connection->reveal(), 'MY_TOKEN');
53
        $result = $client->call('foo/method', ['foo' => 'bar']);
54
55
        $this->assertSame(['result' => 'data'], $result);
56
    }
57
58
    public function testCallWithCustomFormat(): void
59
    {
60
        $this->connection->send([
61
            'foo'        => 'bar',
62
            'method'     => 'foo/method',
63
            'token_auth' => 'MY_TOKEN',
64
            'format'     => 'custom',
65
        ])
66
        ->willReturn('The result')
67
        ;
68
69
        $client = new Client($this->connection->reveal(), 'MY_TOKEN');
70
        $result = $client->call('foo/method', ['foo' => 'bar'], 'custom');
71
72
        $this->assertSame('The result', $result);
73
    }
74
75
    public function testCallWithApiError(): void
76
    {
77
        $this->expectException(MatomoException::class);
78
        $this->expectExceptionMessage('There is an error');
79
80
        $this->connection->send([
81
            'foo'        => 'bar',
82
            'method'     => 'foo/method',
83
            'token_auth' => 'MY_TOKEN',
84
            'format'     => 'php',
85
        ])
86
        ->willReturn('a:2:{s:6:"result";s:5:"error";s:7:"message";s:17:"There is an error";}')
87
        ;
88
89
        $client = new Client($this->connection->reveal(), 'MY_TOKEN');
90
91
        $client->call('foo/method', ['foo' => 'bar']);
92
    }
93
}
94