6

I have some tests that are namespaced being autoloaded in package A using

"autoload-dev": {
    "psr-4": {
        "Vendor\\PackageA\\PhpUnit\\": "tests/PhpUnit"
    }
},

This works fine.

I have another package, package B which also have namespaced tests that require one of the namespaced tests in package A

"autoload-dev": {
    "psr-4": {
        "Vendor\\PackageB\\PhpUnit\\": "tests/PhpUnit"
    }
},

However, when I try and include the file in Package B, the class is not found

use Vendor\PackageA\PhpUnit\MyTestFromA;

class MyTestFromB extends MyTestFromA
{

Making me think that the autoload-dev stuff from other packages is not being loaded.

PHP Fatal error: Class 'Vendor\PackageA\PhpUnit\MyTestFromA' not found in /full/path/to/PackageBClass.php on line 3

When I try and import a file that is being autoloaded using autoload from package B rather than autoload-dev, I get no error.

How can I overcome this?

Part of me is thinking to make a package just for the tests and have it autoloaded in both without autoload-dev but I want to confirm first.

1

1 Answer 1

9
+50

Solution: Composer autoload-dev does not work.

Take a look at the docs. It says: "autoload-dev (root only)". root only means it only applies to the root package. As you included the package, the shown composer.json file is not the root package and the autoload-dev section is thus ignored.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.