You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

全局安装PHPUnit后执行命令提示‘Test file "*" not found’问题求助

问题解决:PHPUnit全局安装后执行命令报错“Test file "*" not found”

这个报错不一定是全局安装导致的,可按以下步骤排查解决:

  • 确认执行目录与文件存在
    确保你在测试文件所在的目录下执行命令,且目录中确实存在userTest.php这类符合命名规范的测试文件。

  • 使用完整路径指定测试文件
    试试用相对完整路径执行命令,避免路径解析异常:

    phpunit ./userTest.php
    
  • 修正phpunit.xml配置文件
    PHPUnit 12.x对配置文件结构有严格要求,你的现有配置缺少必要的命名空间声明和正确节点层级,修改为如下内容:

    <?xml version="1.0" encoding="utf-8" ?>
    <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.0/phpunit.xsd">
        <testsuites>
            <testsuite name='My Test Suit'>
                <directory suffix='Test.php'>./</directory>
            </testsuite>
        </testsuites>
    </phpunit>
    

    注意:<testsuite>必须嵌套在<testsuites>节点内,suffix='Test.php'刚好匹配你的userTest.php命名规范,能确保PHPUnit正确识别测试文件。

  • 切换为本地安装(若上述步骤无效)
    若以上方法都未解决问题,可尝试放弃全局安装,改用项目本地安装:

    1. 卸载全局PHPUnit:
      composer global remove phpunit/phpunit
      
    2. 在项目根目录执行本地安装:
      composer require --dev phpunit/phpunit
      
    3. 使用本地PHPUnit执行测试:
      • Linux/Mac:./vendor/bin/phpunit
      • Windows:vendor\bin\phpunit.bat

内容的提问来源于stack exchange,提问作者Aldo Cauchi Savona

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 19:22:15