当前位置: 首页 > news >正文

VSCode中PHP使用Xdebug

本地环境

  • windows10
  • php8.2 nts
  • xdebug v3
  • thinkphp v8

下载Xdebug

Xdebug下载地址

从xdebug下载地址,下载最新的xdebug,解压后将php_xdebug.dll放入php目录的ext目录下

配置php.ini

[Xdebug]
zend_extension = php_xdebug
xdebug.client_host = 127.0.0.1
xdebug.client_port = 9003
xdebug.mode = debug,coverage
xdebug.start_with_request = yes
xdebug.idekey=VSCODE

安装扩展

配置launch.json

{// 使用 IntelliSense 了解相关属性。// 悬停以查看现有属性的描述。// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0","configurations": [{"name": "Launch built-in server and debug","type": "php","request": "launch","runtimeArgs": ["-S","localhost:8000","-t","."],"port": 9003,"serverReadyAction": {"action": "openExternally"}},{"name": "Debug current script in console","type": "php","request": "launch","program": "${file}","cwd": "${fileDirname}","externalConsole": false,"port": 9003},{"name": "Listen for Xdebug","type": "php","request": "launch","port": 9003}]
}

运行调试

配合单元测试

安装phpunit

composer require phpunit/phpunit --dev

因为我用的是tp8,单元测试bootstrap需要启动tp的容器,所以安装一下我的扩展bingher/think-test

composer require bingher/think-test --dev

安装PHPUnit Test Explorer

扩展配置

"phpunit.command": "php",
"phpunit.phpunit": "vendor/bin/phpunit",
"phpunit.showAfterExecution": "always",
"phpunit.debuggerConfig": "Listen for Xdebug",
"phpunit.xdebugPort": 9003

重点是phpunit.command,phpunit.phpunit,我原来仅配置phpunit.phpunit: vendor/bin/phpunit.bat 发现扩展执行了一直在转圈圈,调试模式报错: Error: spawn -dxdebug.mode=debug ENOENT at Process.ChildProcess._handle.onexit (node:internal/child_process:285:19) at onErrorNT (node:internal/child_process:483:16) at processTicksAndRejections (node:internal/process/task_queues:82:21)

根据以上配置后PHPUnit Test Explorer顺利运行

phpunit.xml

<phpunit colors="true" verbose="true" bootstrap="./vendor/bingher/think-test/src/init.php"><coverage cacheDirectory="./runtime/phpunit/" pathCoverage="true"><include><directory suffix=".php">./app/</directory></include><report><html outputDirectory="./runtime/phpunit/" lowUpperBound="50" highLowerBound="90"/></report></coverage><testsuites><testsuite name="test"><directory>tests</directory></testsuite></testsuites>
</phpunit>

phpunit.xml可以参考phpunit官网进行配置.

如果没有安装bingher/think-test, 可以不用配置bootstrap

单元测试

http://www.dtcms.com/a/241808.html

相关文章:

  • Easy系列PLC变频器控制功能块(ST源代码)
  • VsCode 离线插件下载
  • (1-6-5)Java 多线程(定长线程池)下载器(案例)
  • React 中的TypeScript开发范式
  • ubuntu桌面x11异常修复
  • 上位机开发过程中的设计模式体会(2):观察者模式和Qt信号槽机制
  • ubuntu + nginx 1.26 + php7.4 + mysql8.0 调优
  • 机器学习中的优化问题描述
  • Python列表:高效灵活的数据存储与操作指南
  • 讲讲JVM的垃圾回收机制
  • 基于大模型的输尿管下段结石诊疗全流程预测与方案研究
  • 项目课题——智能花盆系统设计
  • 核心机制:面向字节流
  • 业务:资产管理功能
  • Vim 调用外部命令学习笔记
  • 新一代 Rust Web 框架的高性能之选
  • 【数据结构】图算法(代码)
  • 微信小程序中的计算属性库-miniprogram-computed
  • 全新AI驱动Workspace Security 套件发布!Fortinet 电子邮件安全产品矩阵升级
  • docker compose v2版本创建和运行容器
  • 第九章 窗口看门狗(WWDG)
  • 在 macOS 上搭建 Flutter 开发环境
  • 论文解读:交大港大上海AI Lab开源论文 | 宇树机器人多姿态起立控制强化学习框架(四)
  • 企业产品网络安全日志6月10日-WAF资费消耗排查
  • 【FFmpeg学习(2)】视频概念
  • 【FFmpeg学习(1)】图像表示
  • 如何将数据从 iPhone 传输到笔记本电脑
  • HTML盒子模型
  • 《网络世界的“隐形窥探者”:深度剖析网络监听》
  • SCAU期末笔记 - 数据分析与数据挖掘题库解析