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
  • 配置就是刚刚创建的配置
相关推荐
万世浮华戏骨2 小时前
PHP 与数据库交互 与 SQL注⼊漏洞
数据库·sql·php
Johnstons3 小时前
网络可观测性落地指南:从“出了问题才排查“到“实时感知全网状态“
开发语言·网络·php
heRs BART3 小时前
Ubuntu 20.04配置网络
网络·ubuntu·php
2501_948114244 小时前
大模型API调用成本优化的工程路径:星链4SAPI聚合网关的技术实践
大数据·开发语言·人工智能·架构·php
宋拾壹5 小时前
php网站小程序接入抖音团购核销
android·小程序·php
niucloud-admin6 小时前
PHP SAAS 框架常见问题——安装应用时提示 “未找到 admin 源码所在目录”
php
藤原千花的败北6 小时前
PHP对象注入(PHP反序列化漏洞)
网络安全·php
秋风&萧瑟6 小时前
【Linux系统编程】进程间的通信-管道
linux·服务器·php
淘矿人7 小时前
2026大模型API中转平台深度评测:weelinking领衔五大服务商横向实测与选型指南
开发语言·人工智能·python·oracle·数据挖掘·php·pygame