1、安装phpunit
➜ wget https://phar.phpunit.de/phpunit.phar
➜ chmod +x phpunit.phar
➜ php phpunit.phar --version
>> PHPUnit 6.3.0 by Sebastian Bergmann and contributors.
➜ sudo mv phpunit.phar /usr/local/bin/phpunit
➜ phpunit --version
>> PHPUnit 6.3.0 by Sebastian Bergmann and contributors.
2、配置 ~/.bash_profile
# PHP Unit
t() {
if [ -f vendor/bin/phpunit ]; then
vendor/bin/phpunit "$@"
else
phpunit "$@"
fi
}
这样在 Terminal 中可以使用 t 直接运行。
➜ t --stderr
3、配置 PHPStorm 中 phpunit 路径
PHPStorm: Preferences > Test Frameworks > + > PHP Unit Local
> Path to phpunit.phar: /usr/local/bin/phpunit
> Default configuration file: /Laravel项目目录/phpunit.xml
> Default bootstrap file: /Laravel项目目录/vendor/autoload.php
这样就可以在 PHPStorm 中对 Laravel Test 文件使用 control+alt+d
执行 PHPUnit 了。