Tommy bloggt Some things that matter to me

A Composer plugin development environment

I’ve created several Composer plugins and scripts recently. Currently I’m working on the plugin for PHIVE.

So sometimes people ask me, how I develop and test a plugin or a Composer script. So I released a small development environment powered by Docker and Docker-Compose which you can use to develop your own Composer extension.

With this “dev-env” you don’t make your local Composer environment dirty and you don’t need another local bare Git repository and move some Git tags around.

The only requirement is to have minimal familiarity with Docker and Docker-Compose.

How it works

The repository contains two containers. One for Composer and one for the plugin. Both based on Alpine Linux and including PHP 7.1 over CLI. So they are really small and use minimal disk space. You can find every Docker image in the appropriate directory.

I also added a dummy plugin to see the process directly in action. So after you checked out the repository via Git and built the containers via

docker-compose build

you can install your new (or the dummy) plugin via:

docker-compose run --rm composer global require my/new-plugin

The composer container depends on the plugin container. The sources of your plugin are always symlinked to the Composer container. I used the path type as repository option to register the plugin to Composer, so you instantly see changes by every command call.

So if you want to see the new dummy Composer CLI command, run:

docker-composer run --rm composer new-plugin:sample

Notes and options

Of course you can change the PHP version which is used in the Docker containers.

Assume you need a special Composer version or want to test your plugin with a special one, change the Dockerfile in the composer directory and extend from the offical Composer Docker images.

You can also extend the Dockerfile for the plugin. Maybe to install PHPUnit or an other testing framework. So you can run a command like this:

docker-composer run --rm plugin vendor/bin/phpunit

Summary

I hope this helps other developers to create a new Composer extension.
If you have questions or some additions, please leave a comment below.