Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Support class inheritance in getReference and related methods #541

Description

@pepeh

Feature Request

What

Support retrieving references in getReference and similar methods using parent classes or interfaces.

Currently, references are stored and retrieved using the exact class name as a key. This breaks when trying to retrieve an object using a parent class or interface, as the system performs a strict class name check.

Why

This limitation makes it impossible to work with inheritance hierarchies in fixtures.

For example:

class AdminRole extends Role {}
$this->addReference('admin-role', new AdminRole());

// Later in another fixture:
$role = $this->getReference('admin-role', Role::class); // This fails

How

  • When calling addReference, internally store the reference under all parent classes and interfaces of the object using class_parents() and class_implements().

  • Alternatively, during getReference, resolve all parent classes in case the reference is not found by the original class

These improvements would make fixture references more flexible while preserving the current design for strict lookups.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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