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); |
|
|
|
|
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
|
|
|
|
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: