webman 使用 PHPUnit

  1. 安装 phpunit composer require --dev phpunit/phpunit
  2. 项目根目录新增配置文件 phpunit.xml

引用 webman 官方文档

xml 复制代码
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
    bootstrap="support/bootstrap.php"
    cacheDirectory=".phpunit.cache"
    executionOrder="depends,defects"
    shortenArraysForExportThreshold="10"
    requireCoverageMetadata="false"
    beStrictAboutCoverageMetadata="true"
    beStrictAboutOutputDuringTests="true"
    displayDetailsOnPhpunitDeprecations="true"
    failOnPhpunitDeprecation="true"
    failOnRisky="true"
    failOnWarning="true"
    colors="true">
    <testsuites>
        <testsuite name="tests">
            <directory>./tests</directory>
        </testsuite>
    </testsuites>
    <source>
        <include>
            <directory suffix=".php">./app</directory>
        </include>
    </source>
</phpunit>
  1. 根目录下新建文件夹 tests
  2. 新建测试类并继承 PHPUnit\Framework\TestCase
php 复制代码
namespace tests;

use PHPUnit\Framework\TestCase;

class CswmClientTest extends TestCase
{

    public function testGet()
    {
        $this->assertEquals(1, 1);
    }
}
  1. 使用 ./vendor/bin/phpunit [路径] 运行测试
  • 运行全部测试: ./vendor/bin/phpunit
  • 运行 a 目录下的: ./vendor/bin/phpunit test/a
  • 运行指定实例: ./vendor/bin/phpunit tests/TestConfig.php
  1. 与IDE 集成
    在IDE 里面新建一个测试配置,并使用 Composer 加载配置
  • 脚本路径是项目中 vendor\autoload.php
  • 配置就是刚刚创建的配置
相关推荐
xinhuanjieyi3 小时前
Deprecated: Directive ‘track_errors‘ is deprecated in Unknown on line 0
php
棒棒的唐5 小时前
Composer国内镜像配置全指南:加速依赖下载
php·composer
神净讨魔7655 小时前
【php】老旧PHP项目(PHP 5.6)本地环境搭建与踩坑记录
php
在角落发呆6 小时前
DTU 数据转发服务器:工业物联网的隐形桥梁
开发语言·php
古城小栈8 小时前
宝塔面板部署 ThinkPHP6 后端
php
幽络源小助理11 小时前
MacCMSPro版视频影视系统源码_全开源高可用视频平台解决方案
前端·php·php源码
TO_WebNow1 天前
使用thinkPHP8.x 访问接口提示跨域
前端·php
JSON_L1 天前
PHP使用Intervention Image图像处理
图像处理·php·intervention
treesforest1 天前
IP数据库下载完全指南:免费与商业IP定位库对比
网络·数据库·php
原来是猿1 天前
网络计算器:理解序列化与反序列化(下)
linux·开发语言·网络·网络协议·json·php