thinkphp5.0+phpstorm部署phpunit
1、composer.json加这么一段:
"autoload": { "psr-4": { "app\\": "application" } }
然后执行命令:
composer dump-autoload
2、根目录下新建文件 phpunit.xml:
<?xml version="1.0" encoding="UTF-8"?> <phpunit backupGlobals="false" backupStaticAttributes="false" colors="true" bootstrap="./tests/autoloader.php" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" syntaxCheck="false"> <testsuites> <testsuite name="Application Test Suite"> <directory>./tests/Unit</directory> </testsuite> </testsuites> <logging> <log type="coverage-html" target="/tmp/reports"/> </logging> <php> </php> </phpunit>
3、根目录下新建文件夹tests并在里面新建文件autoloader.php:
require __DIR__ . '/../thinkphp/base.php'; require __DIR__ . '/../vendor/autoload.php';
4、然后如图操作:
5、找了半天没找到初始化数据库的函数,只找到载入model之前会读取文件thinkphp/convention.php,吧thinkphp/convention.php文件里的数据库配置填一下就可以了。
6、可以愉快地进行测试了