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.
How could such a feature look like?
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.
- First one would probably build a blacklist by iterating over all composer.json files generating a list of files and folders to delete.
- Then one could use a whitelist from the main project to kick stuff from the blacklist (= whitelist stuff). This is to override exclude decisions made in fetched packages.
- Finally, use the blacklist for the delete run in the vendor folder.
- That means that the project pulling the vendor packages has full control. This approach provides great flexibility: if a package provider, blacklists a test folder, but the package consuming developer want to keep it, he can whitelist the folder of that package. But he can also do nothing, and go with the normal blacklists.
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.
Regarding the usage of a .gitattributes
file with export-ignore
directive
Yes, 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.