-
-
Notifications
You must be signed in to change notification settings - Fork 454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #730 compatibility with web profiler 4 #735
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6c8a34d
Fix #730 compatibility with web profiler 4
ostrolucky f5821f1
Fix broken phpunit 4
ostrolucky dcfd560
add test
ostrolucky eec3981
Full Symfony 4 compatibility (according to tests) 🎉
ostrolucky 370aaa1
Test SF 3.2 + 2.8, PHP 7.2
ostrolucky 0fa5dd3
More effective clonevar compatibility layer, test SF 3.4
ostrolucky b1e881a
Formatting changes, introduce stability env flag in travis matrix
ostrolucky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
namespace Doctrine\Bundle\DoctrineBundle\Tests; | ||
|
||
|
||
use Doctrine\Bundle\DoctrineBundle\DataCollector\DoctrineDataCollector; | ||
use Doctrine\Bundle\DoctrineBundle\Twig\DoctrineExtension; | ||
use Doctrine\Common\Persistence\ManagerRegistry; | ||
use Doctrine\DBAL\Logging\DebugStack; | ||
use PHPUnit\Framework\TestCase as BaseTestCase; | ||
use Symfony\Bridge\Twig\Extension\CodeExtension; | ||
use Symfony\Bridge\Twig\Extension\HttpKernelExtension; | ||
use Symfony\Bridge\Twig\Extension\HttpKernelRuntime; | ||
use Symfony\Bridge\Twig\Extension\RoutingExtension; | ||
use Symfony\Bundle\WebProfilerBundle\Twig\WebProfilerExtension; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector; | ||
use Symfony\Component\HttpKernel\Fragment\FragmentHandler; | ||
use Symfony\Component\HttpKernel\Profiler\Profile; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
|
||
class ProfilerTest extends BaseTestCase | ||
{ | ||
/** @var DebugStack */ | ||
private $logger; | ||
/** @var \Twig_Environment */ | ||
private $twig; | ||
/** @var DoctrineDataCollector */ | ||
private $collector; | ||
|
||
public function setUp() | ||
{ | ||
$this->logger = new DebugStack(); | ||
$registry = $this->getMockBuilder(ManagerRegistry::class)->getMock(); | ||
$registry->expects($this->once())->method('getManagers')->willReturn([]); | ||
$this->collector = new DoctrineDataCollector($registry); | ||
$this->collector->addLogger('foo', $this->logger); | ||
|
||
$twigLoaderFilesystem = new \Twig_Loader_Filesystem(__DIR__.'/../Resources/views/Collector'); | ||
$twigLoaderFilesystem->addPath(__DIR__.'/../vendor/symfony/web-profiler-bundle/Resources/views', 'WebProfiler'); | ||
$this->twig = new \Twig_Environment($twigLoaderFilesystem, ['debug' => true, 'strict_variables' => true]); | ||
|
||
$this->twig->addExtension(new CodeExtension('', '', '')); | ||
$this->twig->addExtension(new RoutingExtension($this->getMockBuilder(UrlGeneratorInterface::class)->getMock())); | ||
$this->twig->addExtension(new HttpKernelExtension($this->getMockBuilder(FragmentHandler::class)->disableOriginalConstructor()->getMock())); | ||
$this->twig->addExtension(new WebProfilerExtension()); | ||
$this->twig->addExtension(new DoctrineExtension()); | ||
|
||
$loader = $this->getMockBuilder(\Twig_RuntimeLoaderInterface::class)->getMock(); | ||
$loader->method('load')->willReturn($this->getMockBuilder(HttpKernelRuntime::class)->disableOriginalConstructor()->getMock()); | ||
$this->twig->addRuntimeLoader($loader); | ||
} | ||
|
||
public function testRender() | ||
{ | ||
$this->logger->queries = [ | ||
[ | ||
'sql' => 'SELECT * FROM foo WHERE bar IN (?, ?)', | ||
'params' => ['foo', 'bar'], | ||
'executionMS' => 1, | ||
], | ||
]; | ||
|
||
$this->collector->collect($request = new Request(['group' => '0']), $response = new Response()); | ||
|
||
$profile = new Profile('foo'); | ||
|
||
// This is only needed for WebProfilerBundle=3.2, remove when support for it is dropped | ||
$requestCollector = new RequestDataCollector(); | ||
$requestCollector->collect($request, $response); | ||
$profile->addCollector($requestCollector); | ||
|
||
$output = $this->twig->render('db.html.twig', [ | ||
'request' => $request, | ||
'token' => 'foo', | ||
'page' => 'foo', | ||
'profile' => $profile, | ||
'collector' => $this->collector, | ||
'queries' => $this->logger->queries, | ||
]); | ||
|
||
$output = str_replace(["\e[37m", "\e[0m", "\e[32;1m", "\e[34;1m"], "", $output); | ||
$this->assertContains("SELECT * FROM foo WHERE bar IN ('foo', 'bar');", $output); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be better to use a ServiceLocator (by changing the lazy-loading listener resolver) rather than forcing to use public services
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what do you mean, although I don't want to change behaviour. Tests expect this service to be public, meaning having it directly accessible from container. Making it otherwise would be BC break. I have done this change only to fix tests. I think it was concretely this one
DoctrineBundle/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php
Line 911 in eec3981