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.

MatomoStatisticBlockServiceTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 144
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testExecute() 0 39 1
A testExecuteOffline() 0 42 1
A testDefaultSettings() 0 20 1
A testGetMetadata() 0 13 1
A testConfigureEditForm() 0 11 1
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\Form\Mapper\FormMapper;
21
use Sonata\BlockBundle\Model\Block;
22
use Sonata\BlockBundle\Model\BlockInterface;
23
use Sonata\BlockBundle\Test\BlockServiceTestCase;
24
25
final class MatomoStatisticBlockServiceTest extends BlockServiceTestCase
26
{
27
    private $logger;
28
29
    private $factory;
30
31
    protected function setUp(): void
32
    {
33
        parent::setUp();
34
35
        $this->logger  = $this->createMock(LoggerInterface::class);
36
        $this->factory = $this->createMock(ClientFactoryInterface::class);
37
    }
38
39
    public function testExecute(): void
40
    {
41
        $client = $this->createMock(ClientInterface::class);
42
        $client->expects(static::once())->method('call')
43
            ->with(static::equalTo('VisitsSummary.getVisits'), static::equalTo([
44
                'idSite' => 'foo',
45
                'period' => 'day',
46
                'date'   => 'last30',
47
            ]))
48
            ->willReturn(['bar'])
49
        ;
50
51
        $this->factory->expects(static::once())->method('createClient')
52
            ->willReturn($client)
53
        ;
54
55
        $block = new Block();
56
57
        $blockContext = new BlockContext($block, [
58
            'title'    => null,
59
            'site'     => 'foo',
60
            'method'   => 'VisitsSummary.getVisits',
61
            'host'     => 'localhost',
62
            'token'    => '0815',
63
            'period'   => 'day',
64
            'date'     => 'last30',
65
            'template' => '@Core23Matomo/Block/block_matomo_statistic.html.twig',
66
        ]);
67
68
        $blockService = new MatomoStatisticBlockService($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...
69
        $blockService->execute($blockContext);
70
71
        static::assertSame('@Core23Matomo/Block/block_matomo_statistic.html.twig', $this->templating->view);
72
73
        static::assertSame($blockContext, $this->templating->parameters['context']);
74
        static::assertIsArray($this->templating->parameters['settings']);
75
        static::assertInstanceOf(BlockInterface::class, $this->templating->parameters['block']);
76
        static::assertSame(['bar'], $this->templating->parameters['data']);
77
    }
78
79
    public function testExecuteOffline(): void
80
    {
81
        $client = $this->createMock(ClientInterface::class);
82
        $client->expects(static::once())->method('call')
83
            ->with(static::equalTo('VisitsSummary.getVisits'), static::equalTo([
84
                'idSite' => 'foo',
85
                'period' => 'day',
86
                'date'   => 'last30',
87
            ]))
88
            ->willThrowException(new MatomoException('Offline'))
89
        ;
90
91
        $this->factory->expects(static::once())->method('createClient')
92
            ->willReturn($client)
93
        ;
94
95
        $this->logger->expects(static::once())->method('warning');
96
97
        $block = new Block();
98
99
        $blockContext = new BlockContext($block, [
100
            'title'    => null,
101
            'site'     => 'foo',
102
            'method'   => 'VisitsSummary.getVisits',
103
            'host'     => 'localhost',
104
            'token'    => '0815',
105
            'period'   => 'day',
106
            'date'     => 'last30',
107
            'template' => '@Core23Matomo/Block/block_matomo_statistic.html.twig',
108
        ]);
109
110
        $blockService = new MatomoStatisticBlockService($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...
111
        $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...
112
        $blockService->execute($blockContext);
113
114
        static::assertSame('@Core23Matomo/Block/block_matomo_statistic.html.twig', $this->templating->view);
115
116
        static::assertSame($blockContext, $this->templating->parameters['context']);
117
        static::assertIsArray($this->templating->parameters['settings']);
118
        static::assertInstanceOf(BlockInterface::class, $this->templating->parameters['block']);
119
        static::assertNull($this->templating->parameters['data']);
120
    }
121
122
    public function testDefaultSettings(): void
123
    {
124
        $blockService = new MatomoStatisticBlockService($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...
125
        $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...
126
        $blockContext = $this->getBlockContext($blockService);
127
128
        $this->assertSettings([
129
            'title'              => null,
130
            'translation_domain' => null,
131
            'icon'               => 'fa fa-bar-chart-o',
132
            'class'              => null,
133
            'site'               => null,
134
            'method'             => 'VisitsSummary.getVisits',
135
            'host'               => null,
136
            'token'              => null,
137
            'period'             => 'day',
138
            'date'               => 'last30',
139
            'template'           => '@Core23Matomo/Block/block_matomo_statistic.html.twig',
140
        ], $blockContext);
141
    }
142
143
    public function testGetMetadata(): void
144
    {
145
        $blockService = new MatomoStatisticBlockService($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...
146
147
        $metadata = $blockService->getMetadata();
148
149
        static::assertSame('core23_matomo.block.statistic', $metadata->getTitle());
150
        static::assertNull($metadata->getImage());
151
        static::assertSame('Core23MatomoBundle', $metadata->getDomain());
152
        static::assertSame([
153
            'class' => 'fa fa-area-chart',
154
        ], $metadata->getOptions());
155
    }
156
157
    public function testConfigureEditForm(): void
158
    {
159
        $blockService = new MatomoStatisticBlockService($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...
160
161
        $block = new Block();
162
163
        $formMapper = $this->createMock(FormMapper::class);
164
        $formMapper->expects(static::once())->method('add');
165
166
        $blockService->configureEditForm($formMapper, $block);
0 ignored issues
show
Documentation introduced by
$formMapper is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Sonata\BlockBundle\Form\Mapper\FormMapper>.

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...
167
    }
168
}
169