設(shè)置PHP CLI Interpreter(本地php執(zhí)行路徑)
路徑:Preferences > Languages & Frameworks > PHP
image.png
如果CLI Interpreter沒(méi)有顯示可選版本暇藏,可以點(diǎn)擊右邊"..."選擇本地的PHP的可執(zhí)行路徑
image.png
設(shè)置phpunit
路徑:Preferences > Languages & Frameworks > PHP > TestFrameworks
image.png
該示例中我們使用composer自動(dòng)加載的方式楣颠,composer安裝phpunit可以使用
composer require --dev phpunit/phpunit
Path to script:填項(xiàng)目中vendor的autoload.php
Default configuration file:填寫(xiě)項(xiàng)目中phpunit.xml文件的路徑
配置phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="./test/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Tests">
<directory suffix="Test.php">./test</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
</phpunit>
此處我們配置一個(gè)testsuite巡蘸,目錄為項(xiàng)目根目錄所在的test目錄
bootstrap:在PHPUnit命令行測(cè)試在測(cè)試之前執(zhí)行,作用相當(dāng)于include ./test/bootstrap.php饵骨,常用配類(lèi)的自動(dòng)加載
運(yùn)行單元測(cè)試
我們?cè)诟夸泴?xiě)一個(gè)單元測(cè)試,內(nèi)容如下并點(diǎn)擊IDE的執(zhí)行按鈕就可以執(zhí)行單元測(cè)試了
image.png
至此phpstorm的單元測(cè)試就配置完成了^_^
phpunit的具體操作可參考:phpunit官方文檔