Skip to content

Commit

Permalink
fix Doctrine deprecations (#1667)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmaicher authored and ostrolucky committed Jun 4, 2023
1 parent e6da248 commit c09bfc3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
1 change: 1 addition & 0 deletions DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@ protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $
->setArguments([
new Reference(sprintf('doctrine.dbal.%s_connection', $entityManager['connection'])),
new Reference(sprintf('doctrine.orm.%s_configuration', $entityManager['name'])),
new Reference(sprintf('doctrine.dbal.%s_connection.event_manager', $entityManager['connection'])),
])
->setConfigurator([new Reference($managerConfiguratorName), 'configure']);

Expand Down
1 change: 1 addition & 0 deletions Tests/Dbal/Logging/BacktraceLoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use function current;

/** @group legacy */
class BacktraceLoggerTest extends TestCase
{
public function testBacktraceLogged(): void
Expand Down
5 changes: 3 additions & 2 deletions Tests/DependencyInjection/AbstractDoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ public function testLoadSimpleSingleConnection(): void
$this->assertDICConstructorArguments($definition, [
new Reference('doctrine.dbal.default_connection'),
new Reference('doctrine.orm.default_configuration'),
new Reference('doctrine.dbal.default_connection.event_manager'),
]);
}

Expand Down Expand Up @@ -334,6 +335,7 @@ public function testLoadSimpleSingleConnectionWithoutDbName(): void
$this->assertDICConstructorArguments($definition, [
new Reference('doctrine.dbal.default_connection'),
new Reference('doctrine.orm.default_configuration'),
new Reference('doctrine.dbal.default_connection.event_manager'),
]);
}

Expand Down Expand Up @@ -370,6 +372,7 @@ public function testLoadSingleConnection(): void
$this->assertDICConstructorArguments($definition, [
new Reference('doctrine.dbal.default_connection'),
new Reference('doctrine.orm.default_configuration'),
new Reference('doctrine.dbal.default_connection.event_manager'),
]);

$configDef = $container->getDefinition('doctrine.orm.default_configuration');
Expand Down Expand Up @@ -1424,8 +1427,6 @@ private function assertDICDefinitionMethodCallAt(
$calls = $definition->getMethodCalls();
if (! isset($calls[$pos][0])) {
$this->fail(sprintf('Method call at position %s not found!', $pos));

return;
}

$this->assertEquals($methodName, $calls[$pos][0], "Method '" . $methodName . "' is expected to be called at position " . $pos . '.');
Expand Down
3 changes: 3 additions & 0 deletions Tests/DependencyInjection/DoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ public function testSingleEntityManagerWithDefaultConfiguration(): void
$this->assertDICConstructorArguments($definition, [
new Reference('doctrine.dbal.default_connection'),
new Reference('doctrine.orm.default_configuration'),
new Reference('doctrine.dbal.default_connection.event_manager'),
]);
}

Expand Down Expand Up @@ -645,6 +646,7 @@ public function testSingleEntityManagerWithDefaultSecondLevelCacheConfiguration(
$this->assertDICConstructorArguments($definition, [
new Reference('doctrine.dbal.default_connection'),
new Reference('doctrine.orm.default_configuration'),
new Reference('doctrine.dbal.default_connection.event_manager'),
]);

$slcDefinition = $container->getDefinition('doctrine.orm.default_second_level_cache.default_cache_factory');
Expand Down Expand Up @@ -680,6 +682,7 @@ public function testSingleEntityManagerWithCustomSecondLevelCacheConfiguration()
$this->assertDICConstructorArguments($definition, [
new Reference('doctrine.dbal.default_connection'),
new Reference('doctrine.orm.default_configuration'),
new Reference('doctrine.dbal.default_connection.event_manager'),
]);

$slcDefinition = $container->getDefinition('doctrine.orm.default_second_level_cache.default_cache_factory');
Expand Down
27 changes: 12 additions & 15 deletions Tests/ProfilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

use Doctrine\Bundle\DoctrineBundle\DataCollector\DoctrineDataCollector;
use Doctrine\Bundle\DoctrineBundle\Twig\DoctrineExtension;
use Doctrine\DBAL\Logging\DebugStack;
use Doctrine\Persistence\ManagerRegistry;
use PHPUnit\Framework\TestCase as BaseTestCase;
use Symfony\Bridge\Doctrine\Middleware\Debug\DebugDataHolder;
use Symfony\Bridge\Doctrine\Middleware\Debug\Query;
use Symfony\Bridge\Twig\Extension\CodeExtension;
use Symfony\Bridge\Twig\Extension\HttpKernelExtension;
use Symfony\Bridge\Twig\Extension\HttpKernelRuntime;
Expand All @@ -28,21 +29,24 @@
use function preg_quote;
use function str_replace;

/**
* @psalm-suppress InternalMethod
* @psalm-suppress InternalClass
*/
class ProfilerTest extends BaseTestCase
{
private DebugStack $logger;
private DebugDataHolder $debugDataHolder;
private Environment $twig;
private DoctrineDataCollector $collector;

public function setUp(): void
{
$this->logger = new DebugStack();
$registry = $this->getMockBuilder(ManagerRegistry::class)->getMock();
$this->debugDataHolder = new DebugDataHolder();
$registry = $this->getMockBuilder(ManagerRegistry::class)->getMock();
$registry->method('getConnectionNames')->willReturn([]);
$registry->method('getManagerNames')->willReturn([]);
$registry->method('getManagers')->willReturn([]);
$this->collector = new DoctrineDataCollector($registry);
$this->collector->addLogger('foo', $this->logger);
$this->collector = new DoctrineDataCollector($registry, true, $this->debugDataHolder);

$twigLoaderFilesystem = new FilesystemLoader(__DIR__ . '/../Resources/views/Collector');
$twigLoaderFilesystem->addPath(__DIR__ . '/../vendor/symfony/web-profiler-bundle/Resources/views', 'WebProfiler');
Expand Down Expand Up @@ -75,14 +79,7 @@ public function setUp(): void

public function testRender(): void
{
$this->logger->queries = [
[
'sql' => 'SELECT * FROM foo WHERE bar IN (?, ?) AND "" >= ""',
'params' => ['foo', 'bar'],
'types' => null,
'executionMS' => 1,
],
];
$this->debugDataHolder->addQuery('foo', new Query('SELECT * FROM foo WHERE bar IN (?, ?) AND "" >= ""'));

$this->collector->collect($request = new Request(['group' => '0']), new Response());

Expand All @@ -103,7 +100,7 @@ public function testRender(): void
'page' => 'foo',
'profile' => $profile,
'collector' => $this->collector,
'queries' => $this->logger->queries,
'queries' => $this->debugDataHolder->getData(),
]);

$expectedEscapedSql = 'SELECT
  *
FROM
  foo
WHERE
  bar IN (?, ?)
  AND "" >= ""';
Expand Down

0 comments on commit c09bfc3

Please sign in to comment.