orm icon indicating copy to clipboard operation
orm copied to clipboard

Test failing on PHP 8.5

Open mbeccati opened this issue 3 months ago • 2 comments

Bug Report

Q A
Version 2.20.x

Summary

A test started to fail since a few days on the 2.20.x branch with PHP master and 8.5, but not if it is run standalone.

Current behavior

1) Doctrine\Tests\ORM\Functional\Ticket\SwitchContextWithFilterAndIndexedRelation\ChangeFiltersTest::testIndexAliasUpdatedWithUpdatedFilter
Using null as an array offset is deprecated, use an empty string instead

/.../OSS/orm/src/Mapping/ClassMetadataInfo.php:3302
/.../OSS/orm/src/UnitOfWork.php:3177
/.../OSS/orm/src/Internal/Hydration/SimpleObjectHydrator.php:181
/.../OSS/orm/src/Internal/Hydration/SimpleObjectHydrator.php:66
/.../OSS/orm/src/Internal/Hydration/AbstractHydrator.php:276
/.../OSS/orm/src/Persisters/Entity/BasicEntityPersister.php:787
/.../OSS/orm/src/EntityRepository.php:240
/.../OSS/orm/tests/Tests/ORM/Functional/Ticket/SwitchContextWithFilterAndIndexedRelation/ChangeFiltersTest.php:42

Expected behavior

No test failure

How to reproduce

/path/to/php-8.5 vendor/bin/phpunit tests/Tests/ORM/Functional/Ticket

Potential fix

I have no idea why $assoc['mappedBy'] ends up being null when the test is run after other tests. However the following diff fixes the test.

diff --git a/src/UnitOfWork.php b/src/UnitOfWork.php
index adae0cb38..d2b0e4545 100644
--- a/src/UnitOfWork.php
+++ b/src/UnitOfWork.php
@@ -3174,7 +3174,7 @@ EXCEPTION

                     if ($hints['fetchMode'][$class->name][$field] === ClassMetadata::FETCH_EAGER) {
                         $isIteration           = isset($hints[Query::HINT_INTERNAL_ITERATION]) && $hints[Query::HINT_INTERNAL_ITERATION];
-                        $isForeignKeyComposite = $targetClass->hasAssociation($assoc['mappedBy']) && count($targetClass->getAssociationMapping($assoc['mappedBy'])['joinColumns'] ?? []) > 1;
+                        $isForeignKeyComposite = $targetClass->hasAssociation($assoc['mappedBy'] ?? '') && count($targetClass->getAssociationMapping($assoc['mappedBy'])['joinColumns'] ?? []) > 1;

                         if ($assoc['type'] === ClassMetadata::ONE_TO_MANY && ! $isIteration && ! $isForeignKeyComposite && ! isset($assoc['indexBy'])) {
                             $this->scheduleCollectionForBatchLoading($pColl, $class);

mbeccati avatar Nov 20 '25 18:11 mbeccati

That piece of code was introduced in #11397

cc @Brajk19 @HypeMC

This particular piece of code gave me headaches when trying to merge it up in #12277

I think adding the same check I added in that PR might help.

Can one of you send a PR?

greg0ire avatar Nov 20 '25 18:11 greg0ire

@greg0ire Sure, I'll do it.

HypeMC avatar Nov 20 '25 21:11 HypeMC