Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Param pathMapping #9

Closed
wants to merge 2 commits into from
Closed

Conversation

satiromarra
Copy link

Fix remote and local paths mapping in docker

@renandelmonico
Copy link
Owner

Awesome! Thanks for your contribuition!

I saw you PR and it's nice but there is some points we need fix to accept your PR.

Looks good the filepath replacement but we need replace another things as well besides that. I run a test with this configuration above:

"phpunit.relativeFilePath": true,
    "phpunit.shell": "/bin/bash",
    "phpunit.docker": true,
    "phpunit.dockerImage": "/usr/bin/docker run --rm --network=bco_default -v $(pwd):$(pwd)/outro -w=$(pwd) --entrypoint=\"\" myrepo.intranet/my-docker/build/php:7.4-latest",
    "phpunit.phpunit": "./outro/vendor/bin/phpunit",
    "phpunit.discoverConfigFile": true,
    "phpunit.args": [
        "--no-coverage",
        "--testsuite all"
    ],
    "phpunit.pathMappings": {
        "${workspaceRoot}": "/mypath/outro"
    },

Look my volume mapping -v $(pwd):$(pwd)/outro

I create a subfolder in mapping and run it. The filepath replacements is ok but when the extension try to run it throw an error. Take a look at server/src/TestRunner.ts on line 194.

const command = `${dockerImage} bash -c "${phpUnitFile} ${params.join(' ')}"`;

The generated command line is:

/usr/bin/docker run --rm --network=bco_default -v $(pwd):$(pwd)/outro -w=$(pwd) --entrypoint=\"\" myrepo.intranet/my-docker/build/php:7.4-latest bash -c \"./outro/vendor/bin/phpunit -c /mypath/phpunit.xml --no-coverage --testsuite all --filter '/^.*::testFileNameShouldReturnNameOfFile.*$/' outro/tests/unit/Service/Report/AccountStatementLatam/AccountStatementLatamTest.php\"

How can we see, the phpunit.xml didn't change its path to /mypath/outro and we need change that path too.

@renandelmonico renandelmonico added the enhancement New feature or request label Jun 24, 2022
@satiromarra
Copy link
Author

I have tried this:
my current dir in local is src

$ pwd
/home/user/projects/laravel/src

Running test in docker directly

docker run -v $(pwd):$(pwd)/otro --entrypoint="" -w=$(pwd) --rm phpunit_phpunit bash -c "./otro/vendor/bin/phpunit -c ./otro/phpunit.xml --no-coverage --testsuite all --filter '^.*::testFunction.*$' otro/tests/Unit/ExampleTest.php"

returns

PHPUnit 9.5.20 #StandWithUkraine
.                                                                   1 / 1 (100%)
Time: 00:00.045, Memory: 8.00 MB
OK (1 test, 1 assertion) 

in my configuration I specify the path to phpunit.xml instead of "discoverConfigFile:true";

    "discoverConfigFile": false,
    "phpunit.args": [
      "-c",
      "./otro/phpunit.xml"
    ],

It is the same as:

    "discoverConfigFile": false,
    "phpunit.configFile":"/home/user/projects/laravel/src/outro/phpunit.xml",
    // "phpunit.configFile":"./outro/phpunit.xml",

If "discoverConfigFile" is set to "true" the method will search for the file in "workDir" upwards, but the file is in a subdirectory that it will not find.

/home/user/projects/laravel/src/phpunit.xml
/home/user/projects/laravel/phpunit.xml
/home/user/projects/phpunit.xml
/home/user/phpunit.xml
/home/phpunit.xml
/phpunit.xml

but it is a subdirectory and will never come in to search:

/home/user/projects/laravel/src/otro/phpunit.xml

Another thing that can be added is setting:

"phpunit.configFile":"${remoteCwd}otro/phpunit.xml",

and in WorkspaceFolder.ts:

        let configFile = this.config.configFile;
        if (this.config.docker && configFile) {
            configFile = configFile.replace(/\$\{remoteCwd\}/gi, this.config.remoteCwd);
        }
...
        .setConfigFile(configFile)
...

And the new command is:

docker run -v $(pwd):$(pwd)/otro --entrypoint="" -w=$(pwd) --rm phpunit_phpunit bash -c "./otro/vendor/bin/phpunit -c /home/user/projects/laravel/src/otro/phpunit.xml --no-coverage --testsuite all --filter '^.*::testFunction.*$' otro/tests/Unit/ExampleTest.php"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants