Closed slmtbdwry closed 2 years ago
I did not build this extension with docker or remote SSH in mind, and I do not have much experience with either so I am not sure how well I can support those within this extension.
That being said, I have added the configuration option phpunit.workingDirectory
in the newest version which might help with your problem. You should try changing that from Find
to Parent
or perhaps the working directory path you are in. The workingDirectory
refers to the path for the child process when it is spawned. See nodejs.org for more information.
While that might help with the Couldn't find a working directory.
problem, I think you will still have issues with running the tests. I have added the experimental feature phpunit.experimental.useRelativePaths
which might help with the issue. Try turning that on if simply changing the workingDirectory
configuration does not work.
If that does not solve your problem, let me know and I can look into further implementing Docker and SSH support. Also, let me know if the extension better-phpunit works for your setup. I noticed that extension has configuration options for both Docker and SSH and if it does work I could look at that code to help me figure out how to get the correct file paths.
I've checked with different settings and it runs well now. phpunit.workingDirectory
config set to "Parent" resolve this issue.
My configuration is now like this:
"phpunit.testExplorer.folderPattern": "app/code/Icube/**/{test,tests,Test,Tests}/**/*.php",
"phpunit.testExplorer.showOutput": "always",
"phpunit.testExplorer.verboseTestExplorerOutput": true,
"phpunit.commandLine.args": ["-c", "/home/cloudpanel/htdocs/project/dev/tests/unit/phpunit.xml"],
"phpunit.workingDirectory": "Parent",
"phpunit.experimental.ssh.enable": true,
"phpunit.experimental.ssh.host": "localhost",
"phpunit.experimental.ssh.user": "root",
"phpunit.experimental.ssh.paths": {
"/home/me/projects": "/home/cloudpanel/htdocs"
},
"phpunit.experimental.ssh.args": "-t -t \"cd /home/cloudpanel/htdocs/project; /usr/bin/php /home/cloudpanel/htdocs/project/vendor/bin/phpunit\""
I don't use phpunit.experimental.useRelativePaths
since it still triggers error:
Cannot open file "project/app/code/blablabla/DataTest.php".
And I try setting phpunit.configurationPath
with useRelativePaths
false, but still get error:
Could not read "/home/cloudpanel/htdocs/project/dev/tests/unit/phpunit.xml".
Thank you. This issue can be closed now.
Update: Turns out that the SSH experimental config aren't functional yet. And actually my setup is not running phpunit with SSH into docker, but immediately execute the phpunit binary in the Remote SSH session.
But, it's OK enough that the setup is able to read the configuration without useRelativePaths. The latest config is:
"phpunit.testExplorer.folderPattern": "app/code/Vendor/**/{test,tests,Test,Tests}/**/*.php",
"phpunit.configurationPath": "/home/me/projects/project/dev/tests/unit/phpunit.xml",
"phpunit.testExplorer.showOutput": "always",
"phpunit.testExplorer.verboseTestExplorerOutput": true,
"phpunit.workingDirectory": "Parent",
"phpunit.execPath": "/home/me/projects/project/vendor/bin/phpunit",
"phpunit.experimental.useRelativePaths": false
The output is just as expected:
PHPUnit 9.4.4 by Sebastian Bergmann and contributors.
Warning: Your XML configuration validates against a deprecated schema.
Suggestion: Migrate your XML configuration using "--migrate-configuration"!
. 1 / 1 (100%)
Time: 00:00.038, Memory: 16.00 MB
OK (1 test, 1 assertion)
-------------------------------------------------------
Glad to see you got it working! I will remove the useRelativePaths
as I also was never able to get it working. I will have to spend some more time looking into getting it working better with Docker and SSH, but since this is able to work with the workingDirectory
addition those changes are not pressing and may take longer for me to complete.
Hi, thank you for this cool extension.
I get error every time running the test.
Couldn't find a working directory.
That's all what I get in the terminal output and popup notification.
I install the extension in vscode-server a.k.a via Remote SSH, where the project directory is inside docker that can be accessed with SSH. So I try calling phpunit with SSH command to the docker container (from Remote SSH session workspace).
My config is like this: