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 ( ca53dd...8486bb )
by Christian
09:58
created

testExecuteOffline()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 40
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 29
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * (c) Christian Gripp <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Core23\MatomoBundle\Tests\Block\Service;
13
14
use Core23\MatomoBundle\Block\Service\MatomoStatisticBlockService;
15
use Core23\MatomoBundle\Client\ClientFactoryInterface;
16
use Core23\MatomoBundle\Client\ClientInterface;
17
use Core23\MatomoBundle\Exception\MatomoException;
18
use Psr\Log\LoggerInterface;
19
use Sonata\BlockBundle\Block\BlockContext;
20
use Sonata\BlockBundle\Model\Block;
21
use Sonata\BlockBundle\Model\BlockInterface;
22
use Sonata\BlockBundle\Test\AbstractBlockServiceTestCase;
23
24
final class MatomoStatisticBlockServiceTest extends AbstractBlockServiceTestCase
25
{
26
    private $logger;
27
28
    private $factory;
29
30
    protected function setUp(): void
31
    {
32
        parent::setUp();
33
34
        $this->logger  = $this->createMock(LoggerInterface::class);
35
        $this->factory = $this->createMock(ClientFactoryInterface::class);
36
    }
37
38
    public function testExecute(): void
39
    {
40
        $client = $this->createMock(ClientInterface::class);
41
        $client->expects($this->once())->method('call')
42
            ->with($this->equalTo('VisitsSummary.getVisits'), $this->equalTo([
43
                'idSite' => 'foo',
44
                'period' => 'day',
45
                'date'   => 'last30',
46
            ]))
47
            ->will($this->returnValue(['bar']));
48
49
        $this->factory->expects($this->once())->method('createClient')
50
            ->will($this->returnValue($client));
51
52
        $block = new Block();
53
54
        $blockContext = new BlockContext($block, [
55
            'title'    => null,
56
            'site'     => 'foo',
57
            'method'   => 'VisitsSummary.getVisits',
58
            'host'     => 'localhost',
59
            'token'    => '0815',
60
            'period'   => 'day',
61
            'date'     => 'last30',
62
            'template' => '@Core23Matomo/Block/block_matomo_statistic.html.twig',
63
        ]);
64
65
        $blockService = new MatomoStatisticBlockService('block.service', $this->templating, $this->factory);
0 ignored issues
show
Documentation introduced by
$this->factory is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Core23\MatomoBund...ClientFactoryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
66
        $blockService->execute($blockContext);
67
68
        $this->assertSame('@Core23Matomo/Block/block_matomo_statistic.html.twig', $this->templating->view);
69
70
        $this->assertSame($blockContext, $this->templating->parameters['context']);
71
        $this->assertInternalType('array', $this->templating->parameters['settings']);
72
        $this->assertInstanceOf(BlockInterface::class, $this->templating->parameters['block']);
73
        $this->assertSame(['bar'], $this->templating->parameters['data']);
74
    }
75
76
    public function testExecuteOffline(): void
77
    {
78
        $client = $this->createMock(ClientInterface::class);
79
        $client->expects($this->once())->method('call')
80
            ->with($this->equalTo('VisitsSummary.getVisits'), $this->equalTo([
81
                'idSite' => 'foo',
82
                'period' => 'day',
83
                'date'   => 'last30',
84
            ]))
85
            ->willThrowException(new MatomoException('Offline'));
86
87
        $this->factory->expects($this->once())->method('createClient')
88
            ->will($this->returnValue($client));
89
90
        $this->logger->expects($this->once())->method('warning');
91
92
        $block = new Block();
93
94
        $blockContext = new BlockContext($block, [
95
            'title'    => null,
96
            'site'     => 'foo',
97
            'method'   => 'VisitsSummary.getVisits',
98
            'host'     => 'localhost',
99
            'token'    => '0815',
100
            'period'   => 'day',
101
            'date'     => 'last30',
102
            'template' => '@Core23Matomo/Block/block_matomo_statistic.html.twig',
103
        ]);
104
105
        $blockService = new MatomoStatisticBlockService('block.service', $this->templating, $this->factory);
0 ignored issues
show
Documentation introduced by
$this->factory is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Core23\MatomoBund...ClientFactoryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
106
        $blockService->setLogger($this->logger);
0 ignored issues
show
Documentation introduced by
$this->logger is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Log\LoggerInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
107
        $blockService->execute($blockContext);
108
109
        $this->assertSame('@Core23Matomo/Block/block_matomo_statistic.html.twig', $this->templating->view);
110
111
        $this->assertSame($blockContext, $this->templating->parameters['context']);
112
        $this->assertInternalType('array', $this->templating->parameters['settings']);
113
        $this->assertInstanceOf(BlockInterface::class, $this->templating->parameters['block']);
114
        $this->assertNull($this->templating->parameters['data']);
115
    }
116
117
    public function testDefaultSettings(): void
118
    {
119
        $blockService = new MatomoStatisticBlockService('block.service', $this->templating, $this->factory);
0 ignored issues
show
Documentation introduced by
$this->factory is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Core23\MatomoBund...ClientFactoryInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
120
        $blockService->setLogger($this->logger);
0 ignored issues
show
Documentation introduced by
$this->logger is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Log\LoggerInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
121
        $blockContext = $this->getBlockContext($blockService);
122
123
        $this->assertSettings([
124
            'title'              => null,
125
            'translation_domain' => null,
126
            'icon'               => 'fa fa-bar-chart-o',
127
            'class'              => null,
128
            'site'               => null,
129
            'method'             => 'VisitsSummary.getVisits',
130
            'host'               => null,
131
            'token'              => null,
132
            'period'             => 'day',
133
            'date'               => 'last30',
134
            'template'           => '@Core23Matomo/Block/block_matomo_statistic.html.twig',
135
        ], $blockContext);
136
    }
137
}
138