gerardroche / sublime-phpunit

PHPUnit Sublime Text integration.
https://www.gerardroche.com
GNU General Public License v3.0
74 stars 11 forks source link

Docker support #99

Closed gregorip02 closed 1 year ago

gregorip02 commented 4 years ago

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 commented 4 years ago

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",
    // ...
}
gerardroche commented 4 years ago

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.

gregorip02 commented 4 years ago

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 🤔🤔🤔🤔🤔.

gerardroche commented 1 year ago

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 commented 1 year ago

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