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 ( 0b86be...b9c831 )
by Christian
01:14
created

testBuildEditForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
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\AdminBundle\Form\FormMapper;
20
use Sonata\BlockBundle\Block\BlockContext;
21
use Sonata\BlockBundle\Model\Block;
22
use Sonata\BlockBundle\Model\BlockInterface;
23
use Sonata\BlockBundle\Test\AbstractBlockServiceTestCase;
24
25
final class MatomoStatisticBlockServiceTest extends AbstractBlockServiceTestCase
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($this->once())->method('call')
43
            ->with($this->equalTo('VisitsSummary.getVisits'), $this->equalTo([
44
                'idSite' => 'foo',
45
                'period' => 'day',
46
                'date'   => 'last30',
47
            ]))
48
            ->willReturn(['bar'])
49
        ;
50
51
        $this->factory->expects($this->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('block.service', $this->templating, $this->factory);
69
        $blockService->execute($blockContext);
70
71
        $this->assertSame('@Core23Matomo/Block/block_matomo_statistic.html.twig', $this->templating->view);
72
73
        $this->assertSame($blockContext, $this->templating->parameters['context']);
74
        $this->assertInternalType('array', $this->templating->parameters['settings']);
75
        $this->assertInstanceOf(BlockInterface::class, $this->templating->parameters['block']);
76
        $this->assertSame(['bar'], $this->templating->parameters['data']);
77
    }
78
79
    public function testExecuteOffline(): void
80
    {
81
        $client = $this->createMock(ClientInterface::class);
82
        $client->expects($this->once())->method('call')
83
            ->with($this->equalTo('VisitsSummary.getVisits'), $this->equalTo([
84
                'idSite' => 'foo',
85
                'period' => 'day',
86
                'date'   => 'last30',
87
            ]))
88
            ->willThrowException(new MatomoException('Offline'))
89
        ;
90
91
        $this->factory->expects($this->once())->method('createClient')
92
            ->willReturn($client)
93
        ;
94
95
        $this->logger->expects($this->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('block.service', $this->templating, $this->factory);
111
        $blockService->setLogger($this->logger);
112
        $blockService->execute($blockContext);
113
114
        $this->assertSame('@Core23Matomo/Block/block_matomo_statistic.html.twig', $this->templating->view);
115
116
        $this->assertSame($blockContext, $this->templating->parameters['context']);
117
        $this->assertInternalType('array', $this->templating->parameters['settings']);
118
        $this->assertInstanceOf(BlockInterface::class, $this->templating->parameters['block']);
119
        $this->assertNull($this->templating->parameters['data']);
120
    }
121
122
    public function testDefaultSettings(): void
123
    {
124
        $blockService = new MatomoStatisticBlockService('block.service', $this->templating, $this->factory);
125
        $blockService->setLogger($this->logger);
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 testBuildEditForm(): void
144
    {
145
        $blockService = new MatomoStatisticBlockService('block.service', $this->templating, $this->factory);
146
147
        $block = new Block();
148
149
        $formMapper = $this->createMock(FormMapper::class);
150
        $formMapper->expects($this->once())->method('add');
151
152
        $blockService->buildEditForm($formMapper, $block);
153
    }
154
}
155