1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Netgen\Bundle\OpenGraphBundle\Tests\Templating\Twig\Extension; |
4
|
|
|
|
5
|
|
|
use Netgen\Bundle\OpenGraphBundle\MetaTag\Collector; |
6
|
|
|
use Netgen\Bundle\OpenGraphBundle\MetaTag\Item; |
7
|
|
|
use Netgen\Bundle\OpenGraphBundle\MetaTag\Renderer; |
8
|
|
|
use Netgen\Bundle\OpenGraphBundle\Templating\Twig\Extension\NetgenOpenGraphExtension; |
9
|
|
|
use Netgen\Bundle\OpenGraphBundle\Templating\Twig\Extension\NetgenOpenGraphRuntime; |
10
|
|
|
use Psr\Log\NullLogger; |
11
|
|
|
use Twig\RuntimeLoader\FactoryRuntimeLoader; |
12
|
|
|
use Twig\Test\IntegrationTestCase; |
13
|
|
|
|
14
|
|
|
class NetgenOpenGraphExtensionTwigTest extends IntegrationTestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var \Netgen\Bundle\OpenGraphBundle\Templating\Twig\Extension\NetgenOpenGraphExtension |
18
|
|
|
*/ |
19
|
|
|
protected $extension; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var \Netgen\Bundle\OpenGraphBundle\Templating\Twig\Extension\NetgenOpenGraphRuntime |
23
|
|
|
*/ |
24
|
|
|
protected $runtime; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject |
28
|
|
|
*/ |
29
|
|
|
protected $collector; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject |
33
|
|
|
*/ |
34
|
|
|
protected $renderer; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject |
38
|
|
|
*/ |
39
|
|
|
protected $logger; |
40
|
|
|
|
41
|
|
|
public function setUp() |
42
|
|
|
{ |
43
|
|
|
/** @var Item[] $items */ |
44
|
|
|
$items = array( |
45
|
|
|
new Item('tag1', 'some_value'), |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
$this->collector = $this->getMockBuilder(Collector::class) |
49
|
|
|
->disableOriginalConstructor() |
50
|
|
|
->setMethods(array('collect')) |
51
|
|
|
->getMock(); |
52
|
|
|
|
53
|
|
|
$this->collector->method('collect') |
54
|
|
|
->willReturn($items); |
55
|
|
|
|
56
|
|
|
$this->renderer = $this->getMockBuilder(Renderer::class) |
57
|
|
|
->disableOriginalConstructor() |
58
|
|
|
->setMethods(array('render')) |
59
|
|
|
->getMock(); |
60
|
|
|
|
61
|
|
|
$html = ''; |
62
|
|
|
foreach ($items as $item) { |
63
|
|
|
$html .= "<meta property=\"{$item->getTagName()}\" content=\"{$item->getTagValue()}\" />\n"; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$this->renderer->method('render') |
67
|
|
|
->willReturn($html); |
68
|
|
|
|
69
|
|
|
$this->logger = $this->getMockBuilder(NullLogger::class) |
70
|
|
|
->disableOriginalConstructor() |
71
|
|
|
->setMethods(array('error')) |
72
|
|
|
->getMock(); |
73
|
|
|
|
74
|
|
|
$this->extension = new NetgenOpenGraphExtension(); |
75
|
|
|
$this->runtime = new NetgenOpenGraphRuntime($this->collector, $this->renderer, $this->logger); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
|
|
protected function getFixturesDir() |
82
|
|
|
{ |
83
|
|
|
return __DIR__ . '/_fixtures/'; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
protected function getExtensions() |
87
|
|
|
{ |
88
|
|
|
return array($this->extension); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
protected function getRuntimeLoaders() |
92
|
|
|
{ |
93
|
|
|
return array( |
94
|
|
|
new FactoryRuntimeLoader( |
95
|
|
|
array( |
96
|
|
|
NetgenOpenGraphRuntime::class => function () { |
97
|
|
|
return $this->runtime; |
98
|
|
|
}, |
99
|
|
|
) |
100
|
|
|
), |
101
|
|
|
); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
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: