Skip to content

fix(discovery): support PSR-4 paths defined as arrays in composer.json#2112

Draft
nayleen wants to merge 1 commit intotempestphp:3.xfrom
nayleen:fix/discovery-psr4-array-paths
Draft

fix(discovery): support PSR-4 paths defined as arrays in composer.json#2112
nayleen wants to merge 1 commit intotempestphp:3.xfrom
nayleen:fix/discovery-psr4-array-paths

Conversation

@nayleen
Copy link
Copy Markdown

@nayleen nayleen commented Apr 7, 2026

This reproduces the error I'm seeing in a project using tempest/discovery standalone.

The issue most likely affects the main framework as well due to a assumption in the Discovery Composer.php class that PSR-4 namespaces only map to a single path, even though Composer's schema allows both string and list<string>:

https://getcomposer.org/doc/04-schema.md#psr-4

If you need to search for a same prefix in multiple directories, you can specify them as an array as such:

{
    "autoload": {
        "psr-4": { "Monolog\\": ["src/", "lib/"] }
    }
}

As per the contribution guidelines I've only submitted the failing test, even though I gave a fix a shot already.

You'll find the patch in the following Gist: https://gist.github.com/nayleen/1696e073c98c98f7b822ed51927e3350

The test reproduces the exact error I'm seeing:

Tests\Tempest\Integration\Core\ComposerTest::supports_psr4_paths_as_array
TypeError: Tempest\Discovery\Composer::{closure:Tempest\Discovery\Composer::load():41}(): Argument #1 ($path) must > be of type string, array given, called in /app/src/packages/support/src/Arr/functions.php on line 862

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant