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.
require: These are must packages for the code to run. It defines the actual dependency as well as package version. require_dev: It defines the packages necessary for developing the project and not needed in production environment. Note: The require and require_dev are important parameters available in composer.
According to composer's manual: require-dev (root-only) Lists packages required for developing this package, or running tests, etc. The dev requirements of the root package are installed by default. Both install or update support the --no-dev option that prevents dev dependencies from being installed.
To update dependencies two commands can be used: composer update and composer require . The difference between these two commands is that composer update will try to update a dependency based on the current constraints in composer. json and will only update composer. lock .
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 theautoload-dev
section is thus ignored.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With