简体   繁体   English

如何在开发过程中正确测试Composer包?

[英]How do you properly test a Composer package during development?

Update / My Solution: 更新/我的解决方案:

I accidentally didn't remove the VCS require from my composer.json before testing with the "autoload" key. 在使用“autoload”键进行测试之前,我意外地没有从composer.json中删除VCS要求。 It's now my understanding (based on what just happened) that the autoload section of composer.json is processed at runtime. 现在我的理解(基于刚刚发生的事情)composer.json的自动加载部分在运行时被处理。 If this is correct I may have solved my problem. 如果这是正确的,我可能已经解决了我的问题。 (false, but a InvalidArgumentException exception will be thrown by PHP if the trailing "\\\\" is missing from the namespace name, hence the confusion) (false,但如果命名空间名称中缺少尾部“\\\\”,则PHP将抛出InvalidArgumentException异常,因此会产生混淆)

The PSR-4 autoloader is independant of the git repository and does not require me to commit changes before testing, so this solution is sufficient for my purposes. PSR-4自动加载器独立于git存储库,并且不要求我在测试之前提交更改,因此这个解决方案足以满足我的需要。

I'm going to leave this question open for now in case somebody has an answer to my question in broader terms. 我现在打开这个问题,以防有人从广义上回答我的问题。 (ie answer to the question as stated in the title) (即回答标题中所述的问题)

The Problem: 问题:

I'm attempting to build something primarily for use on a specific project, but as I think it will be useful to others I've decided to make it a Composer package. 我正在尝试构建主要用于特定项目的东西,但我认为它对其他人有用我决定将其作为Composer包。

What I want to do is develop the composer package on a git repository, and do manual testing inside my own project where I'm using the package. 我想要做的是在git存储库上开发composer包,并在我自己的项目中进行手动测试,我正在使用该包。

The solutions I've found are as follows, but neither are sufficient: 我发现的解决方案如下,但都不够:

Include local Git repo as VCS repository in project's composer.json 在项目的composer.json中包含本地Git仓库作为VCS存储库

The big issue with this method is that for every small change I make I need to commit changes before being able to test them. 这种方法的一个大问题是,对于我所做的每一个小改动,我都需要在能够测试它们之前提交更改。 I'll wind up with tons of commits for my own silly syntax or api mistakes because I didn't test - not cool. 我会因为我自己的愚蠢语法或api错误而提交了大量的提交,因为我没有测试 - 不是很酷。

Move package folder into project folder and add it to project's "autoload" section in composer.json 将包文件夹移动到项目文件夹中,并将其添加到composer.json中项目的“autoload”部分

Unfortunately this method has the same issue. 不幸的是,这种方法有同样的问题。 I need to commit my changes if I want to perform manual testing, otherwise the following message appears when running "composer update": (see "Update / My Solution" header) 如果我想执行手动测试,我需要提交更改,否则在运行“composer update”时会出现以下消息:( 请参阅“更新/我的解决方案”标题)

[RuntimeException]
Source directory /srv/http/my-project/vendor/my-package
has unpushed changes on the current branch:
M     composer.json                                                             
A     src/EditorApplication.php

Write a shell script that copies source files excluding git-related files from my source folder into the autoloaded folder in my project 编写一个shell脚本,将源文件(不包括git相关文件)从源文件夹复制到项目中的自动加载文件夹中

There must be a way to do something so necessary in Composer without resorting to this. 必须有一种方法可以在Composer中做一些必要的事情,而不必诉诸于此。 How do you test uncommited changes to a composer package without doing the implementation inside the package itself? 如何在不在包本身内部实现的情况下测试对作曲家包的未经修改的更改? Is it even possible? 它甚至可能吗?

What I want to do is develop the composer package on a git repository, and do manual testing inside my own project where I'm using the package. 我想要做的是在git存储库上开发composer包,并在我自己的项目中进行手动测试,我正在使用该包。

How do you test uncommited changes to a composer package without doing the implementation inside the package itself? 如何在不在包本身内部实现的情况下测试对作曲家包的未经修改的更改? Is it even possible? 它甚至可能吗?

You can define the local child project's repository as a path repository in your root project's composer.json . 您可以将本地子项目的存储库定义为根项目的composer.jsonpath存储库。 The path allows you to depend on a local directory. path允许您依赖本地目录。

Referencing: https://getcomposer.org/doc/05-repositories.md#path 参考: https//getcomposer.org/doc/05-repositories.md#path

When the local development phase for the child project finishes, you can publish it and tag it instantly to have a first version out. 当子项目的本地开发阶段结束时,您可以发布它并立即标记它以获得第一个版本。 You are skipping the dev-master phase by having a version listed on Packagist, which can then be included by the/any parent project. 您正在通过在Packagist上列出一个版本来跳过dev-master阶段,然后可以包含/任何父项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM