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
  • 配置就是刚刚创建的配置
相关推荐
BingoGo10 小时前
免费可商用 PHP 管理后台 CatchAdmin V5.4.0 发布,新增短信服务能力
后端·php
纯.Pure_Jin(g)1 天前
靶场PHP函数整理+防御方式
开发语言·php·ctf
神仙别闹1 天前
基于C++ WinPcap 的网络抓包软件
网络·c++·php
斑马1391 天前
Linux软件编程学习笔记(五)——线程
开发语言·php
学习星球1 天前
空天地一体化网络(NTN)深度解析:从Starlink D2C到3GPP NTN,卫星直连手机是如何实现的?
网络·人工智能·算法·智能手机·php
郑州光合科技余经理2 天前
本地生活服务系统:模块边界与结算字段怎么拆
java·开发语言·前端·后端·系统架构·uni-app·php
2601_962072502 天前
网络安全防护指南:筑牢网络安全防线(510)
安全·web安全·php
Patrick在香港2 天前
Python 拉取城巴开放数据:406 条路线,香港岛巴士网络的数字画像
网络·python·数据分析·php·数据可视化·香港·开放数据
吴声子夜歌2 天前
Java——开发中通用的方法和准则(二)
java·开发语言·php