如何删除composer php中的所有测试? [英] How to remove all tests in composer php?

查看:26
本文介绍了如何删除composer php中的所有测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是作曲家开发的新手.我刚开始在我当前的项目中与作曲家合作.而且我认为我的问题之前已经被问过,或者我对作曲家很陌生:D

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

每个依赖项的 vendor 中都有许多测试文件和目录.我只是想在上传到服务器之前删除这些测试.

There are many test files and directories in vendor of each dependency. I just want to remove those tests before upload it to server.

是否有任何命令可以删除这些测试,或者我需要手动删除它,或者什么...?:'(

Is there any command to remove those tests OR I need to remove it manually OR what...? :'(

推荐答案

是否有任何命令可以删除这些测试,或者我需要手动删除它,或者什么...?:'(

Is there any command to remove those tests OR I need to remove it manually OR what...? :'(

这是一个有趣的问题.

目前,作为包消费者,您不能自动忽略测试.下载供应商后,没有 Composer 命令来清理所有文件夹.要解决此问题,请在应用程序构建过程中清理供应商目录.它在引导过程中对手动选择的文件集进行删除运行,然后上传.这是一个设置步骤,类似于用于生产的缓存预热或初始数据库设置.无聊的工作:(

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 :(

之前已请求并讨论过从供应商文件夹中删除测试文件夹(和其他开发内容)的主题,例如参见 Composer 问题 #1750#4438.

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.

很多用户都想要这个功能,但不幸的是 Composer 还没有提供它.我猜,如果有人花时间解决问题,Composer 维护者会合并一个排除文件夹(减少功能).建立标准是一项艰巨的工作.也可以创建一个 Composer 插件来提供此功能.

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.

  1. 解决此问题的一种方法是为文件提供一个通用的黑名单/白名单功能,以便在 composer.json 文件中保留以供生产使用.在我看来,仅添加一个排除部分只能部分解决问题,因为您不能覆盖包中的决定.

  1. 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.

  • 第一个可能会通过遍历所有 composer.json 文件来生成黑名单,生成要删除的文件和文件夹列表.
  • 然后可以使用主项目中的白名单从黑名单中踢出东西(= 白名单的东西).这是为了覆盖在获取的包中做出的排除决定.
  • 最后,在 vendor 文件夹中使用黑名单进行删除运行.
  • 这意味着拉取供应商包的项目拥有完全控制权.这种方法提供了很大的灵活性:如果包提供者将测试文件夹列入黑名单,但使用包的开发人员想要保留它,他可以将该包的文件夹列入白名单.但他也无能为力,按照正常的黑名单去.

在获取源而不是分布时,也许还可以尊重包的 .gitattributes 文件中的 export-ignore 设置.

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 在 requireautoload 旁边提供 require-devautoload-dev.这意味着我们在开发类和生产类之间有明确的分离.想想 phpunit 依赖项和你的测试文件夹,在 require-dev 中定义和在 autoload-dev 中定义的测试命名空间.

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.

这使得可以使用自动加载映射并删除 Composers自动加载范围"中未包含的所有文件以进行生产.

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) 在他的Composer Cleaner.

David Grudl (@dg) used this approach in his Composer Cleaner.

它的实验性.进行备份.

Its experimental. Do a backup.

关于 .gitattributes 文件与 export-ignore 指令的使用

是的,这是减少 git 档案大小的一种方法,但它从未被 PHP 社区采用为标准或最佳实践.

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.

Composer 维护者正在推广它的使用(参见alcoholnaderman),例如 Symfony 停止使用.

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.

它用于Dists",使用 composer --prefer-dist 获取.

Its for "Dists", fetched with composer --prefer-dist.

即使有些开发者采用了这种做法,很多使用 Composer 获取Source"的方法也没有得到处理:hg、svn、git source.

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.

这篇关于如何删除composer php中的所有测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆