sublime-phpunit
sublime-phpunit copied to clipboard
Docker support
Please add support for running unit tests on docker containers.
{
"docker.container": "my-container"
}
This could be interpreted as.
docker exec -it my-container ${phpunitPath} ${filters} ${options}
I'm working with a script like:
#!/usr/bin/env bash
set -o errexit
set -o nounset
docker exec my-container-name vendor/bin/phpunit "$@"
In the config
{
// ...
"phpunit.executable": "./phpunit",
// ...
}
I don't use Docker so I'm not sure how best to support it yet.
It looks like in order to get to work you've created a script named "phpunit" in the root of your project and then pointed the phpunit.executable
at it. Essentially you've created a "proxy" script to execute phpunit properly in docker.
Maybe PHPUnitKit could have an option "phpunit.docker" (true|false) and then automatically execute phpunit in docker if true, but I think we'll have to also account for some options, like the container name, that may need to be passed to Docker too.
So it is exactly.
I was inspired by making this little proxy script based on docker support from https://github.com/calebporzio/better-phpunit#features
I think two things should be taken into account.
- The name of the container.
- The absolute path of the project in the container.
- The path of the phpunit binary in the container.
I'm not sure how we can share these settings among sublime text users 🤔🤔🤔🤔🤔.
You can take advantage of the new phpunit.prepend_cmd
settings so you can now do
"phpunit.prepend_cmd": ["docker", "exec", "-it", "my-container"]
I added dedicated support for SSH and Docker. I haven't been able to test the Docker support directly, but it should work in theory. If you get a chance to test it, let me know how it works for you.
Here are some examples.
SSH
Example: Run tests via SSH using Laravel Homestead
Command Palette → Preferences: PHPUnit Settings
{
"phpunit.ssh": true,
"phpunit.ssh_options": {
"-p": "22",
"-tt": true
},
"phpunit.ssh_user": "vagrant",
"phpunit.ssh_host": "homestead.test",
"phpunit.ssh_paths": {
"~/code/project1": "~/project1",
"/home/code/project2": "/home/vagrant/project2",
}
}
Docker
Example: Run tests via Docker
Command Palette → Preferences: PHPUnit Settings
{
"phpunit.docker": true,
"phpunit.docker_command": ["docker", "exec", "-it", "my-container"],
"phpunit.docker_paths": {
"~/code/project1": "~/project1",
"/home/code/project2": "/home/vagrant/project2",
}
}