I\'m new in composer development. I just start to work with composer in my current project. And I think my question is already asked before or I\'m noob about composer :D
<
Is there any command to remove those tests OR I need to remove it manually OR what...? :'(
Thats an interesting question.
At the moment, you as the package consumer can't ignore tests automatically. There is no Composer command to clean all the folders after the download of vendors. To solve the problem, clean up the vendor dir as part of your application build process. Its a delete run during bootstrap on a manually selected file set, then upload. This is a setup step, comparable to a cache warmup or inital database setup for production. Boring work :(
The topic of removing the test folder (and other development stuff) from the vendor folder was requested and discussed before, see for example Composer Issues #1750 and #4438.
A lot of users want this feature, but unfortunately Composer doesn't provide it, yet. I guess, the Composer maintainers would merge an exclude folders (reduce feature), if someone invests the time to solve the problem. Its hard work to establish a standard. Its also possible to create a Composer Plugin to provide this feature.
One way of solving this would be to provide a general blacklist-/whitelisting feature for files to keep for production in the composer.json
file. Adding only an exclude section solves the problem only partly in my humble opinion, because you can't override decision made in packages.
Maybe one could also respect the export-ignore
settings in the .gitattributes
file of a package, when fetching the Source and not the Dist.
Another way is to concentrate on the autoloading description.
Composer provides require-dev
and autoload-dev
next to require
and autoload
. That means we have a clear separation between development and production classes. Think about the phpunit dependency and your tests folder, defined in require-dev
and test namespace defined in autoload-dev
.
That makes it possible to use the autoloading map and remove all files which are not included in Composers "autoload scope" for production.
David Grudl (@dg) used this approach in his Composer Cleaner.
Its experimental. Do a backup.
.gitattributes
file with export-ignore
directiveYes, this is one way to reduce the size of git archives, but its never been adopted as a standard or best practice by the PHP commmunity.
The Composer maintainers are promoting its usage (see the comments of alcohol and naderman), while for instance Symfony dropped its usage.
There is no clear guidance for a best practice on this issue at the moment. So, i'm not sure that this is a best practice and we should really promote or suggest this.
Its for "Dists", fetched with composer --prefer-dist
.
And even if some developers adopt this practice, a lot of ways to fetch the "Source" with Composer are not taken care of: hg, svn, git source.