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.

MatomoTwigExtensionTest::testGetFunctions()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 2
nc 2
nop 0
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\Twig\Extension;
11
12
use Core23\MatomoBundle\Twig\Extension\MatomoTwigExtension;
13
use PHPUnit\Framework\TestCase;
14
use Prophecy\Argument;
15
use Twig\Environment;
16
use Twig\TwigFunction;
17
18
final class MatomoTwigExtensionTest extends TestCase
19
{
20
    private $environment;
21
22
    protected function setUp(): void
23
    {
24
        $this->environment = $this->prophesize(Environment::class);
25
    }
26
27
    public function testGetFunctions(): void
28
    {
29
        $extension = new MatomoTwigExtension($this->environment->reveal());
30
31
        $functions = $extension->getFunctions();
32
33
        static::assertCount(1, $functions);
0 ignored issues
show
Documentation introduced by
$functions is of type array<integer,object<Twig\TwigFunction>>, but the function expects a object<Countable>|object...nit\Framework\iterable>.

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...
34
35
        foreach ($functions as $function) {
36
            static::assertInstanceOf(TwigFunction::class, $function);
37
            static::assertIsCallable($function->getCallable());
38
        }
39
    }
40
41
    public function testRenderTracker(): void
42
    {
43
        $this->environment->render('@Core23Matomo/tracker_code.html.twig', [
44
            'site_id'       => 13,
45
            'matomo_host'   => 'localhost',
46
            'cookie_domain' => null,
47
        ])
48
            ->willReturn('HTML CONTENT')
49
        ;
50
51
        $extension = new MatomoTwigExtension($this->environment->reveal());
52
53
        static::assertSame('HTML CONTENT', $extension->renderTracker([
54
            'site_id' => 13,
55
        ]));
56
    }
57
58
    public function testRenderTrackerWithoutSiteId(): void
59
    {
60
        $extension = new MatomoTwigExtension($this->environment->reveal());
61
62
        $this->environment->render(Argument::any())
63
            ->shouldNotBeCalled()
64
        ;
65
66
        static::assertSame('', $extension->renderTracker());
67
    }
68
}
69