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.

ClientTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 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\Connection\ConnectionInterface;
14
use Core23\MatomoBundle\Exception\MatomoException;
15
use PHPUnit\Framework\TestCase;
16
17
final class ClientTest extends TestCase
18
{
19
    private $connection;
20
21
    protected function setUp(): void
22
    {
23
        $this->connection = $this->prophesize(ConnectionInterface::class);
24
    }
25
26
    public function testGetConnection(): void
27
    {
28
        $client = new Client($this->connection->reveal());
29
30
        static::assertSame($this->connection->reveal(), $client->getConnection());
31
    }
32
33
    public function testCall(): void
34
    {
35
        $this->connection->send([
36
            'foo'        => 'bar',
37
            'method'     => 'foo/method',
38
            'token_auth' => 'MY_TOKEN',
39
            'format'     => 'php',
40
        ])
41
        ->willReturn('a:1:{s:6:"result";s:4:"data";}')
42
        ;
43
44
        $client = new Client($this->connection->reveal(), 'MY_TOKEN');
45
        $result = $client->call('foo/method', ['foo' => 'bar']);
46
47
        static::assertSame(['result' => 'data'], $result);
48
    }
49
50
    public function testCallWithCustomFormat(): void
51
    {
52
        $this->connection->send([
53
            'foo'        => 'bar',
54
            'method'     => 'foo/method',
55
            'token_auth' => 'MY_TOKEN',
56
            'format'     => 'custom',
57
        ])
58
        ->willReturn('The result')
59
        ;
60
61
        $client = new Client($this->connection->reveal(), 'MY_TOKEN');
62
        $result = $client->call('foo/method', ['foo' => 'bar'], 'custom');
63
64
        static::assertSame('The result', $result);
65
    }
66
67
    public function testCallWithApiError(): void
68
    {
69
        $this->expectException(MatomoException::class);
70
        $this->expectExceptionMessage('There is an error');
71
72
        $this->connection->send([
73
            'foo'        => 'bar',
74
            'method'     => 'foo/method',
75
            'token_auth' => 'MY_TOKEN',
76
            'format'     => 'php',
77
        ])
78
        ->willReturn('a:2:{s:6:"result";s:5:"error";s:7:"message";s:17:"There is an error";}')
79
        ;
80
81
        $client = new Client($this->connection->reveal(), 'MY_TOKEN');
82
83
        $client->call('foo/method', ['foo' => 'bar']);
84
    }
85
}
86