Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run PHPUnit with different Linux user

  1. My unit tests are located inside a Vagrant machine
  2. I'm using Xdebug with Apache on Ubuntu 18,
  3. I use PhpStorm to run PHPUnit tests.

The issue is the unit tests are restricted to be run by "apache" user and the way I run them from the command line is:

sudo -u apache phpunit tests/EmailFunctionsLargeTest.php --stop-on-failure

and it works, but how do I simulate the sudo -u apache phpunit when using PhpStorm?

P.S.

PhpStorm runs the tests as vagrant user...

like image 441
Jacob Balabanov Lanir Avatar asked Oct 15 '25 20:10

Jacob Balabanov Lanir


2 Answers

Not possible yet. Feel free to add your scenario as a comment to https://youtrack.jetbrains.com/issue/WI-38656

like image 191
Dmitrii Avatar answered Oct 18 '25 10:10

Dmitrii


Create a file php_wrapper.sh at /home/vagrant/php_wrapper.sh with below contents:

#!/bin/bash

sudo /usr/bin/php $@

Replace the command with sudo -u apache $@ if you want.

In your PhpStorm setup the remote interpreter as shown in the below screenshot. When you run phpunit, it uses the php_wrapper.sh as a PHP executable and runs seamlessly.

enter image description here

like image 23
Shaunak Sontakke Avatar answered Oct 18 '25 11:10

Shaunak Sontakke