|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\Bundle\DoctrineBundle\Tests; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use Doctrine\Bundle\DoctrineBundle\DataCollector\DoctrineDataCollector; |
|
7
|
|
|
use Doctrine\Bundle\DoctrineBundle\Twig\DoctrineExtension; |
|
8
|
|
|
use Doctrine\Common\Persistence\ManagerRegistry; |
|
9
|
|
|
use Doctrine\DBAL\Logging\DebugStack; |
|
10
|
|
|
use PHPUnit\Framework\TestCase as BaseTestCase; |
|
11
|
|
|
use Symfony\Bridge\Twig\Extension\CodeExtension; |
|
12
|
|
|
use Symfony\Bridge\Twig\Extension\HttpKernelExtension; |
|
13
|
|
|
use Symfony\Bridge\Twig\Extension\HttpKernelRuntime; |
|
14
|
|
|
use Symfony\Bridge\Twig\Extension\RoutingExtension; |
|
15
|
|
|
use Symfony\Bundle\WebProfilerBundle\Twig\WebProfilerExtension; |
|
16
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
18
|
|
|
use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector; |
|
19
|
|
|
use Symfony\Component\HttpKernel\Fragment\FragmentHandler; |
|
20
|
|
|
use Symfony\Component\HttpKernel\Profiler\Profile; |
|
21
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
|
22
|
|
|
|
|
23
|
|
|
class ProfilerTest extends BaseTestCase |
|
24
|
|
|
{ |
|
25
|
|
|
/** @var DebugStack */ |
|
26
|
|
|
private $logger; |
|
27
|
|
|
/** @var \Twig_Environment */ |
|
28
|
|
|
private $twig; |
|
29
|
|
|
/** @var DoctrineDataCollector */ |
|
30
|
|
|
private $collector; |
|
31
|
|
|
|
|
32
|
|
|
public function setUp() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->logger = new DebugStack(); |
|
35
|
|
|
$registry = $this->getMockBuilder(ManagerRegistry::class)->getMock(); |
|
36
|
|
|
$registry->expects($this->once())->method('getManagers')->willReturn([]); |
|
37
|
|
|
$this->collector = new DoctrineDataCollector($registry); |
|
|
|
|
|
|
38
|
|
|
$this->collector->addLogger('foo', $this->logger); |
|
39
|
|
|
|
|
40
|
|
|
$twigLoaderFilesystem = new \Twig_Loader_Filesystem(__DIR__.'/../Resources/views/Collector'); |
|
41
|
|
|
$twigLoaderFilesystem->addPath(__DIR__.'/../vendor/symfony/web-profiler-bundle/Resources/views', 'WebProfiler'); |
|
42
|
|
|
$this->twig = new \Twig_Environment($twigLoaderFilesystem, ['debug' => true, 'strict_variables' => true]); |
|
43
|
|
|
|
|
44
|
|
|
$this->twig->addExtension(new CodeExtension('', '', '')); |
|
45
|
|
|
$this->twig->addExtension(new RoutingExtension($this->getMockBuilder(UrlGeneratorInterface::class)->getMock())); |
|
|
|
|
|
|
46
|
|
|
$this->twig->addExtension(new HttpKernelExtension($this->getMockBuilder(FragmentHandler::class)->disableOriginalConstructor()->getMock())); |
|
|
|
|
|
|
47
|
|
|
$this->twig->addExtension(new WebProfilerExtension()); |
|
48
|
|
|
$this->twig->addExtension(new DoctrineExtension()); |
|
49
|
|
|
|
|
50
|
|
|
$loader = $this->getMockBuilder(\Twig_RuntimeLoaderInterface::class)->getMock(); |
|
51
|
|
|
$loader->method('load')->willReturn($this->getMockBuilder(HttpKernelRuntime::class)->disableOriginalConstructor()->getMock()); |
|
52
|
|
|
$this->twig->addRuntimeLoader($loader); |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testRender() |
|
56
|
|
|
{ |
|
57
|
|
|
$this->logger->queries = [ |
|
58
|
|
|
[ |
|
59
|
|
|
'sql' => 'SELECT * FROM foo WHERE bar IN (?, ?)', |
|
60
|
|
|
'params' => ['foo', 'bar'], |
|
61
|
|
|
'executionMS' => 1, |
|
62
|
|
|
], |
|
63
|
|
|
]; |
|
64
|
|
|
|
|
65
|
|
|
$this->collector->collect($request = new Request(['group' => '0']), $response = new Response()); |
|
66
|
|
|
|
|
67
|
|
|
$profile = new Profile('foo'); |
|
68
|
|
|
|
|
69
|
|
|
// This is only needed for WebProfilerBundle=3.2, remove when support for it is dropped |
|
70
|
|
|
$requestCollector = new RequestDataCollector(); |
|
71
|
|
|
$requestCollector->collect($request, $response); |
|
72
|
|
|
$profile->addCollector($requestCollector); |
|
73
|
|
|
|
|
74
|
|
|
$output = $this->twig->render('db.html.twig', [ |
|
75
|
|
|
'request' => $request, |
|
76
|
|
|
'token' => 'foo', |
|
77
|
|
|
'page' => 'foo', |
|
78
|
|
|
'profile' => $profile, |
|
79
|
|
|
'collector' => $this->collector, |
|
80
|
|
|
'queries' => $this->logger->queries, |
|
81
|
|
|
]); |
|
82
|
|
|
|
|
83
|
|
|
$output = str_replace(["\e[37m", "\e[0m", "\e[32;1m", "\e[34;1m"], "", $output); |
|
84
|
|
|
$this->assertContains("SELECT * FROM foo WHERE bar IN ('foo', 'bar');", $output); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
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: