thinkphp6+phpunit+mockery 做单元测试

原创
07/30 16:40
阅读数 1.2K
  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. 运行 vendor\bin\phpunit --generate-configuration 生成配置文件

  3. 编写测试代码

  4. 运行 composer testcomposer coverage

参考了以下项目

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

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部