Skip to content

Test failing on PHP 8.5 #12282

@mbeccati

Description

@mbeccati

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions