I have many microservices running locally in a kubernetes/devspace environment.
Based on this and this, IntelliJ and PhpStorm don't support running PHPUnit tests from within devspace or kubectl.
So in the meantime, I am just running a bash script manually as a script via Run | Edit Configurations...:
#!/usr/bin/env bash
devspace enter -c foo php artisan config:clear;
kubectl exec -it deploy/foo -- \
vendor/bin/phpunit \
tests/MyExamples/ExampleTest.php -v \
--log-junit reports/unitreport0.xml \
-d memory_limit=-1
Is there a better way to do this using devspace? I'd like to be able to at least integrate it with the test runner instead of running a script.
If not, is there any way to extract the current test name or class in IntelliJ/PhpStorm so that I can pass it into the script as a parameter?
Also, is there any way to make the lines clickable in IntelliJ/PhpStorm?
/bar/foo/tests/MyExamples/ExampleTest.php:123
I think the best way to do this in IntelliJ/PHPStorm is to use
sshd. This is well supported in devspace with a tiny amount of configuration.First, add this line to the
devspace.yamlfile to set up sshd on your instance:Then you should be able to log in via ssh. Note that you will have appended some lines to your
.ssh/configfile, so you may want to verify these settings:Then in IntelliJ, go to
File→Settings→Tools→SSH Configurations, add a new entry:Host:
foo.bar.devspaceUsername:
devspacePort:
10659(NOTE: confirm this value in your ~/.ssh/config file. The default of 22 is probably incorrect)Authentication Type:
Key pairPrivate key file:
/Users/<myusername>/.devspace/ssh/id_devspace_ecdsa(replacing myusername with your own user name)ensure that Parse config file ~/.ssh/config is checked
Then, in
File→Remote Development, click onSSH Connection→New Connection, then choose the connection we just created from the Connection dropdown (all the other fields should be greyed out), and click Check Connection and Continue. (If this doesn’t work, your shell may be set incorrectly---make sure the$SHELLis not set to something like/sbin/nologininside devspace).In the "Choose IDE and Project" dialogue, choose an IDE and version and set the Project directory to some value---it doesn't look like you can set it to be empty, so maybe your home directory will work. You may get some confirmation dialogues from docker desktop as it installs Intellj/PHPStorm on the devspace client.
Run Intellij---it will connect to your devspace environment. You can load your project from the container. It will likely prompt you to install the PHP plugin and restart.
Now you should be able to Run a unit test---click on the Green arrow beside a test to make sure it works. You should also be able to Debug a unit test with a breakpoint.