sublime-phpunit icon indicating copy to clipboard operation
sublime-phpunit copied to clipboard

Docker support

Open gregorip02 opened this issue 4 years ago • 3 comments

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}

gregorip02 avatar Sep 14 '20 14:09 gregorip02

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",
    // ...
}

gregorip02 avatar Sep 14 '20 14:09 gregorip02

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.

gerardroche avatar Sep 14 '20 18:09 gerardroche

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.

  1. The name of the container.
  2. The absolute path of the project in the container.
  3. The path of the phpunit binary in the container.

I'm not sure how we can share these settings among sublime text users 🤔🤔🤔🤔🤔.

gregorip02 avatar Sep 15 '20 13:09 gregorip02

You can take advantage of the new phpunit.prepend_cmd settings so you can now do

"phpunit.prepend_cmd": ["docker", "exec", "-it", "my-container"]

gerardroche avatar Apr 09 '23 22:04 gerardroche

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",
    }
}

gerardroche avatar Aug 04 '23 04:08 gerardroche