Skip to content
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

Add compatibility with doctrine/orm 3 #1946

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading