Skip to content

Commit

Permalink
Merge pull request #1946 from VincentLanglet/compatibility-orm-3
Browse files Browse the repository at this point in the history
Add compatibility with doctrine/orm 3
  • Loading branch information
XWB authored May 30, 2024
2 parents 9f3c43a + ef0eb9b commit 11dc7d6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"require-dev": {
"doctrine/doctrine-bundle": "^2.1.1",
"doctrine/mongodb-odm": "^2.2",
"doctrine/orm": "^2.8",
"doctrine/orm": "^2.8 || ^3.2",
"doctrine/phpcr-odm": "^1.5.3 || ^2.0",
"ergebnis/composer-normalize": "^2.28",
"jackalope/jackalope-doctrine-dbal": "^1.2 || ^2.0",
Expand Down
21 changes: 13 additions & 8 deletions src/Doctrine/RegisterListenersService.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,22 @@ public function register(ObjectManager $manager, PagerInterface $pager, array $o
});
}

if (false === $options['debug_logging'] && $manager instanceof EntityManagerInterface) {
if (
false === $options['debug_logging']
&& $manager instanceof EntityManagerInterface
) {
$configuration = $manager->getConnection()->getConfiguration();
$logger = $configuration->getSQLLogger();
if (\method_exists($configuration, 'getSQLLogger') && \method_exists($configuration, 'setSQLLogger')) {
$logger = $configuration->getSQLLogger();

$this->addListener($pager, PreFetchObjectsEvent::class, function () use ($configuration) {
$configuration->setSQLLogger(null);
});
$this->addListener($pager, PreFetchObjectsEvent::class, function () use ($configuration) {
$configuration->setSQLLogger(null);
});

$this->addListener($pager, PreInsertObjectsEvent::class, function () use ($configuration, $logger) {
$configuration->setSQLLogger($logger);
});
$this->addListener($pager, PreInsertObjectsEvent::class, function () use ($configuration, $logger) {
$configuration->setSQLLogger($logger);
});
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Doctrine/ORM/ElasticaToModelTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace FOS\ElasticaBundle\Tests\Unit\Doctrine\ORM;

use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ManagerRegistry;
Expand Down Expand Up @@ -132,7 +132,7 @@ public function testTransformUsesDefaultQueryBuilderMethodConfiguration()
*/
public function testUsesHintsConfigurationIfGiven()
{
$query = $this->getMockBuilder(AbstractQuery::class)
$query = $this->getMockBuilder(Query::class)
->setMethods(['setHint', 'execute', 'setHydrationMode'])
->disableOriginalConstructor()
->getMockForAbstractClass()
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Doctrine/ORM/ListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected function getClassMetadataClass()

protected function getLifecycleEventArgsClass()
{
return \Doctrine\ORM\Event\LifecycleEventArgs::class;
return \Doctrine\Persistence\Event\LifecycleEventArgs::class;
}

protected function getListenerClass()
Expand Down
4 changes: 4 additions & 0 deletions tests/Unit/Doctrine/RegisterListenersServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ public function testShouldNotCallSleepListenerForAnotherPagers()

public function testShouldRegisterDisableDebugLoggingByDefaultForEntityManager()
{
if (!\interface_exists('Doctrine\DBAL\Logging\SQLLogger')) {
$this->markTestSkipped('This is only possible on doctrine/orm 2.');
}

$dispatcher = $this->createDispatcherMock();
$dispatcher->expects($this->exactly(2))
->method('addListener')
Expand Down

0 comments on commit 11dc7d6

Please sign in to comment.