phpstorm中如何配置phpunit(單元測試)
一、總結
一句話總結:
phpstorm中配置phpunit需要配置php的CLI Interpreter
1、為什么phpstorm中使用phpunit需要配置php的CLI Interpreter?
因為phpunit是命令行的工具,而默認phpstorm里面是沒有配置php的CLI Interpreter,所以默認雖然laravel框架中有phpunit,但是phpunit是運行不了的,這種情況下網頁可以運行是因為用的phpstudy(如果網站環境是phpstudy的話)中的php.exe
二、laravel中如何配置phpunit(單元測試)
轉自或參考:laravel中如何配置phpunit(單元測試)_PHP_huha666的博客-CSDN博客
https://blog.csdn.net/huha666/article/details/103503313
laravel中集成了單元測試工具phpunit可以在項目的根目錄下進行使用,在phpstorm中使用phpunit需要做一些配置,指定composer的autoload.php就可以了。具體操作如下:
1)設置->語言&框架->PHP,點擊PHP后,選擇CLI Interpreter ,選擇當前運行的php版本(點擊后跳新頁面CLI Interpreter,在
General 中,PHP executable 下 選擇 php.exe文件即可)
注釋 : 如果不選 會報錯 ,Please select PHP Interpreter to load PHPUnit version
2) 設置->語言&框架->PHP->Test Frameworks中,Local-> Use Composer autoloader,選中地址即可
配置好phpunit的運行環境之后,可以直接在phpstorm的菜單欄中通過run操作來運行單元測試
為什么phpstorm中使用phpunit需要配置php的CLI Interpreter
因為phpunit是命令行的工具,而默認phpstorm里面是沒有配置php的CLI Interpreter,所以默認雖然laravel框架中有phpunit,但是phpunit是運行不了的,這種情況下網頁可以運行是因為用的phpstudy(如果網站環境是phpstudy的話)中的php.exe