简体   繁体   中英

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. It's now my understanding (based on what just happened) that the autoload section of composer.json is processed at runtime. 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)

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.

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.

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.

The solutions I've found are as follows, but neither are sufficient:

Include local Git repo as VCS repository in project's composer.json

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.

Move package folder into project folder and add it to project's "autoload" section in composer.json

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)

[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

There must be a way to do something so necessary in Composer without resorting to this. 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.

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 . The path allows you to depend on a local directory.

Referencing: 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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