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

查看:74
本文介绍了如何删除作曲家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

每个依赖项的供应商中都有很多测试文件和目录。我只是想删除那些测试,然后再将其上传到服务器。

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 Issues #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文件夹中运行的删除。

  • 这意味着提取供应商软件包的项目具有完全控制权。这种方法提供了极大的灵活性:如果程序包提供者将测试文件夹列入黑名单,但是使用程序包的开发人员希望保留该文件夹,则他可以将该程序包的文件夹列入白名单。但是他也无能为力,只能使用普通的黑名单。

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

也许有人也可以尊重出口在获取源文件而不是Dist时,在包的 .gitattributes 文件中-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提供了 require-dev autoload-dev 旁边的 require autoload 。这意味着我们在开发和生产类别之间有明确的区分。考虑一下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维护人员正在推广其用法(请参阅
酒精 naderman ),而例如 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的源未得到处理:hg,svn,git源。

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.

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

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