Run test in phpunit with specific php version

Solution 1:

$ /Applications/MAMP/bin/php/php5.2.17/bin/php path/to/phpunit.phar

Create a script e.g. phpunit-using-5.2

#!/bin/sh
set -e

/Applications/MAMP/bin/php/php5.2.17/bin/php path/to/phpunit.phar "$@"

Now you can run it:

$ phpunit-using-5.2

Or you can create a bash alias too.

Solution 2:

I had two version of php, default is 7.4 and older is 7.3, so I can test my testcase with older version like this.

php7.3 ./vendor/bin/phpunit