thinkphp6+phpunit+mockery做单元测试

编程

  1. 使用composer安装phpunit

composer require phpunit/phpunit --dev

composer require mockery/mockery --dev

  1. 配置composer

{

"autoload-dev": {

"psr-4": {

"tests\": "tests"

}

},

"scripts": {

"start": "php think run",

"post-autoload-dump": [

"@php think service:discover",

"@php think vendor:publish"

],

"coverage": "vendor\bin\phpunit --coverage-html=coverage",

"test": "vendor\bin\phpunit"

}

}

  1. 在项目目录下新建tests目录

  2. 运行 vendorinphpunit --generate-configuration 生成配置文件

  3. 编写测试代码

  4. 运行 composer testcomposer coverage

参考了以下项目

https://github.com/friendsofthinkphp/think-jwt/

以上是 thinkphp6+phpunit+mockery做单元测试 的全部内容, 来源链接: utcz.com/z/518908.html

回到顶部