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
  • 配置就是刚刚创建的配置
相关推荐
niucloud-admin11 小时前
NIUCLOUD PHP SAAS上门家政使用文档:城市管理
java·前端·php
ESDWAN11 小时前
企业网络监控应该监测哪些目标?网关、网络节点还是业务系统?
服务器·网络·php
呆呆虫1212 小时前
用 orjson 加速 SerpBase 响应解析:基准对比与注意事项
开发语言·php
中科三方14 小时前
IPv6检测常见问题:AAAA记录检测不通过是什么原因?
开发语言·php
云边云科技_云网融合16 小时前
面向汽车零部件制造业场景的解决方案 | 70 秒:一台车下线的时间里,藏着五张网
开发语言·汽车·php
李纲明19 小时前
WordPress 媒体库上传图片失败:先核 PHP 体积与目录权限,再查安全插件与对象存储
php·上传·wordpress·媒体库·devdiy
海域云SeaArea_19 小时前
Windows Server 2008 R2 从零安装 IIS7.5(二):php.ini 配置
开发语言·windows·php
niucloud-admin20 小时前
NIUCLOUD PHP SAAS上门家政使用文档:服务保障
java·开发语言·php
honsor1 天前
用 Grafana 做温湿度异常检测:从阈值告警到趋势预测
数据库·mysql·php
开源推荐官1 天前
多门店 O2O 商城选型复盘:从开发视角对比主流开源系统
java·架构·开源·php