初始化一个composer项目,composer.json配置文件如下
{"name": "zingfront/questions-php","type": "project","require": {"php": "^7.4"},"require-dev": {"phpunit/phpunit": "^9.5.10"},"autoload": {"psr-4": {"": "src/"}},"autoload-dev": {"psr-4": {"Tests\\": "tests/"}},"config": {"preferred-install": "dist","sort-packages": true,"allow-plugins": {"easywechat-composer/easywechat-composer": false,"php-http/discovery": true}},"minimum-stability": "dev","prefer-stable": true,"repositories": {"packagist": {"type": "composer","url": "https://mirrors.aliyun.com/composer/"}}}
配置phpstorm的解释器
composer 安装 phpunit
composer require --dev phpunit/phpunit:^9.5.10
追加tests的代码目录到命名空间
执行composer dump-autoload 重新生成autoload配置文件
配置测试框架路径
编写测试用例
测试代码覆盖率检查(这个必须安装xdebug)否则会报找不到No code coverage driver available
覆盖检测结果