Composer autoload-dev does not work
Asked Answered
T

2

9

The file autoload_psr4.php not contains the namespace from "autoload-dev" section only from "autoload" section.

When my composer.json reads

"autoload": {
    "psr-4": {
        "Namespace\\": "src/"
    }
},
"autoload-dev": {
    "prs-4": {
        "Namespace\\Tests\\": "tests/"
    }
}

And I run

composer require vendor/namespace 1.0-dev

My /vendor/composer/autoload_prs4.php file appears as

// autoload_psr4.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
    'Namespace\\' => array($baseDir . '/src'),
);

Thanks!

Tosh answered 11/4, 2016 at 2:40 Comment(1)
What have you tried to debug the problem? What about checking for any typos like ` prs-4` ?Known
B
11

My guess is that you're showing the composer.json of vendor/namespace package. If that's the case:

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.

Bales answered 11/4, 2016 at 7:56 Comment(1)
change directory to package directory under 'vendor/', and run phpunitSalsbury
I
11

Since this is the first Search Engine result when searching for "autoload-dev not working": In composer.json, if "autoload-dev" was added after defining and using "autoload", run $ composer dump-autoload.

Inter answered 22/4, 2020 at 9:32 Comment(1)
Thanks man, saved me a headache I was wondering what that command did should of just ran it. I didn't wanna have to make my own autoloader and bootstrap that into the phpunit.xmlPiddling

© 2022 - 2024 — McMap. All rights reserved.