Composer require-dev requiring dependency in different require-dev packages

I have several tests that are with names that will autoload in package A using

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

This works great.

I have another package, package B, which also has name extension tests that require one of the tests with names in package A

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

However, when I try to include the file in package B, the class was not found

 use Vendor\PackageA\PhpUnit\MyTestFromA; class MyTestFromB extends MyTestFromA { 

Make me think that autoload-dev files from other packages are not loading.

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

When I try to import a file that is automatically loaded using autoload from package B and not autoload-dev , I get no error.

How can I overcome this?

Part of me is thinking of making the package only for tests and automatically downloading it without autoload-dev , but first I want to confirm.

+5
source share
1 answer

Composer autoload constructor does not work .

Take a look at the docs . It says: "autoload-dev (only for root) . Root means that it applies only to the root package. When you include the package shown, the composer.json file is not the root package, so the autoload-dev section is ignored.

+6
source

Source: https://habr.com/ru/post/1260825/


All Articles