How to run PHPUnit with different Linux user

Viewed 657
  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...

2 Answers

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

Related